MFC Technical Instructions: <See msdn mfc tno 3>
Mapping of Windows handles to objects
MFC
Object and
Win32 SDK
Handle ing Note: MFC uses the C ++ object to encapsulate Win32 handles (handle, the resource scheduling unit of the operating system ), therefore, the concept of C ++ object and Win32 handle object in MFC must be distinguished. The following discussion is how to encapsulate functions and technologies related to the correlated handle in the mfc c ++ object: 1 fromhandle () fromhandle (handle); // The static method of the MFC class member is used to create a temporary and valid MFC object ie: cwnd * pwnd = cwnd :: fromhandle (hwndobject); note that the temporary object created here may be deleted after it leaves its scope, because it will be called during the processing of the default onidle () function of cwinthread Deletetempmap () Replace these MFC Object slave Handle Upper Detach Drop and release heap memory Note: This is a memory recovery mechanism provided by MFC. 2 attach () to create a continuous effective (Permanent persistent) method of the MFC object Create The MFC object then calls the member function attach (handle ); At this time, the created object is continuously associated The Note that if the object is destroyed When an MFC object (such as a local variable out of its scope) is destroyed by default If this is not the desired effect, destroy it. When you use an MFC object, you must first remove the MFC object from the handle. Detach () 3 MFC object thread relevance whether temporary or continuous The MFC object is thread-related, so it is impossible to obtain the MFC object associated with the handle of another thread, therefore, if different threads want to operate on the objects pointed to by the same handle, it is best to pass the handle object instead of the associated MFC object. 4. Common handle objects (Handle object) MFC ing relationship with the MFC object
-
- Hwnd (Cwnd And Cwnd-Derived classes)
-
- HDC (CDC And CDC-Derived classes)
- Hmenu (Cmenu)
-
- Hpen (Cgdiobject)
-
- Hbrush (Cgdiobject)
-
- Hfont (Cgdiobject)
- Hbitmap (Cgdiobject)
-
- Hpalette (Cgdiobject)
-
- Hrgn (Cgdiobject)
-
- Himagelist (Cimagelist)
- socket ( csocket )