• Advertisement
Sign in to follow this  

Creating a window without maximize button

This topic is 4736 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I'm trying to create an MDI child window without the standard maximize, minimize and exit buttons. I've got the MDI child window working fine, but, how in the world can I change the style so it doesn't have any of these standard buttons?

Share this post


Link to post
Share on other sites
Advertisement
Oh, and, plus, how do I create a window with tabs?

Share this post


Link to post
Share on other sites
I believe when creating the window, you have to use this for the style:

WS_VISIBLE | WS_SYSMENU

This will give it just the X button. If you want the bar and borders and such, then I suppose just use WS_VISIBLE.

If you want the window not to have any border or anything, then use POPUPWINDOW

Tell me if this works!

Share this post


Link to post
Share on other sites
I dug about, and found some information on MSDN, Ill quote the relevant info:

Quote:
The MDI Case

A little more work is required to change the window style of a child window in a multiple document interface (MDI) application. By default, an MDI application created with AppWizard uses the default CMDIChildWnd class defined in MFC. To change the window style of an MDI child window, you must derive a new class from CMDIChildWnd and replace all references to CMDIChildWnd in your project with references to the new class. Most likely, the only reference to CMDIChildWnd in the application is located in your application's InitInstance member function.

The default window style used in an MDI application is a combination of the WS_CHILD, WS_OVERLAPPEDWINDOW, and FWS_ADDTOTITLE styles. To change the window attributes of an MDI application’s child windows, override the PreCreateWindow function in your class derived from CMDIChildWnd. For example:

BOOL CMyChildWnd::PreCreateWindow(CREATESTRUCT& cs)
{
// Create a child window without the maximize button
cs.style &= ~WS_MAXIMIZEBOX;

// Call the base-class version
return CMDIChildWnd::PreCreateWindow(cs);
}

This code creates MDI child windows without a Maximize button.


Here is the link if you want to dig deeper:

[link=http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vccore98/HTML/_core_changing_the_styles_of_a_window_created_by_mfc.asp]More Info[/link]

Share this post


Link to post
Share on other sites
And here is my problem. I don't know if I'm using MFC.

I have set up the MDI client manually and I'm not using objects, so I don't have any references to a CMDIChildWnd object.

I'm using C for the windows programming side.

Share this post


Link to post
Share on other sites
After creating a window you can change the styles with SetWindowLong( GWL_style, ... ). (and GWL_EXstyle).

Get the old styles with GetWindowLong, modify the flags to your liking (remove WS_MAXIMIZEBOX) and set them again. Maybe you have to call SetWindowPos with SWP_FRAMECHANGED to see the changes in the border.

Share this post


Link to post
Share on other sites
Window styles are represented by a series of bitflags. Each bitflag can be eliminated by a simple operation:
newstyle = oldStye & ~bitflag;

Therefore, say your child window had the styles WS_CHILD and WS_OVERLAPPED, you'd do the following:
DWORD style = (WS_CHILD|WS_OVERLAPPED) & ~(WS_MAXIMIZEBOX|WS_MINIMIZEBOX|WS_SYSMENU);

To fully understand this code, read up on bitwise operators. To the best of my knowledge, you can not eliminate the close button without removing the caption entirely (in which case, add WS_CAPTION to the right side of the above expression, or just use WS_DLGFRAME for your window style).

Depending on whether you wish to apply this style before or after the window is created, you may pass it to CreateWindow[Ex] or SetWindowPos respectively.

Share this post


Link to post
Share on other sites
Much appreciated.

Anyone want to guess what my problem was with the bitwise operations?

I don't do enough of them. I absent-mindedly used the '!' operator instead of '~' for NOT.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement