Library tutorials & articles
Attaching and Detaching Objects
Summary
While this essay has concentrated primarily on the CFont object, the techniques here apply to all MFC classes that are wrappers for Windows objects. CGDIObject, the superclass of CPen, CBrush, CFont, CRgn, CPalette, and others is where Attach, Detach, and FromHandle are implemented. Subclasses such as CPen override FromHandle to take an HPEN and return a CPen *, but in fact they simply call the superclass to do all the work and provide the type casting necessary to make things work right in a C++ environment. In addition, the CWnd class has Attach, Detach, and FromHandle. The CWnd class has one other operation, FromHandlePermanent, which I may someday write about, but not right now.
All of these operations are designed to allow you to move freely between the Windows object domain, where objects are represented by instances of HANDLEs, and the MFC object domain, where objects are represented by class instances of C++ classes. It can help you a lot to understand the relationship between these two representations, and how to use them in a safe and non-leaking fashion.
Related articles
Related discussion
-
VS2005 app's won't run on another machine
by ted4444 (0 replies)
-
VB.NET: Hide and show table using radio buttons
by converter2009 (1 replies)
-
Convert C++ code to VB6
by mawcot (4 replies)
-
How to create a games like FIFA08
by mawcot (0 replies)
-
Binary Studio | software development outsourcing Ukraine
by shane124 (4 replies)
Sorry posted in wrong thread
i am new to VC++, while creating a model dialog from a cwnd class i am getting a Assertion error.
can any one tell me where i did wrong.
class CAuthen:: public CWnd
{
............
..
public:
CAuthenDlg auth_dlg;
..
public :
void checkAuthentication();
};
void CAuthen :: checkAuthentication()
{
..
..
..
if( auth_dlg.DoModal() == IDOK)
{
...
// some operation goes here
}
..
..
}
This thread is for discussions of Attaching and Detaching Objects.