September 5th, 2012, 04:37 PM
Problem with CStatusBar panes in Windows 7
* Development System: WinXP SP3
* Development Environment: MS VC++ 6.0 SP6
* Program is statically linked.
It's kind of a long-winded post but I wanted to present as much information as I could.
Here is the basic problem. In Win7 (and probably Vista) my status bar panes are not always displaying their text. The problem may also exist in other Windows OSs but never noticed.
I have a program that I've maintained for 10 years. Through the yearss it has been updated for capability and to make sure it runs on the all Windows platforms through Win7.
In all this time it has had the same status bar derivecd from MFC's CStatusBar. It has always had five panes of text. Pane 0 is the normal status pane used for displaying the normal 'status' text. The other four panes are for displaying program settings that the user selects. I know it doesn't matter much, but examples of pane 3 text are "NONE", "COM1", "GPIB0", and "PL89".
The status bar panes 1, 2, 3, and 4 have displayed their text just fine through WinXP. But Win7 (and I presume Vista) is DRIVING ME NUTS! Panes 2, 3, and 4 are sometimes cleared and display no text at all. Pane 1 appears to be OK but its text never changes. Pane 1 text is always "RAW", but the text can be normal or dimmed according to a user selectable option.
I will describe pane 3 because it seems to give me the most problems. I'll also leave out most of the error checking in the code snippets below to simplify things.
The status bar is created with:
m_cStatusBar.SetIndicators (indicator info goes here);
Pane 3 is initialized like this (the other panes are the same):
nIndex = m_cStatusBar.CommandToIndex (ID_INDICATOR_3);
m_cStatusBar.GetPaneInfo (nIndex, uID, uStyle, nWidth);
m_cStatusBar.SetPaneInfo (nIndex, uID, uStyle | SBT_OWNERDRAW, nWidth);
The status bar panes are owner-drawn, mostly so I can select the color for the pane and center the text in the pane. Here is the DrawItem() function in a nutshell:
void CStatusBarBmp:rawItem (LPDRAWITEMSTRUCT pstDrawItemStruct)
//get pane's text
nItemID = static_cast<INT>(pstDrawItemStruct->itemID);
GetPaneText (nItemID, cszPaneText);
//set pane's background and foreground colors
cDC.SetBkColor (::GetSysColor (COLOR_BTNFACE));
if (m_abEnabled [nItemID])
dwTextColor = ::GetSysColor (COLOR_BTNTEXT);
dwTextColor = ::GetSysColor (COLOR_GRAYTEXT);
//draw centered text in the pane
cDC.DrawText (cszPaneText, cRect, DT_CENTER);
I use CStatusBar::SetPaneText() to initially write text to the panes. I'm not sure that the CStatusBar::SetPaneText() is needed. In my CMDIFrameWnd derived main frame I use ON_UPDATE_COMMAND_UI commamnd handlers to write the text during idle time. For example:
void CMainFrame::OnUpdateIndicator3 (CCmdUI* pCmdUI)
pCmdUI->SetText (pane text goes here);
During my tests it apears that the ON_UPDATE_COMMAND_UI handlers in WinXP are NOT really need. But it also appears that they ARE needed in Win7. It also appears that in Win7 the panes display correctly in _DEBUG builds but have problems in RELEASE builds. I've also noted that in Win7 if the pane is cleared I can get the pane text to display again if I either resize the main frame or cover/uncover the pane with another program.
Here is the worst possible situation. Sometimes, if the panes are cleared during operation I can simply restart the program and they might work.
So here is my current code:
1. Use CStatusBar::SetPaneText().
2. Use CStatusBar:rawItem().
3. Use CMainFrame::OnUpdateIndicatorX()
I ran across this quote someplace on the 'net (CAPS emphasis is mine:
"The SetText approach is recommended. It is possible to perform this task at a slightly lower level by calling the CStatusBar member function SetPaneText. Even so, you still need an update handler. Without such a handler for the pane, MFC AUTOMATICALLY DISABLES THE PANE, ERASING ITS CONTENT."
What the Hell do they mean "MFC AUTOMATICALLY DISABLES THE PANE, ERASING ITS CONTENT"?
Anybody have any idea what I can do to get the status bar panes working reliably in Win7?
Click Here to Expand Forum to Full Width
This is a Codeguru.com survey!