MFC状态栏-不能完全正常运行 [英] MFC Status Bars - not quite operational

查看:93
本文介绍了MFC状态栏-不能完全正常运行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所需的最终结果是CMFCStatusBar,其中包含3个窗格,即0、1、2.窗格0& 2将包含以编程方式设置的文本;窗格1是位图.窗格0和1是固定长度,窗格2是拉伸".

我有以下内容:
//------------------------------------------------ ----------------- CMainFrameEx.cpp

The end desired result is a CMFCStatusBar with 3 panes, 0, 1, 2. Panes 0 & 2 are to contain programmatically set text; pane 1 is a bitmap. Panes 0 & 1 are of fixed length, pane 2 is "Stretch".

I have the following:
//-----------------------------------------------------------------CMainFrameEx.cpp

ON_UPDATE_COMMAND_UI(IDCTL_SB_Pane_0, &CJBK_MF::OnUpdatePane)

p_SBCls = new CJBK_SB; //Pointer To Status Bar Class - Called by "OnCreate(…)"
ASSERT(p_SBCls->CreateEx(this, SB_CTRL_STYLE, SB_WND_STYLE, IDCls_SB));

sTemp.LoadStringW(ID_Text_SB_Init);                //Called after the above
p_SBCls->SetPaneText(0, sTemp, TRUE);

void CJBK_MF::OnUpdatePane(CCmdUI* p_CmdUI)    
 {
  p_CmdUI->Enable(TRUE);
 }

//------------------------------------------- ------------------- Status_Bar_Class.cpp

//--------------------------------------------------------------Status_Bar_Class.cpp

IDArr[0] = IDCTL_SB_Pane_0;
  IDArr[1] = IDCTL_SB_Pane_1;
  IDArr[2] = IDCTL_SB_Pane_2;
  
  p_IDArr = &IDArr[0];
  ASSERT(this->;SetIndicators(p_IDArr, 3));   

//-------------------------------------------- ----------------------- CMainFrameEx.h

//-------------------------------------------------------------------CMainFrameEx.h

afx_msg void OnUpdatePane(CCmdUI* p_CmdUI);


窗格0和1工作正常.

当我修改CMainframeEx.cpp(见下文)时,窗格2不显示文本.


Panes 0 & 1 work correctly.

When I modify CMainframeEx.cpp (see below), Pane 2 does not display the text.

sTemp.LoadStringW(ID_Text_SB_Init);        //Was
p_SBCls->SetPaneText(0, sTemp, TRUE);

sTemp.LoadStringW(ID_Text_SB_Init);                       //Now
p_SBCls->SetPaneText(0, sTemp, TRUE);
sTemp.LoadStringW(ID_Text_SB_ABC);                       
p_SBCls->SetPaneText(2, sTemp, TRUE);





ON_UPDATE_COMMAND_UI(IDCTL_SB_Pane_0, &CJBK_MF::OnUpdatePane) //Was

ON_UPDATE_COMMAND_UI(IDCTL_SB_Pane_0, &CJBK_MF::OnUpdatePane)             //Now
ON_UPDATE_COMMAND_UI(IDCTL_SB_Pane_2, &CJBK_MF::OnUpdatePane)



谁能帮我找出为什么Pane 2不显示吗?状态栏包含一个"gipper";窗格中的数字是否计数?

谢谢,
Barry



Can anyone please help me spot why Pane 2 does not display? The status bar contains a "gipper"; does that count in the pane count?

Thanks,
Barry

推荐答案

找到了一个把戏:):
A trick is found :) :
// Frame.h
class CMyStatusBar : public CMFCStatusBar
{
public:
    BOOL MySetIndicators(int nCount);
};

class CMainFrame : public CFrameWndEx
{
   CMyStatusBar m_wndStatusBar;
//.. 
public:
    virtual CWnd* GetMessageBar() { return NULL; } // no tracing of menu/toolbar commands in the first pane
//..
};


//Frame.cpp
BOOL CMyStatusBar::MySetIndicators(int nCount)
{
    ASSERT_VALID(this);
    ASSERT(nCount >= 1);  // must be at least one of them

    // free strings before freeing array of elements
    for (int i = 0; i < m_nCount; i++)
    {
        VERIFY(SetPaneText(i, NULL, FALSE));
        SetPaneIcon(i, NULL, FALSE);
    }

    // first allocate array for panes and copy initial data
    if (!AllocElements(nCount, sizeof(CMFCStatusBarPaneInfo)))
        return FALSE;

    ASSERT(nCount == m_nCount);
    RecalcLayout();
    return TRUE;
}

int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
//..
	if (!m_wndStatusBar.Create(this))
	{
		TRACE0("Failed to create status bar\n");
		return -1;      // fail to create
	}

	m_wndStatusBar.MySetIndicators(3);
	
	m_wndStatusBar.SetPaneWidth(0, 100);
	m_wndStatusBar.SetPaneBackgroundColor(0, ::afxGlobalData.clrBarFace);
	m_wndStatusBar.SetPaneText(0, _T("Hello"));
	
	m_wndStatusBar.SetPaneWidth(1, 50);
	m_wndStatusBar.SetPaneBackgroundColor(1, ::afxGlobalData.clrBarFace);
	m_wndStatusBar.SetPaneText(1, _T("World")); // or set icon here :)
	
	m_wndStatusBar.SetPaneWidth(2, 1); // very important :)
	m_wndStatusBar.SetPaneBackgroundColor(2, ::afxGlobalData.clrBarFace);
	m_wndStatusBar.SetPaneStyle(2, SBPS_STRETCH);
	m_wndStatusBar.SetPaneText(2, _T("Test"));
//..
}


这篇关于MFC状态栏-不能完全正常运行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆