Well say you want to catch when you hit the scrollbar in a listbox control.
It is impossible with just a normal listbox because the messages from the
scrollbar in the listbox is handled internally.
If you want to try something - download the source from the tutorial
at http://www.winprog.org/tutorial/ and load the ctl_one project
into Dev-cpp. Compile it and see how it looks.
Now add a global variable and a new function:
--- snip ---
WNDPROC OldProc; // This holds a pointer to DlgProc
HWND hWndc; // This can be moved to the DlgProc function
LRESULT CALLBACK NewProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
switch(msg)
{
case WM_VSCROLL:
MessageBox(hwnd, "You are pressing the scrollbar!", "WoW", MB_OK);
break;
default:
break;
}
return CallWindowProc(OldProc, hwnd, msg, wParam, lParam);
}
--- snip ---
In the WM_INITDIALOG add
--- snip ---
hWndc = GetDlgItem(hwnd, IDC_LIST);
OldProc = (WNDPROC)SetWindowLong(hWndc, GWL_WNDPROC, (LONG)NewProc);
--- snip ---
This will replace the original CALLBACK function with the one you supplied.
From now on all messages goes to NewProc first and are then dispatched
to the original DlgProc function!
This can be used for several things, this is just an example!
/Roger
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
have seen some msgs where people are talking about "Subclassing " a control. Can anyone explain me what is that about?
Well say you want to catch when you hit the scrollbar in a listbox control.
It is impossible with just a normal listbox because the messages from the
scrollbar in the listbox is handled internally.
If you want to try something - download the source from the tutorial
at http://www.winprog.org/tutorial/ and load the ctl_one project
into Dev-cpp. Compile it and see how it looks.
Now add a global variable and a new function:
--- snip ---
WNDPROC OldProc; // This holds a pointer to DlgProc
HWND hWndc; // This can be moved to the DlgProc function
LRESULT CALLBACK NewProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
switch(msg)
{
case WM_VSCROLL:
MessageBox(hwnd, "You are pressing the scrollbar!", "WoW", MB_OK);
break;
default:
break;
}
return CallWindowProc(OldProc, hwnd, msg, wParam, lParam);
}
--- snip ---
In the WM_INITDIALOG add
--- snip ---
hWndc = GetDlgItem(hwnd, IDC_LIST);
OldProc = (WNDPROC)SetWindowLong(hWndc, GWL_WNDPROC, (LONG)NewProc);
--- snip ---
This will replace the original CALLBACK function with the one you supplied.
From now on all messages goes to NewProc first and are then dispatched
to the original DlgProc function!
This can be used for several things, this is just an example!
/Roger