The study of Programming Windows with MFC--BitMap

来源:互联网 发布:虚无世界2java下载 编辑:程序博客网 时间:2024/05/08 12:10

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);
   };

   


 

原创粉丝点击