How would I Catch a Resize event? Would I Use WM_SIZE? If so how would I determine if the form is resized because aint this used for catching Minimize and Maximize events?
I knew this would come in handy for more than skinning one day!
case WM.WM_SYSCOMMAND:
if (m.WParam == (IntPtr)SystemCommands.Maximize ||
m.WParam == (IntPtr)SystemCommands.MaximizeByFrame)
{
OnMaximized();
}
else if (m.WParam == (IntPtr)SystemCommands.Restore ||
m.WParam == (IntPtr)SystemCommands.RestoreByFrame)
{
OnRestored();
}
else if (m.WParam == (IntPtr)SystemCommands.Minimize)
{
OnMinimized();
}
DefWndProc(ref m);
break;
#endregion
m is the Msg struct (this is C# btw, so I wouldn't try to stick this into your code directly), but look up WM_SYSCOMMAND in MSDN to find out what the command constants are (I wouldn't be surprised if it was SC_MAXIMIZE/SC_MINIMIZE).
WM_SIZE does other resize events though.
Thanks once again Myndfyre, appreciate it!
I think looking at WM_SYSCOMMAND for that purpose is wrong and might not work properly for things programmatically minimizing or maximizing a window.
It would probably be better to use WM_WINDOWPOSCHANGED, or if you are passing that to DefWindowProc, WM_SIZE.
If you are using WM_WINDOWPOSCHANGED, you will have to figure out what operation is happening based on the old and new window positions.
If you are using WM_SIZE, wParam indicates what sort of operation just occured.
You should use GetClientRect in WM_SIZE to determine the new client area instead of relying on the truncated values provided in lParam.
Quote from: Skywing on February 11, 2006, 06:51 AM
I think looking at WM_SYSCOMMAND for that purpose is wrong and might not work properly for things programmatically minimizing or maximizing a window.
It would probably be better to use WM_WINDOWPOSCHANGED, or if you are passing that to DefWindowProc, WM_SIZE.
If you are using WM_WINDOWPOSCHANGED, you will have to figure out what operation is happening based on the old and new window positions.
If you are using WM_SIZE, wParam indicates what sort of operation just occured.
You should use GetClientRect in WM_SIZE to determine the new client area instead of relying on the truncated values provided in lParam.
Ahh, so WM_SIZE does work? I couldn't ever get this to function. But -- C#. :)
Quote from: MyndFyre on February 11, 2006, 06:49 PM
Ahh, so WM_SIZE does work? I couldn't ever get this to function. But -- C#. :)
I suspect that you (or something else) is handling WM_WINDOWPOSCHANGED and not passing it to DefWindowProc.
WM_SIZE/WM_MOVE are compatibility messages sent to programs that don't support figuring out their new positioning from the newer WM_WINDOWPOSCHANGED. If the program handles WM_WINDOWPOSCHANGED internally, WM_SIZE/WM_MOVE would not be sent as they are generated by DefWindowProc in response to WM_WINDOWPOSCHANGED.
You can use them in new programs if you don't want to write code to determine your new positioning from WM_WINDOWPOSCHANGED, however. This requires that you pass WM_WINDOWPOSCHANGED to DefWindowProc, though.