想在多文档的子窗口视图上画个能用的按钮,但不知道哪里错了,执行不了。大家帮忙看看哈~,谢谢~
在class CMDIsplitView 头文件类中声明:
public CButton m_btn3;
protected:
//{{AFX_MSG(CMDIsplitView)
afx_msg int OnCreate(LPCREATESTRUCT lpCreateStruct);
afx_msg void Onbtn3();
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
.CPP文件中:
BEGIN_MESSAGE_MAP(CMDIsplitView, CView)
//{{AFX_MSG_MAP(CMDIsplitView)
ON_WM_CREATE()
//}}AFX_MSG_MAP
// Standard printing commands
ON_BN_CLICKED(20,Onbtn3)
END_MESSAGE_MAP()
再创建个按钮,
int CMDIsplitView::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
if (CView::OnCreate(lpCreateStruct) == -1)
return -1;
// TODO: Add your specialized creation code here
m_btn3.Create(_T("button3"), WS_CHILD|WS_VISIBLE|BS_PUSHBUTTON,
CRect(20,20,10,40),this, 20); return 0;
}
函数响应:
void CMDIsplitView::Onbtn3()
{
CClientDC dc(this);
dc.TextOut(0,0,"hii");
}
哪里出错了呢??
在class CMDIsplitView 头文件类中声明:
public CButton m_btn3;
protected:
//{{AFX_MSG(CMDIsplitView)
afx_msg int OnCreate(LPCREATESTRUCT lpCreateStruct);
afx_msg void Onbtn3();
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
.CPP文件中:
BEGIN_MESSAGE_MAP(CMDIsplitView, CView)
//{{AFX_MSG_MAP(CMDIsplitView)
ON_WM_CREATE()
//}}AFX_MSG_MAP
// Standard printing commands
ON_BN_CLICKED(20,Onbtn3)
END_MESSAGE_MAP()
再创建个按钮,
int CMDIsplitView::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
if (CView::OnCreate(lpCreateStruct) == -1)
return -1;
// TODO: Add your specialized creation code here
m_btn3.Create(_T("button3"), WS_CHILD|WS_VISIBLE|BS_PUSHBUTTON,
CRect(20,20,10,40),this, 20); return 0;
}
函数响应:
void CMDIsplitView::Onbtn3()
{
CClientDC dc(this);
dc.TextOut(0,0,"hii");
}
哪里出错了呢??
CRect(20,20,10,40),this, 20);
红色的地方错了,看下CRect的构造函数
CRect(
int l,
int t,
int r,
int b
) throw( );
其中:
l:
Specifies the left position of CRect.
t:
Specifies the top of CRect.
r:
Specifies the right position of CRect.
b:
Specifies the bottom of CRect.
即(l, t)是按钮的左上角点的坐标,(r, b)是按钮的左下角点的坐标
按照楼主的代码CRect(20,20,10,40),应该改成CRect(10,20,20,40)
不过这样的按钮很小个,呵呵
在class CChildFrame 中声明CToolBar m_wndChildToolBar;
怎么在view中调用呢?
在click中创建 m_wndChildToolBar的思想,能实现么?