#include "afxwin.h"#define IDB_BUTTON 100
#define IDT_TIMER 200class CButtonApp:public CWinApp
{
public:
virtual BOOL InitInstance();
};CButtonApp ButtonApp;class CButtonWin:public CFrameWnd
{
CButton *Button;
public:
CButtonWin(); afx_msg void HandleButton();
afx_msg void OnSize(UINT,int,int);
afx_msg void OnTimer(UINT);
DECLARE_MESSAGE_MAP();
};void CButtonWin::OnTimer(UINT id)
{
MessageBeep(-1);
}void CButtonWin::OnSize(UINT,int cx ,int cy)
{
CRect r;
GetClientRect(&r);
r.InflateRect(-20,-20);
Button->MoveWindow(r);
}void CButtonWin::HandleButton()
{
MessageBeep(-1);
}BEGIN_MESSAGE_MAP(CButtonWin,CFrameWnd)
ON_BN_CLICKED(IDB_BUTTON,HandleButton)
ON_WM_SIZE()
ON_WM_TIMER()
END_MESSAGE_MAP()
BOOL CButtonApp::InitInstance()
{
m_pMainWnd = new CButtonWin();
m_pMainWnd->ShowWindow(m_nCmdShow);
m_pMainWnd->UpdateData();
return TRUE;
}CButtonWin::CButtonWin()
{
CRect r;
SetTimer(IDT_TIMER,1000,NULL);
Create(NULL,"hello button!!!",WS_OVERLAPPEDWINDOW,CRect(0,0,200,200));
GetClientRect(&r);
r.InflateRect(-20,-20);
Button = new CButton();
Button->Create("push me",WS_CHILD | WS_VISIBLE |BS_PUSHBUTTON,r,this,IDB_BUTTON);
}
大家帮我看看,我运行时候,语法没有问题,可就是出现出错对话框,大家可以帮我看看是什么原因吗?谢谢你了