Re: Catch WM_SIZE
On Thu, 14 Aug 2008 09:53:05 -0700, Erakis
<Erakis@discussions.microsoft.com> wrote:
Hi,
The parent need to know when this child control change size because it must
be realign on CENTER of the dialog.
I find a working solution :
LRESULT CALLBACK MyControlCtrlNewWndProc(HWND hWnd,UINT Message, WPARAM
wParam, LPARAM lParam);
LONG MyControlOldWndProc;
BOOL CMyDialog::OnInitDialog()
{
CDialog::OnInitDialog();
m_MyControlCreate( NULL, _T(""), WS_VISIBLE, CRect(10, 10, 0, 0), this, 1
);
MyControlOldWndProc = SetWindowLong(m_MyControl, GWL_WNDPROC,
(long)MyControlCtrlNewWndProc);
...
}
LRESULT CALLBACK MyControlCtrlNewWndProc(HWND hWnd, UINT Message, WPARAM
wParam, LPARAM lParam)
{
switch(Message)
{
case WM_SIZE :
LRESULT result = CallWindowProc( (WNDPROC)TrappeOldWndProc, hWnd, NULL,
wParam, lParam);
// Do realign stuff...
return result;
break;
}
// Call default function
return CallWindowProc((WNDPROC)MyControlOldWndProc, hWnd, Message, wParam,
lParam);
}
What are you thinking of this solution ?
First, get rid of the WndProc casts, as they aren't necessary if you've
declared your functions correctly. Second, if it works, it works, but I'd
be worried about compatibility with MFC's subclassing. You might want to
check out CSubclassWnd here, which does the same thing you're doing but
makes it easier, and presumably accounts for any obscure MFC edge cases:
http://www.dilascia.com/PixieLib.asp
Also, dialog layout is usually performed in the dialog's WM_SIZE handler,
and the controls themselves cannot be resized by, say, dragging a sizer
gadget. If your control is dynamically resizable by means other than parent
dialog activity, it could post a message to the dialog notifying it has
been resized, but the subclassing method is certainly less intrusive, so I
think it's fine.
--
Doug Harrison
Visual C++ MVP