Subclassing means that you effectively "take control" of the edit box in order to make it react in the way you want it to. You're familiar with making a WindowProc for your window, right? This is very similar, you make a WindowProc and replace the edit box's default WindowProc so you can process the messages it receives.
Start with:
Code:
//put this with your globals at the top of your code
WNDPROC DefEditProc;
//Then add this template
LRESULT EditProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
switch (uMsg)
{
default:
return CallWindowProc(DefEditProc, hwnd, uMsg, wParam, lParam);
}
return FALSE;
}
There ya go, that'll be your initial WindowProc. To replace the default WindowProc with it, use:-
Code:
DefEditProc = (WNDPROC)SetWindowLong(hwndEdit, GWL_WNDPROC, (long)EditProc);
Where hwndEdit is your Edit box's window handle.
WARNING
Make sure that you replace the WindowProc before your program exits! Otherwise bad things may happen. Do this via:-
Code:
SetWindowLong(hwndEdit, GWL_WNDPROC, (long)DefEditProc);