⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 pcdmpicture.h

📁 《Windows CE 权威指南》(作者:(美)CHRIS MUENCH
💻 H
字号:
// PCDMPicture.h : Declaration of the CPCDMPicture

#ifndef __PCDMPICTURE_H_
#define __PCDMPICTURE_H_

#include "resource.h"       // main symbols
#include <atlctl.h>

// <BOOK_ADDON STEP6 Chapter 10.1.4> *****************************************
void DrawBitmapFromFile(HDC hdc,LPCTSTR FileName,DWORD Offset,
					    int x,int y, int dx, int dy,BOOL stretch);
#define WIDTHBYTES(bits)      ((((bits) + 31)>>5)<<2)
// </BOOK_ADDON STEP6 Chapter 10.1.4> *****************************************
/////////////////////////////////////////////////////////////////////////////
// CPCDMPicture
class ATL_NO_VTABLE CPCDMPicture : 
	public CComObjectRootEx<CComSingleThreadModel>,
	public IDispatchImpl<IPCDMPicture, &IID_IPCDMPicture, &LIBID_PCDMUILib>,
	public CComControl<CPCDMPicture>,
	public IPersistStreamInitImpl<CPCDMPicture>,
	public IOleControlImpl<CPCDMPicture>,
	public IOleObjectImpl<CPCDMPicture>,
	public IOleInPlaceActiveObjectImpl<CPCDMPicture>,
	public IViewObjectExImpl<CPCDMPicture>,
	public IOleInPlaceObjectWindowlessImpl<CPCDMPicture>,
	public IPersistStorageImpl<CPCDMPicture>,
	public ISpecifyPropertyPagesImpl<CPCDMPicture>,
	public IQuickActivateImpl<CPCDMPicture>,
	public IDataObjectImpl<CPCDMPicture>,
	public IProvideClassInfo2Impl<&CLSID_PCDMPicture, NULL, &LIBID_PCDMUILib>,
	public CComCoClass<CPCDMPicture, &CLSID_PCDMPicture>
{
public:
	CPCDMPicture()
	{
// <BOOK_ADDON STEP6 Chapter 10.1.4> ***********************************
		m_hBitmap=NULL;
		m_lpSrcDIB=NULL;
	}
	~CPCDMPicture()
	{
		if (!m_hBitmap)
			DeleteObject(m_hBitmap);
		if (!m_lpSrcDIB)
			free(m_lpSrcDIB);
	}
// </BOOK_ADDON STEP6 Chapter 10.1.4> ***********************************

DECLARE_REGISTRY_RESOURCEID(IDR_PCDMPICTURE)

DECLARE_PROTECT_FINAL_CONSTRUCT()

BEGIN_COM_MAP(CPCDMPicture)
	COM_INTERFACE_ENTRY(IPCDMPicture)
	COM_INTERFACE_ENTRY(IDispatch)
	COM_INTERFACE_ENTRY(IViewObjectEx)
	COM_INTERFACE_ENTRY(IViewObject2)
	COM_INTERFACE_ENTRY(IViewObject)
	COM_INTERFACE_ENTRY(IOleInPlaceObjectWindowless)
	COM_INTERFACE_ENTRY(IOleInPlaceObject)
	COM_INTERFACE_ENTRY2(IOleWindow, IOleInPlaceObjectWindowless)
	COM_INTERFACE_ENTRY(IOleInPlaceActiveObject)
	COM_INTERFACE_ENTRY(IOleControl)
	COM_INTERFACE_ENTRY(IOleObject)
	COM_INTERFACE_ENTRY(IPersistStreamInit)
	COM_INTERFACE_ENTRY2(IPersist, IPersistStreamInit)
	COM_INTERFACE_ENTRY(ISpecifyPropertyPages)
	COM_INTERFACE_ENTRY(IQuickActivate)
	COM_INTERFACE_ENTRY(IPersistStorage)
	COM_INTERFACE_ENTRY(IDataObject)
	COM_INTERFACE_ENTRY(IProvideClassInfo)
	COM_INTERFACE_ENTRY(IProvideClassInfo2)
END_COM_MAP()

BEGIN_PROP_MAP(CPCDMPicture)
	PROP_DATA_ENTRY("_cx", m_sizeExtent.cx, VT_UI4)
	PROP_DATA_ENTRY("_cy", m_sizeExtent.cy, VT_UI4)
	// Example entries
	// PROP_ENTRY("Property Description", dispid, clsid)
	// PROP_PAGE(CLSID_StockColorPage)
END_PROP_MAP()

BEGIN_MSG_MAP(CPCDMPicture)
	CHAIN_MSG_MAP(CComControl<CPCDMPicture>)
	DEFAULT_REFLECTION_HANDLER()
END_MSG_MAP()
// Handler prototypes:
//  LRESULT MessageHandler(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
//  LRESULT CommandHandler(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& bHandled);
//  LRESULT NotifyHandler(int idCtrl, LPNMHDR pnmh, BOOL& bHandled);



// IViewObjectEx
	DECLARE_VIEW_STATUS(VIEWSTATUS_SOLIDBKGND | VIEWSTATUS_OPAQUE)

// IPCDMPicture
public:
	STDMETHOD(Load)(BSTR Path,LONG ResourceID);

	HRESULT OnDraw(ATL_DRAWINFO& di)
	{
// <BOOK_ADDON STEP7 Chapter 10.2.1> ***********************************
		RECT& rc = *(RECT*)di.prcBounds;
		RECT			bRC;
		HDC            	hSourceDC;
		HBITMAP        	hSourceBitmap, hOldSourceBitmap;
	
		if (m_hBitmap==NULL && m_lpSrcDIB==NULL)	return S_OK;
	
		hSourceDC = CreateCompatibleDC( di.hdcDraw );
		bRC.left=0; bRC.top=0; 
		if (m_lpSrcDIB!=NULL)
		{
			LPBITMAPINFO lpbmi = (LPBITMAPINFO)m_lpSrcDIB;
			LPBYTE       lpSourceBits;
			DWORD        dwSourceBitsSize;
				
			hSourceBitmap = CreateDIBSection( di.hdcDraw, lpbmi,
							DIB_RGB_COLORS, (void **)&lpSourceBits,
							NULL, 0 );
			dwSourceBitsSize = lpbmi->bmiHeader.biHeight * BytesPerLine(&(lpbmi->bmiHeader));
			memcpy( lpSourceBits, FindDIBBits((LPSTR)lpbmi),  dwSourceBitsSize );
			bRC.right=lpbmi->bmiHeader.biWidth;
			bRC.bottom=lpbmi->bmiHeader.biHeight;
		}
		else
		{
			BITMAP bm;
	
			hSourceBitmap=m_hBitmap;
			GetObject (m_hBitmap, sizeof(BITMAP), &bm);
			bRC.right=bm.bmWidth;
			bRC.bottom=bm.bmHeight;
		}
				
		hOldSourceBitmap = (HBITMAP)SelectObject( hSourceDC, hSourceBitmap );
		if( rc.right-rc.left!= bRC.right || rc.bottom-rc.top!=bRC.bottom)
		    StretchBlt( di.hdcDraw, rc.left,  rc.top, rc.right,
						rc.bottom, hSourceDC, 0, 0, bRC.right,
						bRC.bottom, SRCCOPY );
		else
		    BitBlt( di.hdcDraw, rc.left,  rc.top, rc.right, rc.bottom, hSourceDC, 0, 0, SRCCOPY );
				
		// Clean up and delete the DCs
		SelectObject( hSourceDC, hOldSourceBitmap );
		DeleteDC( hSourceDC );
// </BOOK_ADDON STEP7 Chapter 10.2.1> ***********************************
		return S_OK;
	}
// <BOOK_ADDON STEP6 Chapter 10.1.4> ***********************************
private:
	BOOL BlitDIB( HDC JChdc,LPBITMAPINFO lpSrcDIB, int x,int y,int dx, int dy,BOOL bStretch );
	LPSTR FindDIBBits( LPSTR lpbi );
	WORD DIBNumColors( LPSTR lpbi );
	WORD PaletteSize( LPSTR lpbi );
	DWORD BytesPerLine( LPBITMAPINFOHEADER lpBMIH );	
	LPBYTE ReadBMPFile(LPCTSTR szFileName,DWORD Offset);
	HBITMAP			m_hBitmap;
	LPBYTE			m_lpSrcDIB;
// </BOOK_ADDON STEP6 Chapter 10.1.4> ***********************************
};

#endif //__PCDMPICTURE_H_

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -