MFC ing between an MFC object and a Win32 SDK handle

Source: Internet
Author: User
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 )

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.