MFC class about its window handle

Attach, in fact, it is to allow members of a HWND CWnd object points to the window handle. Attach this is the main task.

Detach. As mentioned earlier, WNDCLASS fact and CWnd simply does not matter. Between them just by linking members of CWnd HWND.

If the Attach seen as "marriage", then Detach the umbilical cord is the "divorce", and quite literally, cut off a CWnd object and a valid window. CWnd, CDC, Cxxx are all MFC classes, these classes provide a number of member functions to execute system calls and other operations, but the core of the class members handle all data, (including window handle, DC handle, thread handle, etc.). m_hWnd, m_hDC, m_hThread if these handles these class object is empty, it means an invalid object. If you apply for a CWnd, CDC object entity, you can use Attach to specify a valid handle paid to this object. So this object is of a Valid. You might look at the implementation Attach track, in fact, is to give m_hxxx assignment, and the value of Detach is reset.

      

CBitmap Detach the relationship and DeleteObject

Note: When you have finished using resources, must release the accelerator tables, bitmaps, cursors, icons, and menus memory resources occupied by calling the function;

Accelerator table: DesteoyAcceleratorTable;

Bitmap: DeleteObject;

Cursor: DestroyCursor;

Icon: Destroylcon;

Menu: DestroyMenu

 

HBITMAP / CBitmap relationship between conversion / BITMAP three:

HBITMAP hBitmap;  

CBitmap bitmap;  

BITMAP bm;  

bitmap.Attach (hBitmap); // get the HBITMAP associated CBitmap  

bitmap.GetBitmap (& bm); // get the associated BITMAP CBitmap  

hBitmap = (HBITMAP) bitmap.GetSafeHandle (); // get the associated HBITMAP CBitmap 

 

Description:

1. Detach allow C ++ objects and GDI objects separated, but they are not released. Must now DeleteObject respectively deletepBmp and the two were released;

2. m_Bitmap-> DeleteObject will enable GDI object is released, and the C ++ object itself will not be released. You can re-use Attach it is associated with a GDI object or with delete their release;

3.deletepBmp (Note that we do not call DeleteObject is assumed destructor) will make C ++ objects demise, and the corresponding GDI objects still exist. For the release of GDI objects, you must call the DeleteObject again.

 

Guess you like

Origin www.cnblogs.com/arxive/p/11748240.html