This topic is now archived and is closed to further replies.

Clash Rocker

[Win32 API]Subclassing controls

Recommended Posts

Clash Rocker    130
Does anyone have or know of some tutorials on subclassing. I''m have a hell of alot of trouble trying to subclass my edit control. I wish I had some code to present, but alas I do not. So some a few pointer would be much appreciated. TIA

Share this post

Link to post
Share on other sites
Sandman    2210
1. Create your custom WndProc for message handling etc.

2. Use SetWindowLong GWL_WNDPROC flag to get access to the controls original window procedure and replace it with your own. Make sure

3. Make sure your custom WndProc makes a call to the original one, or your edit box wont do very much.


// untested code.....

void SubClassControl(HWND ctrl, WNDPROC custom)
WNDPROC original = SetWindowLong(ctrl,GWL_WNDPROC,(LONG)custom);
// need to store a copy of the original somewhere so we can

// get at it later... use the user defined space for the control...


// also need to call this function at the end of your custom WndProc

BOOL OriginalWndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
// retrieve the original window proc from the user defined

// data field and run it...

WNDPROC original = (WNDPROC)GetWindowLong(hWnd,GWL_USERDATA);
return CallWindowProc(original, hWnd, msg,wParam,lParam);


Share this post

Link to post
Share on other sites