Maximizing the ChildFrame window

When maximizing the CMDIChildWnd window on MDI application it looses the Minimize, Restore and Maximize buttons on the top-right frame window.

Here’s how I try to maximize the window (simple, but it doesn’t work):

int CChildFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
      if (CMDIChildWnd::OnCreate(lpCreateStruct) == -1)
            return -1;

      MDIMaximize();

      return 0;
}

The application shows Minimize, Restore and Maximize buttons only for the main window  (CMDIFrameWnd), that is I cannot restore or minimize the ChildFrame windows after calling MDIMaximise() member function.

If anyone knows how to solve this problem I will appreciate your help.

smripaAsked:
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.

abancroftCommented:
Try ShowWindow(SW_SHOWMAXIMIZED) instead.
0
vbk_bgmCommented:
It may be that your CChildFrame class does not have WS_SYSMENU style bit. try
ORing the class bits in PrecreateWindow
with the style.
0
vachoohoCommented:
ShowWindow(SW_SHOWMAXIMIZED);
UPdateWindow();
0
Angular Fundamentals

Learn the fundamentals of Angular 2, a JavaScript framework for developing dynamic single page applications.

smripaAuthor Commented:
I'm afraid ShowWindow(SW_SHOWMAXIMIZED);
does not work. I have no problem on maximizing the window. The problem is that when I maximize it, it looses the WS_SYSMENU style. Yes WS_SYSMENU is there before mazimizing it. Somehow MFC removes this style???
 If you maximize the CChildFrame window by clicking on the maximize button it works fine, but if I call maximize function from the code it does not work.
0
migelCommented:
Hi!
Try override PreCreateWindowmethod and set WS_MAXIMIZE style for example:
BOOL CChildFrame::PreCreateWindow(CREATESTRUCT& cs)
{
      BOOL bRes = CMDIChildWnd::PreCreateWindow(cs);
      cs.style |= WS_MAXIMIZE;
      return bRes;
}
0
ZoppoCommented:
Hi smripa,

does your mainframe has at a menu? I tested it with some MDI applications where it's possible to hide the menu: when menu is hidden, the min/max buttons of a maximized MDIChild aren't visible, when the menu is floated (like a undocked toolbar), the buttons appear within this menu window.

If your mainframe doesn't have a menu I do not know how to work around this... :(

ZOPPO
0
cyberfrankCommented:
Hi!

To maximize CChildFrame You have to override and implement following function:

void CChildFrame::OnShowWindow(BOOL bShow, UINT nStatus)
{
  TRACE("CChildFrame::OnShowWindow - 1 " );
  CMDIChildWnd::OnShowWindow(bShow, nStatus);

  ShowWindow(SW_MAXIMIZE);
      UpdateWindow();
}
0
ZoppoCommented:
Hi cyberfrank,

did you read the previous comments carefully ? the problem smripa had was NOT the maximizing, the problem was the disappearing of the child frame's minimize-, maximize- and close-buttons ...

I do not know, why smripa does not react anymore on this thread, but with the situation I described in my last comment (which I'm not sure if it's the case) your answer unfortunately even does not help ...

ZOPPO
0
cyberfrankCommented:
Ok.
I have solution for that question to:
You have to add in ChildFrame::Create function following:


BOOL CChildFrame::Create(LPCTSTR lpszClassName, LPCTSTR lpszWindowName, DWORD dwStyle, const RECT& rect, CMDIFrameWnd* pParentWnd, CCreateContext* pContext)
{
      // TODO: Add your specialized code here and/or call the base class
      DWORD d = dwStyle ^ WS_SYSMENU;
      return CMDIChildWnd::Create(lpszClassName, lpszWindowName, d, rect, pParentWnd, pContext);
}

Is it now Ok?
CF
0
ZoppoCommented:
Hi cyberfrank,

Unfortunately no, please test following:

In CWinApp-derived OnInitInstance() near the end (after ProcessShellCommand() ) call

pMainFrame->SetMenu( NULL );

Now the mainframe has no menu bar, and now maximizing the child makes the minimize-, maximize and close-buttons of the childframe dissapear (as I told before this is the only case I found where this happens anyway).

ZOPPO


0
cyberfrankCommented:
Hi Zoppo!

The one thing, that I'm not understand is, why want You disable menu in the start? Smripa doesn't ask for it. BTW:

BOOL CChildFrame::PreCreateWindow(CREATESTRUCT& cs)
{
BOOL bRes = CMDIChildWnd::PreCreateWindow(cs);
cs.style |= WS_MAXIMIZE;
return bRes;
}
code is wrong!! It should be:

BOOL CChildFrame::PreCreateWindow(CREATESTRUCT& cs)
{
cs.style |= WS_MAXIMIZE;
BOOL bRes =
CMDIChildWnd::PreCreateWindow(cs);
return bRes;
}

So, smripa, what's now the real problem, because i do not see the wood because of the tree :-(


CF
0
ZoppoCommented:
Now, as I told, I do not know why smripa has the problem with the dissappearing buttons, so I've tried some time to reproduce the problem: The only case I found in which these child frame's buttons dissappear was the case with a mainframe without a menu. So I asked if smripa uses a mainframe without a menu but never got an answer ...


So, as I'm not used to ask people for let me help them, it's smripa's turn...


BTW, I'm going home in half an hour, will be back here tomottow morning (about 8.30CET, just for two or three hours), so I wish you all a happy and safe Y2K    <|:o)>-<
0
cyberfrankCommented:
Hi Zoppo!

Thanks for comments! Have You tried my suggestion? Because they will disapear whatever is on MainFrame.
I hope smripa will react in the near future (maybe in next millenium ;-) )

Happy New Year!!

CF
0
cyberfrankCommented:
Hi!

I have found an interesting solution. At
http://www.codeguru.com/dialog/disable_close.shtml
site there is a simple solution for enabling/disabling system menu items on the fly:
For disabling:
CMenu* mnu = this->GetSystemMenu(FALSE);
   mnu->ModifyMenu(SC_CLOSE,MF_BYCOMMAND | MF_GRAYED );

and for enabling:

CMenu* mnu = this->GetSystemMenu(FALSE);
   mnu->EnableMenuItem( SC_CLOSE, MF_BYCOMMAND|MF_GRAYED);

and at
mk:@MSITStore:d:\Program%20Files\Microsoft%20Visual%20Studio\MSDN98\98OCT\1033
you can find that, you can use instead of SC_CLOSE SC_MAXIMIZE and SC_MINIMIZE, like You guess.

Where "this" was an CDialog instance, but hopefully, GetSystemMenu is available as member of CWindow, of CWnd and as a global function :-)


CF


0
smripaAuthor Commented:
Hi Folks

Sorry for not responding on your comments, I was off for couple of days.

Happy new year!

I’m afraid cyberfrank’s solution does not work.

Let me re-emphasize the problem.

ChildFrame window has WS_SYSMENU style, so there is no need to set it (i tried it anyway and it doesn't work).  Please try to maximize the child frame window from the code and you’ll see that maximize and minimize buttons disappear.  The MDI frame window has a menu (and is not floatable). Try MFC AppWizard (exe) and Multiple document options with default options.
My self  I’m having a problem to maximize the ChildFrame window from the code without loosing maximize and minimize buttons.

Cheers
smripa
0
cyberfrankCommented:
Ok, now I'm understand. I'll try to find You a solution, because, have had done same thing long before and it worked.

CF
0
ZoppoCommented:
Hi smripa,

I'm still not able to reproduce it ... please can you send some code where you maximize the child window ... BTW, which version of MSVC do you use?

I've tried following (like you suggested):

1. Created a new MDI project with all AppWizard options as default.

2. Added this code to the end of InitInstance():
....
CWnd* pWnd = pMainFrame->MDIGetActive();
if ( pWnd )
 pWnd->ShowWindow( SW_MAXIMIZE );
return TRUE;
}

When running the app the child is maximized and the min-/max- buttons are still visible ...

ZOPPO
0
smripaAuthor Commented:
Hi Zoppo,

I'm using VC++ 6 and I'm maximizing the child frame window as below:

int CChildFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
      if (CMDIChildWnd::OnCreate(lpCreateStruct) == -1)
            return -1;

      ShowWindow(SW_SHOWMAXIMIZED);

      return 0;
}
0
ZoppoCommented:
Hi smripa,

I did not find out why this is, but I found a way to solve it:

Override the CChildFrame's Create function and maximize it there like this:

BOOL CChildFrame::Create(LPCTSTR lpszClassName, LPCTSTR lpszWindowName, DWORD dwStyle, const RECT& rect, CMDIFrameWnd* pParentWnd, CCreateContext* pContext)
{
 BOOL ret = CMDIChildWnd::Create(lpszClassName, lpszWindowName, dwStyle, rect, pParentWnd, pContext);
 if ( ret )
  ShowWindow( SW_MAXIMIZE );//or I think it's better to use MDIMaximize();
 return ret;
}

hope that helps,

ZOPPO
0

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
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
System Programming

From novice to tech pro — start learning today.