用给状态条加文字失败了,原因何在

sity 2001-01-02 01:03:00
我已经增加了相应的字符串资源,加入了indicators[]数组中(共5个元素),并在CMainFrame::OnCreate中加入:
m_wndStatusBar.SetPaneText(4,"Hello!");但运行时状态条只多了一个框,上面没有文字。
...全文
159 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
sity 2001-01-03
  • 打赏
  • 举报
回复
原来如此,兄弟们拿分吧!
raojun 2001-01-03
  • 打赏
  • 举报
回复
首先我得问一下,你的字符串资源的ID是多少?VC MFC已经预定义了许多字符串,如果你的字符串ID和VC的重了,那你八成显示不出来。如果你是修改了wizard生成的字符串资源中已有的字符串,因为它的ID已被占用,你肯定无法正确显示。另外,在你新定义字符串资源时,字符串的ID名一定注意不要是ID_INDICATOR_xxx,因为VC发现有ID_INDICATOR会自动分配它预定义的ID。最后,检查一下你的字符串资源ID是不是59136,59137或类似59XXX的值,如果是的话那原因就非常明确,为新的字符串资源起名ID_XXXXXXX_XXX,不要出现ID_INDICATOR。good luck!
abnegate 2001-01-03
  • 打赏
  • 举报
回复
只要响应相应的OnUpdateCommandUI函数,在函数里SetText就可以了,
当然你应该预留好位置。
reigod 2001-01-03
  • 打赏
  • 举报
回复
在OnCreate中只是把位置留出来罢了,你要使用更新机制,像RedFire兄说的一样。
dusj 2001-01-02
  • 打赏
  • 举报
回复
设置高度和宽度。
adrianx 2001-01-02
  • 打赏
  • 举报
回复
有关代码给出来吧!
RedFire 2001-01-02
  • 打赏
  • 举报
回复
你还要加上消息映射函数;如下:
Status Bars: Updating the Text of a Status-Bar Pane
Home | Overview | How Do I | Tutorial

This article explains how to change the text that appears in an MFC status bar pane. A status bar — a window object of class CStatusBar — contains several “panes.” Each pane is a rectangular area of the status bar that you can use to display information. For example, many applications display the status of the CAPS LOCK, NUM LOCK, and other keys in the rightmost panes. Applications also often display informative text in the leftmost pane (pane 0), sometimes called the “message pane.” For example, the default MFC status bar uses the message pane to display a string explaining the currently selected menu item or toolbar button. The figure in Status Bars shows a status bar from an AppWizard-created MFC application.

By default, MFC does not enable a CStatusBar pane when it creates the pane. To activate a pane, you must use the ON_UPDATE_COMMAND_UI macro for each pane on the status bar and update the panes. Because panes do not send WM_COMMAND messages (they aren’t like toolbar buttons), you can’t use ClassWizard to create an update handler to activate a pane; you must type the code manually.

For example, suppose one pane has ID_INDICATOR_PAGE as its command identifier and that it contains the current page number in a document. The following procedure describes how to create a new pane in the status bar.

To make a new pane

Define the pane’s command ID.
Open the ResourceView in the Project Workspace window. Open the Symbol Browser with the Resource Symbols command on the View menu, and click New. Type a command ID name: for example, ID_INDICATOR_PAGE. Specify a value for the ID, or accept the value suggested by the Symbol Browser. For example, for ID_INDICATOR_PAGE, accept the default value. Close the Symbol Browser.

Define a default string to display in the pane.
With the ResourceView open, double-click String Table in the window that lists resource types for your application. With the String Table editor open, choose New String from the Insert menu. In the String Properties window, select your pane’s command ID (for example, ID_INDICATOR_PAGE) and type a default string value, such as “Page ”. Close the string editor. (You need a default string to avoid a compiler error.)

Add the pane to the indicators array.
In file MAINFRM.CPP, locate the indicators array. This array lists command IDs for all of the status bar’s indicators, in order from left to right. At the appropriate point in the array, enter your pane’s command ID, as shown here for ID_INDICATOR_PAGE:

static UINT BASED_CODE indicators[] =
{
ID_SEPARATOR, // status line indicator
ID_INDICATOR_CAPS,
ID_INDICATOR_NUM,
ID_INDICATOR_SCRL,
ID_INDICATOR_PAGE,
};

The recommended way to display text in a pane is to call the SetText member function of class CCmdUI in an update handler function for the pane. For example, you might want to set up an integer variable m_nPage that contains the current page number and use SetText to set the pane’s text to a string version of that number.

Note 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.

The following procedure shows how to use an update handler function to display text in a pane.

To make a pane display text

Add a command update handler for the command.
You can’t use ClassWizard to write a handler for a status bar pane, so manually add a prototype for the handler, as shown here for ID_INDICATOR_PAGE (in MAINFRM.H):

afx_msg void OnUpdatePage(CCmdUI *pCmdUI);

In the appropriate .CPP file, add the handler’s definition, as shown here for ID_INDICATOR_PAGE (in MAINFRM.CPP):

void CMainFrame::OnUpdatePage(CCmdUI *pCmdUI)
{
pCmdUI->Enable();
}

In the appropriate message map, add the ON_UPDATE_COMMAND_UI macro (outside the “{{AFX” comments), as shown here for ID_INDICATOR_PAGE (in MAINFRM.CPP):

ON_UPDATE_COMMAND_UI(ID_INDICATOR_PAGE, OnUpdatePage)

Add code to the handler to display your text.
For ID_INDICATOR_PAGE, expand the OnUpdatePage handler from step 1 above, adding the last three lines:

void CMainFrame::OnUpdatePage(CCmdUI *pCmdUI)
{
pCmdUI->Enable();
CString strPage;
strPage.Format( "Page %d", m_nPage );
pCmdUI->SetText( strPage );
}

Once you define the value of the m_nPage member variable (of class CMainFrame), this technique causes the page number to appear in the pane during idle processing in the same manner that the application updates other indicators. If m_nPage changes, the display changes during the next idle loop.

What do you want to know more about?
Updating user-interface objects, such as toolbar buttons and menu items, as program conditions change
See Also CStatusBar
hugos 2001-01-02
  • 打赏
  • 举报
回复
你是否没有设置正确的panewidth. 试一下SetPaneWidth(4,100);

16,471

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC相关问题讨论
社区管理员
  • 基础类社区
  • Web++
  • encoderlee
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

        VC/MFC社区版块或许是CSDN最“古老”的版块了,记忆之中,与CSDN的年龄几乎差不多。随着时间的推移,MFC技术渐渐的偏离了开发主流,若干年之后的今天,当我们面对着微软的这个经典之笔,内心充满着敬意,那些曾经的记忆,可以说代表着二十年前曾经的辉煌……
        向经典致敬,或许是老一代程序员内心里面难以释怀的感受。互联网大行其道的今天,我们期待着MFC技术能够恢复其曾经的辉煌,或许这个期待会永远成为一种“梦想”,或许一切皆有可能……
        我们希望这个版块可以很好的适配Web时代,期待更好的互联网技术能够使得MFC技术框架得以重现活力,……

试试用AI创作助手写篇文章吧