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  

You might also like...

Comments

Contribute

Why not write for us? Or you could submit an event or a user group in your area. Alternatively just tell us what you think!

Our tools

We've got automatic conversion tools to convert C# to VB.NET, VB.NET to C#. Also you can compress javascript and compress css and generate sql connection strings.

“Memory is like an orgasm. It's a lot better if you don't have to fake it.” - Seymour Cray