Maximizing in MDI

I'm writting an MDI-like interface that does not use the standard windows MDI classes and procedures.  I have a couple of questions involving maximizing/minimizing the MDI child (document windows).  

1.  I need to know how to tell when a MDI child window has be maximized, minimized, or restored.  What is the best message (or messages) to "hook" for this.  WM_SYSCOMMAND, WM_WINDOWPOSCHANGED or is there some other.  I don't want to hook a message that occurs only in some cases, like will the SYSCOMMAND message always occur, regardless of how the window is maximized.minimized.

2.  The default behavior for maximizing a window is that it enlarges to fill the parent's client area.  However, it still has its title (caption).  The standard MDI behavior is that the title should disappear.  How should I do this?  Do I want to resize the MDI child window's client area to fill its window frame (leaving no room for the title)?  Do I want to change the window styles so there is no caption?   (I don't even know if that can be done)  Or is there a better way?

3.  How does a program make a window maximize or minimize?  Should is send a WM_SYSCOMMAND message to the window or is there a better way?
LVL 22
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Tommy HuiEngineerCommented:
1. The WM_SYSCOMMAND will be sent whenever the user does anything to cause it to minimize or maximize (by pressing the corresponding caption buttons or the system menu). You can catch the WPARAM to see what happened. Look in the header files for SC_xxx IDs.

2. If you resize the child, you still have the caption, so that won't work. The best guess would be to remove the caption by changing its style: use GetWindowLong(GWL_STYLE) and mask out WS_CAPTION. Make sure the child does not have a style that implies a caption like WS_OVERLAPPEDWINDOW.

3. You can send the window a WM_SYSCOMMAND with the appropriate SC_xxx in WPARAM.


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
nietodAuthor Commented:
I'm not 100% sure of a couple points.  (Actually they are related) I realize that the WM_SYSCOMMAND message occurs when the window is maximized/minimized using the menus or buttons, but my concern is there some other way a window could be maximized/minimized where the messages would not be sent.  For example, is there an API command (or some event) that does it without sending the messages.  

Kinda related to that, is how do I maximize/minimize a window "manually"?  I realize that sending the SYSCOMMAND will work, but does that just cause the Default window procedure to call some API command or is that it?

In case this wasn't clear, let me give an example in a similar case.  The WM_CLOSE message is sent when ever the close box is hit.  But if I had tasks to perform every time a window was closed, I would not want to hook the WM_CLOSE message because it is not always sent.  For example, if DestroyWindow() is called directly to close a window.  Also, if I want to close a window, I can call DestroyWindow() directly rather than using the WM_CLOSE message (which leads to calling DestroyWindow()).

I suspect that is not an issue with the minimize/maximize case, but I want to make sure that this same sort of design is not in use.

By the way in, question 2, I was proposing resizing the client area so there is no room for a caption in the non-client area.  But if changing the styles works, it is a better way.  I was just afraid that some styles (like the caption) wouldn't change.
Tommy HuiEngineerCommented:
WM_SYSCOMMAND is it for maximizing, minimizing, and restoring a window. That's what the regular MDI child uses to signal certain events in the MDI frame.

WM_CLOSE is not a regular message you would use because that is a request to close the window. It does not mean go away. To know whenever a window is closing, you should catch WM_DESTROY.
nietodAuthor Commented:
I understand the close issue.  I just wanted to make sure the same issue wasn't happening with the maximizing.  i.e. is the SYSCOMMAND message a request just like the CLOSE message?  Apparently it is not.  I just wanted to make sure.
nietodAuthor Commented:
Thui, it turns out the maximize/minimize process does work just like the close process.  The WM_SYSCOMMAND is just a "request" to perform an action and the default window procedure performs that action using an API procedure.  In this case, the procedure is ShowWindow().  ShowWindow() can be used directly to maximize or minimize a window and it does not result in a WM_SYSCOMMAND.  (Which is what I needed and will greatly simplify my code.)
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Development

From novice to tech pro — start learning today.