hello.cpp

来自「采用VC++控件实现一个响应鼠标按钮事件的例子」· C++ 代码 · 共 47 行

CPP
47
字号
#include<afxwin.h>
#include<string.h>
#define IDB_BUTTON 100
class CButtonApp:public CWinApp
{
public:
	virtual BOOL InitInstance();
};
CButtonApp ButtonApp;
class CButtonWindow:public CFrameWnd
{
	CButton*button;
public:
	CButtonWindow();
	afx_msg void HandleButton();
	DECLARE_MESSAGE_MAP();
    
};
void CButtonWindow::HandleButton()
{
	char a[20];
	char str[20];
   gets(str);
	strcpy(a,"str");
	AfxMessageBox(a);
}
BEGIN_MESSAGE_MAP(CButtonWindow,CFrameWnd)//创建消息映射宏
ON_BN_CLICKED(IDB_BUTTON,HandleButton)//将鼠标单击按钮IDB_BUTTON事件与此消息的成员函数HandleButton联系在一起
END_MESSAGE_MAP()
BOOL CButtonApp::InitInstance()
{
	m_pMainWnd=new CButtonWindow();
	m_pMainWnd->ShowWindow(m_nCmdShow);
	m_pMainWnd->UpdateWindow();
	return TRUE;
}
CButtonWindow::CButtonWindow()
{
	CRect r;
	//创建窗口
	Create(NULL,"CButton Tests",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);
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?