Maximizing in MDI

Posted on 1997-11-12
Last Modified: 2013-12-03
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?
Question by:nietod
  • 3
  • 2
LVL 15

Accepted Solution

Tommy Hui earned 70 total points
ID: 1408360
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.

LVL 22

Author Comment

ID: 1408361
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.
LVL 15

Expert Comment

by:Tommy Hui
ID: 1408362
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.
LVL 22

Author Comment

ID: 1408363
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.
LVL 22

Author Comment

ID: 1408364
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.)

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article describes how to add a user-defined command button to the Windows 7 Explorer toolbar.  In the previous article (, we saw how to put the Delete button back there where it belongs.  "Delete" is …
zlib is a free compression library (a DLL) on which the popular gzip utility is built.  In this article, we'll see how to use the zlib functions to compress and decompress data in memory; that is, without needing to use a temporary file.  We'll be c…
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA.…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

929 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now