• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 351
  • Last Modified:

Showing/Hiding toolbar

I have a MDI application which uses two toolbars based on the document type. Say I have MDIChild1,MDIChild2 two frame classes with toolbar1, toolbar2 associated to them.

In CMainFrame's oncreate function I create both the toolbars and show toolbar1 and hide toolbar2. Now when I open MDIChild2 frame and associted doc/view I want toolbar2 to be
visible and toolbar1 to be hidden.
So I have written following code in Overridden OnMDIActivate (WM_MDIACTIVATE)function of MDIChild2.
Everything is working as expected but when I call print preview fron MDIChild2 the print preview dilaog is shown and
when I close this Toolbar1 is also shown along with Toolbar2. Can anybody say why is this happening.
1 Solution
I think you have to create at least three toolbars, one is default. On WM_MDIACTIVARE you have to chek and if your window is diactivates you have to set default toolbar. When one of your child is about to activate you just set the corespondent toolbar.
Have U written code in WM_MDIACTIVATE  of  MDIChild1  
to show toolbar1  and hide toolbar2 ?

I think when U close the print preview dialog  , the
WM_MDIACTIVATE is getting called for  both MDIChild2
and  MDIChild1  .

Another possibility is  , when U  close the print preview dialog  , OnDraw function is getting called  for the
MDIFrameWnd  . U can   write code inside this  function
to  get the  active  MDiChildWnd  and  send a
WM_MDIACTIVATE message to it , thereby activating the appropriate  tool bar .

sangameshAuthor Commented:
I had already tried placing showcontrolbar(.......) in OnDraw of MainFrame and it works but I am wondering why the other toolbar is being shown without that code.
Actually I want to know why it happens like that. I am listing the code I have wrriten for MDIChildWnd2's OnMDIActivate

showcontolbar(Toolbar1, false,false);
showcontolbar(Toolbar2, true,false);
showcontolbar(Toolbar1, true,false);
showcontolbar(Toolbar2, false,false);

else block is executed when the MDIChildWnd2 is being deactivaed
and other block is executed when the MDIChildWnd2 is being activated

Train for your Pen Testing Engineer Certification

Enroll today in this bundle of courses to gain experience in the logistics of pen testing, Linux fundamentals, vulnerability assessments, detecting live systems, and more! This series, valued at $3,000, is free for Premium members, Team Accounts, and Qualified Experts.

check when U are setting the value of bActivate .
when are U setting the values of bActivate  to TRUE
and FALSE ?

Where are U creating the toolbars ? Is it OnCreateClient ?

Does  the ELSE block ever get executed ? because
when MDIChildWnd2  is  being  deactivated the  control
won't  come  to  MDIChildWnd2::OnMDIActivate  because
it is not getting Activated .

Also , are U showing the toolbars i.e. calling ShowControl
Bar anywhere else in the program ? whereby  Toolbar
of  MDIChild1 is being displayed

sangameshAuthor Commented:
I have tried all but it doesn't work
Sangamesh, There are two ways to solve this problem.
1) The way in which you are trying to show/hide toolbars, where the Toolbars are members of MainFrame( Am I right there? ). BUT you have to make the Show/Hide on corresponding view's OnActivateView() override. This would work even with the printpreview case.
2) Or make each of these toolbars are members of the Child frames and create them in the OnCreate() of these Child frames( Instead of the create of the Main Frame)

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now