Not receiving any HDN messages (for list control)

Hi,
I am trying to prevent a user resizing the columns of a list control. I have read loads of pages about this, including some known bugs, but cannot receive any HDN messages (especially the HDN_BEGINTRACK message (and I have added HDN_BEGINTRACKA and HDN_BEGINTRACKW)). Using the WM_NOTIFY message, I check for the correct control and cast the lParam to a LPNMHDR, but the ->code value is never correct. All it seems to equal is either 0xFFFFFFF4, 0xFFFFFFF8 or 0xFFFFFFF9. The code I have is-

case WM_NOTIFY:
{
switch(LOWORD(wParam))
{
case IDC_DISPLAYFORMAT:
{
switch((UINT)((LPNMHDR)lParam)->code)
{
case HDN_BEGINTRACKA:
case HDN_BEGINTRACKW:
return TRUE; <--- NEVER REACHES HERE

case HDN_TRACK:
return TRUE;

}
}
break;
....

Can anyone help?
Many thanks,
DumbMonkey.
[1283 byte] By [DumbMonkey] at [2007-11-20 11:46:27]
# 1 Re: Not receiving any HDN messages (for list control)
It is next to impossible to find answer to your question.
The code snippet you posted does not tell much, since it os not possible to determine what window procedure it represents.

Is your app written using MFC or strictly API?

Consider posting your entire project.
JohnCz at 2007-11-11 4:03:06 >
# 2 Re: Not receiving any HDN messages (for list control)
Hi John,
Its strictly API (i hate MFC). I have used SPY++ on the window and tried moving the List control header and the correct HDN_BEGINTRACK message is sent by the window, but not picked up in my program. The WND_PROC below is from the dialog box which holds the list control. There isnt much more to my project, the list box IDC_DISPLAYFORMAT was created in the resource dialog editor.
Thanks for your reply.

LRESULT CALLBACK ConfigurationDialogProc(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam)
{
switch(Msg)
{
case WM_INITDIALOG:
INITCOMMONCONTROLSEX commonControls;
commonControls.dwSize = sizeof(INITCOMMONCONTROLSEX);
commonControls.dwICC = ICC_BAR_CLASSES | ICC_UPDOWN_CLASS | ICC_USEREX_CLASSES;
InitCommonControlsEx(&commonControls);
return TRUE;

case WM_COMMAND:
switch(LOWORD(wParam))
{
case IDC_CONFIGURATIONCANCEL:
PostMessage(hWnd, WM_QUIT, 0, 0);
return TRUE;
}
break;

case WM_NOTIFY:
{
switch(LOWORD(wParam))
{
case IDC_DISPLAYFORMAT:
{
switch((UINT)((LPNMHDR)lParam)->code)
{
case HDN_BEGINTRACKA:
case HDN_BEGINTRACKW:
return TRUE;

case HDN_ENDTRACKA:
case HDN_ENDTRACKW:
return TRUE;

case HDN_ITEMCHANGED:
return TRUE;

case LVN_COLUMNCLICK:
return TRUE;
}
}
break;
}
}
break;

case WM_CLOSE:
PostMessage(hWnd, WM_QUIT, 0, 0);
break;

case WM_QUIT:
DestroyWindow(hWnd);
break;

}
return FALSE;
}
DumbMonkey at 2007-11-11 4:04:12 >
# 3 Re: Not receiving any HDN messages (for list control)
From MSDN:HDN_BEGINTRACK

Notifies a header control's parent window that the user has begun dragging a divider in the control (that is, the user has pressed the left mouse button while the mouse cursor is on a divider in the header control). This notification message is sent in the form of a WM_NOTIFY message.
As you can see this message is sent to the parent of the header control which is the list control, not a dialog!
VictorN at 2007-11-11 4:05:11 >
# 4 Re: Not receiving any HDN messages (for list control)
Hi Victor,
That was the key! Thanks. I added a new WND_PROC for the list control using

listViewProc = (WNDPROC) (LRESULT) SetWindowLong(GetDlgItem(hWnd, IDC_DISPLAYFORMAT), GWLP_WNDPROC, (LONG) ListViewDialogProc);

And handled the messages in there.
It works! Muchos appreciated. :)
DumbMonkey
DumbMonkey at 2007-11-11 4:06:15 >