响应CButton的ON_BN_CLICKED通告消息

/************************************************************************/
/* mywnd.h */
/************************************************************************/
#pragma once

#include
<afxwin.h>
#define BTNID 1

class MyWnd : public CFrameWnd
{
public:
MyWnd();
~MyWnd();
void InitButton();
afx_msg
void OnButtonClicked();
private:
CButton
*btn;
DECLARE_MESSAGE_MAP()
};

 

/************************************************************************/
/* myapp.h */
/************************************************************************/
#pragma once
#include
<afxwin.h>

class MyApp : public CWinApp
{
public:
virtual BOOL InitInstance();
DECLARE_MESSAGE_MAP()
};

 

 

/************************************************************************/
/* mywnd.cpp */
/************************************************************************/
#include
"mywnd.h"

BEGIN_MESSAGE_MAP(MyWnd, CFrameWnd)
ON_BN_CLICKED(BTNID,
&MyWnd::OnButtonClicked)
END_MESSAGE_MAP()

MyWnd::MyWnd() : btn(
0)
{
Create(NULL, _T(
"MyWnd"));
InitButton();
}
MyWnd::
~MyWnd()
{
if(btn) delete btn;
}
void MyWnd::InitButton()
{
btn
= new CButton;
btn
->Create(_T("OK"), BS_DEFPUSHBUTTON | WS_CHILD | WS_VISIBLE, CRect(100, 100, 200, 200), this, BTNID);
}

void MyWnd::OnButtonClicked()
{
MessageBox(_T(
"Hello, Button!"));
}

 

 

 

/************************************************************************/
/* myapp.cpp */
/************************************************************************/
#include
"myapp.h"
#include
"mywnd.h"

BEGIN_MESSAGE_MAP(MyApp, CWinApp)
END_MESSAGE_MAP()

MyApp theApp;

BOOL MyApp::InitInstance()
{
m_pMainWnd
= new MyWnd;

m_pMainWnd
->ShowWindow(SW_SHOWNORMAL);
m_pMainWnd
->UpdateData();
return TRUE;
}

 

posted @ 2010-07-12 22:47  penink  阅读(3994)  评论(0)    收藏  举报