I. Methods and differences for obtaining device context HDC
1. Basic Windows HDC operations
HDC _ HDC =: getdc (m_hwnd); // assume that m_hwnd is valid.
...
: Releasedc (m_hwnd, _ HDC );
2. cview-based HDC operations
HDC _ HDC = getdc ();
...
Releasedc (_ HDC );
3. CDC operations on MFC
CDC * _ CDC = getdc ();
...
Releasedc (_ CDC );
4. cclientdc operations on MFC: the constructor of cclientdc directly obtains the HDC handle; The Destructor is released, so you don't have to worry about HDC.
Cclientdc _ CCDC (m_hwnd );
...
Releasedc (_ CCDC );
5. Obtain the parent window of 4
Cclientdc _ CCDC (getparentdc ());
...
Releasedc (_ CCDC );
6. Window cwindowdc operations
Cwindowdc _ windc (This/m_hwnd/getparentdc ()/getdesktopwindow ());
...
Releasedc (_ windc );
Ii. Operations on paint brushes, paint brushes, and bitmap
1. Paint Brush
Cpen pen (Ps_solid, 1, RGB (255, 0, 0));
... Remember to select the device and the last logical brush.
2. Image painter
(1) normal painter
Cbrush brush (RGB (255, 0, 0 ));
....
(2) bitmap painter
Cbitmap bitmap;
Bitmap. loadbitmap (ID );
Cbrush brush (& Bitmap );
....
(3) transparent image brush