windows_programming_notes.nbk: Home | Index | Next Page: How To Use Win32 API to Draw a Dragging Rectangle on Screen DC | Previous Page: how to subclass a dialog control - installing and removing


 how to subclass control not in a dialog

After creating the control with CreateWindow or CreateWindowEx:

    SetWindowLong(handle, GWL_USERDATA, (LPARAM)SubclassWindow(handle, subclass));

The above code saves the handle of the original Window class in the user data area so it can be called for things you don't want to handle with the subclass, and so you can put the original class back in place before the control is destroyed.

Before the control is destroyed, unsubclass it:

    // unsubclass the window - there better be a subclass!
    SetWindowLong(hwnd, GWL_WNDPROC, (LONG)GetWindowLong(hwnd, GWL_USERDATA));
    DestroyWindow(hwnd);

windows_programming_notes.nbk: Home | Index | Next Page: How To Use Win32 API to Draw a Dragging Rectangle on Screen DC | Previous Page: how to subclass a dialog control - installing and removing


Notebook exported on Monday, 7 July 2008, 18:56:50 PM Eastern Daylight Time