您的位置:首页 > 其它

The study of Programming Windows with MFC--BitMap

2010-08-04 11:37 369 查看
1.DDB and CBitMap



CClientDC dcScreen(this);

CBitmap bitmap;

bitmap.CreateCompatibleBitMap(&dcScreen,m_nWidth,m_nHeight);



CDC dcMem;

dcMem.CreateCompatibleDC(&dcScreen);



CBitMap *pOldBitMap=dcMem.SelectObject(&bitmap);

CBrush brush(RGB(255,255,0);

dcMem.FillRect(CRect(0,0,100,100),&brush);

dcMem.SelectObject(pOldBitmap);





2.Blit Bitmap to Screen and Other Devices

void CMyBitMap::DrawBitmap(CDC *pDC, int x, int y)

{

BITMAP bm;

GetBitmap(&bm);

CSize size(bm.bmWidth, bm.bmHeight);

pDC->DPtoLP(&size);

CPoint Org(0,0);

pDC->DPtoLP(&Org);



CDC dcMem;

dcMem->CreateCompatibleDC(pDC);

CBitmap *pOldBitmap=dcMem.SelectObjec(this);

dcMem.SetMapMode(pDC->GetMapMode ());

pDC->BitBlit(x,y,size.x,size.y,pDC,Org.x,Org.y,SRCCOPY);

dcMem.SelectObject(pOldBitmap);

}



//When you pass CDC::DPtoLP the address of a CPoint object, the call goes straight through to the ::DPtoLP API function and the conversion is performed properly, even if one or more of the coordinates comes back negative. But when you pass CDC::DPtoLP the address of a CSize object, MFC performs the conversion itself and converts any negatives to positives.



3.LoadMap

//.rc

IDB_MYLOGO BITMAP Logo.bmp

CBitmap bitmap;
bitmap.LoadBitmap (IDB_MYLOGO); //bitmap.LoadMappedBitmap (IDB_BITMAP);





4.the structure of The BitmapDemo application

class CMainFrame:public CFrameWnd

{

public:

CMainFrame();

protected:

DECLARE_DYNAMIC(CMainWnd);

public:

virtual BOOL PreCreateWindow(CREATESTRUCT &cs)

virtual BOOL OnCmdMsg(UINT nID, int nCode, void* pExtra,
AFX_CMDHANDLERINFO* pHandlerInfo);

virtual ~CMainWnd();

protected:

CStatusBar m_wndStatusBar;

CChildView m_wndView;

afx_msg int OnCreate(LPCREATESTRUCT lpCreateStruct);
afx_msg void OnSetFocus(CWnd *pOldWnd);
afx_msg BOOL OnQueryNewPalette();
afx_msg void OnPaletteChanged(CWnd* pFocusWnd);

DECLARE_MESSAGE_MAP()
};





class CChildView : public CWnd
{

public:

CChildView();

protected:
virtual BOOL PreCreateWindow(CREATESTRUCT& cs);

virtual ~CChildView();

protected:
void DoGradientFill (CDC* pDC, LPRECT pRect);
CPalette m_palette;
CMaskedBitmap m_bitmap;
BOOL m_bDrawOpaque;
afx_msg void OnPaint();
afx_msg int OnCreate(LPCREATESTRUCT lpCreateStruct);
afx_msg BOOL OnEraseBkgnd(CDC* pDC);
afx_msg void OnOptionsDrawOpaque();
afx_msg void OnOptionsDrawTransparent();
afx_msg void OnUpdateOptionsDrawOpaque(CCmdUI* pCmdUI);
afx_msg void OnUpdateOptionsDrawTransparent(CCmdUI* pCmdUI);
DECLARE_MESSAGE_MAP()
};



class CMaskedBitmap : public CBitmap
{
public:
void DrawTransparent (CDC* pDC, int x, int y,COLORREF clrTransparency);
void Draw (CDC* pDC, int x, int y);
};
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: