自己创建的CMyStatusBar,然后又在CSMyStatusBar上创建CButton,但Button是灰色的。代码如下,请大家帮一下,谢谢!
int CMyStatusBar::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
if (CStatusBar::OnCreate(lpCreateStruct) == -1)
return -1;
// TODO: Add your specialized creation code here
CRect rc(0,0,0,0);
m_btn.Create("Hello",WS_VISIBLE | WS_CHILD | BS_PUSHBUTTON,rc,this,IDC_BUTTON);
return 0;
}void CMyStatusBar::OnSize(UINT nType, int cx, int cy)
{
CStatusBar::OnSize(nType, cx, cy);
// TODO: Add your message handler code here
CRect rc;
int Index;
Index=CommandToIndex(IDC_BUTTON);
GetItemRect(9,&rc);
rc.left=30;
rc.top=10;
rc.right=rc.left+50;
rc.bottom=rc.top+25;
m_btn.MoveWindow(&rc,TRUE);
}
int CMyStatusBar::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
if (CStatusBar::OnCreate(lpCreateStruct) == -1)
return -1;
// TODO: Add your specialized creation code here
CRect rc(0,0,0,0);
m_btn.Create("Hello",WS_VISIBLE | WS_CHILD | BS_PUSHBUTTON,rc,this,IDC_BUTTON);
return 0;
}void CMyStatusBar::OnSize(UINT nType, int cx, int cy)
{
CStatusBar::OnSize(nType, cx, cy);
// TODO: Add your message handler code here
CRect rc;
int Index;
Index=CommandToIndex(IDC_BUTTON);
GetItemRect(9,&rc);
rc.left=30;
rc.top=10;
rc.right=rc.left+50;
rc.bottom=rc.top+25;
m_btn.MoveWindow(&rc,TRUE);
}
int CMyStatusBar::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
if (CStatusBar::OnCreate(lpCreateStruct) == -1)
return -1; // TODO: Add your specialized creation code here
CRect rc(0,0,0,0);
m_btn.Create("Hello",WS_VISIBLE | WS_CHILD | BS_PUSHBUTTON,rc,this,IDC_BUTTON);
return 0;
} void CMyStatusBar::OnSize(UINT nType, int cx, int cy)
{
CStatusBar::OnSize(nType, cx, cy); // TODO: Add your message handler code here
CRect rc;
int Index; Index=CommandToIndex(IDC_BUTTON);
GetItemRect(0,&rc);
rc.left=30;
rc.top=10;
rc.right=rc.left+50;
rc.bottom=rc.top+25;
m_btn.MoveWindow(&rc,TRUE);
}
建议你也从CSDN上下载“特色状态栏”的代码研究一下。
还有,我重载的CStatusBar是不是也要重载CPaneInfo?如果重载CPaneInfo的话,可能我这里的麻烦就大了,只有重载CPaneInfo.希望得到大家的指导.
.h 中
class CBStatusBar : public CStatusBar
{
public:
...
CButton m_wndButton;
protected:
afx_msg int OnCreate(LPCREATESTRUCT lpCreateStruct);
DECLARE_MESSAGE_MAP()
};
.cpp中
...
int CBStatusBar::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
if (CStatusBar::OnCreate(lpCreateStruct) == -1)
return -1;
CRect rect(0, 0, 70, 18) // 测试值,具体参考msdn
m_wndButton.Create(_T("Button1"), BS_PUSHBUTTON, rect, this, -1);
m_wndButton.ShowWindow(SW_SHOW);
return 0;
}
以上是最简单的派生方法,注意在MainFrame中要把CStatusBar m_wndStatusBar 改成 CBStatusBar m_wndStatusBar!
你的按钮是灰色的,时因为这个按钮没有添加消息响应。你可以把CBStatusBar中的那个成员变量——CButton m_wndButton;改成一个派生的CMyButton,然后就能在其中为按钮添加消息映射了,完全自定义,爽吧
{
if (CStatusBar::OnCreate(lpCreateStruct) == -1)
return -1; // TODO: Add your specialized creation code here
CRect rc(0,0,0,0);
m_btn.Create("Hello",WS_VISIBLE | WS_CHILD | BS_PUSHBUTTON,rc,this,IDC_BUTTON);
return 0;
} void CMyStatusBar::OnSize(UINT nType, int cx, int cy)
{
CStatusBar::OnSize(nType, cx, cy); // TODO: Add your message handler code here
CRect rc;
int Index; Index=CommandToIndex(IDC_BUTTON);
GetItemRect(0,&rc);
rc.left=30;
rc.top=10;
rc.right=rc.left+50;
rc.bottom=rc.top+25;
m_btn.MoveWindow(&rc,TRUE);
}