Archived

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

[Win32 API]Subclassing controls

This topic is 5976 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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

SetWindowLong(ctrl,GWL_USERDATA,(LONG)original);
}

// 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);
}




HTH

Share this post


Link to post
Share on other sites