I have dialog created using CreateDialogParam. It has only a single ListView child control. In the dialog WM_INITDIALOG message handler, I subclass the ListView to customize header redrawing.
Now I want to prevent the user from resizing the ListView column (header) and, to do this, I just need to handle the HDN_BEGINTRACKA notification message in the ListView's WndProc, like below:
case WM_NOTIFY:
{
if ((((LPNMHDR)lParam)->code == HDN_BEGINTRACKA)
|| (((LPNMHDR)lParam)->code == HDN_BEGINTRACKW))
return TRUE; // to disable column resizing
}
This works OK; but, for some reason I want to handle this message in the parent (dialog) procedure. So, I forward this message to that parent as below:
case WM_NOTIFY:
{
if ((((LPNMHDR)lParam)->code == HDN_BEGINTRACKA)
|| (((LPNMHDR)lParam)->code == HDN_BEGINTRACKW))
{
BOOL b = FALSE;
HWND hParent = GetRealParent(hwnd);
if (hParent) b = SendMessage(hParent, msg, wParam, lParam);
return b; // to disable column resizing return TRUE;
}
}
break;
The message is sent OK but, even though I return TRUE from the dialog procedure, here in the ListView procedure, the return value of the SendMessage call is FALSE.
In the dialog procedure, the code is as below:
case WM_NOTIFY:
{
if ((((LPNMHDR)lParam)->code == HDN_BEGINTRACKA)
|| (((LPNMHDR)lParam)->code == HDN_BEGINTRACKW))
return TRUE;
}
So, my question is why directly sending (forwarding) the WM_NOTIFY message to the parent returns a different result, or simply just doesn't work?
Edit :-
In the past, I have faced the same problem; to solve it, I tried a user-defined message, like:
#define UWM_WM_NOTIFY (WM_APP + 7)
and use that with SendMessage to communicate between child and parent, or between any other dialogs. But it also fails to get proper return values.
So, I am using SendMessage as follow:
BOOL b = FALSE;
SendMessageA(hDlg, UWM_ANY_WM, 0, (LPARAM) &b);
return b;
Sending address of variable as LPARAM to get return value. Is there any better way to do this. Or Why SendMessageA return value is different?