Reputation: 319
I have a ListView whose columns I'd like to prevent being resized. I'm using code similar to this question, however my HDN_BEGINTRACK
message isn't recognised.
My code to create the ListView:
HWND Instructions_ListView = CreateWindowEx(LVS_EX_DOUBLEBUFFER |
LVS_EX_FULLROWSELECT, WC_LISTVIEW, L"", WS_CHILD | WS_VISIBLE |
LVS_REPORT | LVS_EDITLABELS, 320, 50, 300, 400, hWnd, NULL, NULL, NULL);
My code to handle the header events follows. WM_NOTIFY
is inside of WndProc
for the main program window:
case WM_NOTIFY:
{
UINT debugval = (((LPNMHDR)lParam)->code);
switch (((LPNMHDR)lParam)->code)
{
case HDN_BEGINTRACKA:
case HDN_BEGINTRACK:
{
::MessageBox(hWnd, L"RESIZE", L"", MB_OK);
break;
}
}
break;
}
When debugging the value of debugval
is 4294966969
when breaking on (what should be) the HDN_BEGINTRACK
event.
Absolutely stumped as to why it's not working as intended; any help would be greatly appreciated.
Upvotes: 2
Views: 676
Reputation: 14649
When using COMCTL32 version 5, applications need to send common controls a CCM_SETVERSION message to take advantage of new functionality and fixes not available in earlier versions. The list view control does not forward all header notifications unless the control version is greater than or equal to 5. The List View control in COMCTL32 version 6 forwards all header notifications without sending the control a CCM_SETVERSION message.
So in your sample after creation of list view please add the below line
SendMessage(Instructions_ListView, CCM_SETVERSION, 5, 0);
Upvotes: 0
Reputation: 597885
The ListView's header control is a child of the ListView, so the header's WM_NOTIFY
notifications will be sent to the ListView itself, not to your parent window. As such, your WndProc will not see them.
To catch WM_NOTIFY
(and WM_COMMAND
) messages sent by the ListView's internal child controls, you need to subclass the ListView using SetWindowLongPtr(GWL_WNDPROC)
or SetWindowSubclass()
.
FYI, HDN_BEGINTRACKA
has a value of 4294966990
(-306
, hex 0xFFFFFECE
), and HDN_BEGINTRACKW
has a value of 4294966970
( -326
, hex 0xFFFFFEBA
).
You say you are getting a WM_NOTIFY
notification with a code
of 4294966969
. That is 0xFFFFFEB9
(dec -327
), which is the HDN_ENDTRACKW
notification.
Upvotes: 4