• Welcome to Valhalla Legends Archive.
 

Resize Event

Started by Spilled, February 10, 2006, 12:51 PM

Previous topic - Next topic

Spilled

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?

MyndFyre

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.
QuoteEvery generation of humans believed it had all the answers it needed, except for a few mysteries they assumed would be solved at any moment. And they all believed their ancestors were simplistic and deluded. What are the odds that you are the first generation of humans who will understand reality?

After 3 years, it's on the horizon.  The new JinxBot, and BN#, the managed Battle.net Client library.

Quote from: chyea on January 16, 2009, 05:05 PM
You've just located global warming.

Spilled

Thanks once again Myndfyre, appreciate it!

Skywing

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.

MyndFyre

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#.  :)
QuoteEvery generation of humans believed it had all the answers it needed, except for a few mysteries they assumed would be solved at any moment. And they all believed their ancestors were simplistic and deluded. What are the odds that you are the first generation of humans who will understand reality?

After 3 years, it's on the horizon.  The new JinxBot, and BN#, the managed Battle.net Client library.

Quote from: chyea on January 16, 2009, 05:05 PM
You've just located global warming.

Skywing

#5
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.