Library tutorials & articles

Attaching and Detaching Objects

Introduction

MFC provides a set of "wrapper objects" that contain embedded Windows objects. For example, a CWnd wraps an HWND, a CFont wraps an HFONT, a CBrush wraps an HBRUSH, and so on. These are summarized in the table below. There are some significant interactions between the MFC and Windows objects, which you need to understand.

Failure to deal with these issues can lead to problems with spontaneous ASSERT statements, access errors, disappearing objects, and other, more subtle problems.

This essay attempts to elucidate the issues of dealing with the MFC/Windows interface.

MFC Ojbect Windows Object (variant)
CWnd HWND any window
CEdit HWND EDIT
CListBox HWND LISTBOX
CStatic HWND STATIC
CComboBox HWND COMBOBOX
CGDIObject (gdi object) (any)
CBitmap HBITMAP  
CBrush HBRUSH  
CPen HPEN  
CFont HFONT  
CRegion HRGN  
CPalette HPALETTE  

Comments

  1. 13 Sep 2006 at 07:43

    Sorry posted in wrong thread

  2. 13 Sep 2006 at 06:14

    Hi

    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 authdlg;
    ..

    public :

     void checkAuthentication();
     

    };

    void CAuthen :: checkAuthentication()
    {
    ..
    ..
    ..

       if(  auth
    dlg.DoModal() == IDOK)
        {
           ...
           // some operation goes here
        }
    ..
    ..
    }



































  3. 01 Jan 1999 at 00:00

    This thread is for discussions of Attaching and Detaching Objects.

Leave a comment

Sign in or Join us (it's free).

AddThis

Events coming up

  • Jun 16

    Code Generation 2009

    Cambridge, United Kingdom

    A developer event with a practical focus on helping people get to grips with code generation tools and technologies.