创建button,并实现ON_BN_CLICKED消息(C++)
(2013-03-11 15:51:22)
标签:
函数c文件消息it |
分类: VC |
- 定义CButton变量为类的成员变量;
CButton button; - 定义该按钮的ID;
#define IDC_BUTTON1 8888 - 在适当的地方创建按钮;
button.Create("BUTTON", WS_VISIBLE | WS_CHILD | WS_BORDER | BS_AUTO3STATE,
CRect(10 , 10, 100, 40), this, IDC_BUTTON1 );
在头文件中定义消息响应函数;
// Generated message map functions
//{{AFX_MSG(CDialogTestDlg)
virtual BOOL OnInitDialog();
afx_msg void OnSysCommand(UINT nID, LPARAM lParam);
afx_msg void OnPaint();
afx_msg HCURSOR OnQueryDragIcon();
//}}AFX_MSG
afx_msg void
OnBnClicked();
DECLARE_MESSAGE_MAP()
在CPP文件中完成消息路有;
BEGIN_MESSAGE_MAP(CDialogTestDlg, CDialog)
//{{AFX_MSG_MAP(CDialogTestDlg)
ON_WM_SYSCOMMAND()
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
//}}AFX_MSG_MAP
ON_BN_CLICKED(IDC_BUTTON1,
OnBnClicked)
END_MESSAGE_MAP()
完成消息函数本身;
void CDialogTestDlg::OnBnClicked()
{
AfxMessageBox("Button1");
}

加载中…