Click here to Skip to main content
15,868,016 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
Object: To show or hide the Status Bar programmatically.

The mainframe (MF) is created conventionally as CFrameWndEx class by Visual Studio 10 wizard as a Doc/View application.

The status bar (SB) is created from the OnCreate message of CFrameWndEx class.

***** CFrameWndEx.h *****
C++
#define SB_STYLE        WS_CHILD | CBRS_BOTTOM | CBRS_TOOLTIPS | CBRS_FLYBY | WS_VISIBLE
#define SB_STYLE_EX     WS_EX_CLIENTEDGE
CMFCStatusBar*   p_SBCls;


***** CFrameWndEx.cpp *****
C++
p_SBCls = new CJBK_III_SB;
ASSERT(p_SBCls->CreateEx(this, SB_STYLE_EX, SB_STYLE, nID)); 

The SB is toggled in CFrameWndEx class by:

b_Flag = p_RegCls->m_bGetRegFlag(ID_REGKEY_Item_SB, KEY_READ); //ID_REGKEY_Item_SB == nID

if (b_Flag)            
  p_SBCls->ShowWindow(SW_SHOW);  
else
  p_SBCls->ShowWindow(SW_HIDE); 
        
p_SBCls->Invalidate(TRUE);
p_SBCls->UpdateWindow();

where the toggle flag, b_Flag, is stored in the registry and set by a check box in the RibbonBar; it is retrieved by m_bGetRegFlag(…). The toggle code (above) is called when either the check box is checked (or unchecked) and after the Status Bar is created from the main frame class.

The above works and the SB toggles as shown or hidden as required. The problem comes about when the application is created, the b_Flag is retrieved as TRUE and one attempts to hide the Status Bar by checking the checkbox on the Ribbon Bar. p_SCBls->IsVisible() == FALSE but the Status Bar is still visible.

If I move the mouse over the frame of CFrameWndEx and left click, the SB disappears. More check box clicking does nothing. If the application opens with b_Flag == FALSE, everything works as required. I am not sure what is causing this, however I get the feeling that I have to get the main frame or the SB region to redraw to get CFrameWndEx to redraw and erase the Status Bar.

Any input would be appreciated.

Thanks,

Barry
Posted
Updated 8-Mar-12 0:44am
v3

Sorry, but ShowControlBar(...) seems to have no effect. I did, however, do some "reverse engineering" and found that the hide/show actions seem to revolve around ID_VIEW_STATUS_BAR, one of the message ID's that Microsoft supplies in the support files.

ID_VIEW_STATUS_BAR eventually appears to get inserted in the Windows internal message loop and command structure. This is way above my pay grade. I guess I will have to design my own, on say a docked dialog box.

Whom ever put the CMFC..... code together apparently kept most of it to him/herself and cut a bunch of corners! Thanks for the effort though. :-)
 
Share this answer
 
You can use either ShowWindow or ShowPane to show or hide the status bar. However, the CFrameWndEx will not automatically update the visuals as you noticed.

You will need to call CFrameWndEx::RecalcLayout() after showing or hiding the status bar. So in your CFrameWndEx-extending class, try this:
m_wndStatusBar.ShowWindow(bShow ? SW_SHOW : SW_HIDE);
RecalcLayout();

or this:
ShowFrame(&m_wndStatusBar, bShow, FALSE, FALSE);
RecalcLayout();
 
Share this answer
 
I expect that using ShowControlBar() [^] to show or hide the status bar will solve your problem.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS


CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900