For child window controls, sometimes we might want to get some messages from a subwindow, such as having three buttons under a main window, and if you want to use the Keyboard tab or the Shift-tab key to switch the focus between different buttons, you can use the Subwindow Class (window subclassing) method.
Subcategory of child window:
The window message handler for the button control is internal to Windows. However, by calling GetWindowLong with the Gwl_wndproc identifier as a parameter, you can get the address of this window's message handler. In addition, you can call SetWindowLong to set a new window message handler for the specified button, which is called "window sub-categorization" and is useful. It allows you to set a "hook" for an existing window message handler to process some messages in your own program while passing all other messages to the old window message handlers.
For each of the three buttons, COLORS1 uses SetWindowLong to set the address of the New scroll bar window message handler and obtains the address of the existing ScrollBar window message handler:
for (i=0;i<3; i++=createwindow (TEXT ("button"), Buttonname[i ],ws_child| Bs_pushbutton, 0,0,0,0= (WNDPROC) SetWindowLong (Hwndbutton[i], Gwl_ WNDPROC, (LONG) newwndproc)); }
The function Newwndproc now gets all the messages that Windows sends to the scroll bar window message handler in Hwndbutton. The window message handler changes the input focus to the next (or Previous) button window when it receives the tab or Shift-tab key. It uses CallWindowProc to call the old button window message handlers.
LRESULT CALLBACK Newwndproc (HWND hwnd, UINT Message,wparam WPARAM, LPARAM LPARAM) {intID =GetWindowLong (hwnd, gwl_id); Switch(message) { CaseWm_keydown:if(WParam = =vk_tab) SetFocus (GetDlgItem (GetParent (HWND), (ID+ (Getkeystate (Vk_shift) <0?2:1)) %3)) ; Break ; CaseWm_setfocus:idfocus=ID; Break ; } returnCallWindowProc (Oldbuttonwndproc[id], hwnd, message, Wparam,lparam);}
Windows Programming--child window categorization (window subclassing)