* 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):
//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:
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?
I tried your suggestion and ran automatic and manual tests all day long, but it didn't quite solve the problem. Sometimes when I update one pain another pane would be cleared. However, when a pane is cleared it would be redrawn again if I reseize the program window or cover/uncover the status bar pane with anther program window.
Instead of InvalidateRect() for a pane I''l try Invalidate() for the entire status bar and then call UpdateWindow().
I DO NOT call DrawItem() directly. It is only called from the framework. I just setup a variable for each pane that defines the color (dimmed or normal) of the text. The variable is used during DrawItem().
As stated at the bottom of my original post "...MFC automatically disables the pane, erasing its content.". If I knew what causes MFC to disable the pane maybe I can fix the problem instead of handling the symptoms.
I want to thanl every one who offered pointers. This is the code I ended up with and things seem to be working OK but I'm still testing. If anyone can see any holes I'd appreciate some feedback. I'm especially not sure of the OnPaint() routine at the bottom of the post.
//adds indicator ID to an array used in DrawItem()