MFC 实现button window
这里用mfc来实现一遍。运行效果与汇编那个一样。
#include <afxwin.h>
// 主窗口框架
class ButtonWin : public CWnd
{
public:
ButtonWin()
{
//创建窗口
this->CreateEx(NULL, (LPCTSTR)_T("button"), (LPCTSTR)_T("buttonwin test"), WS_POPUP, 100,100,300,300,NULL,NULL,NULL);
}
private:
// 重载窗口过程
LRESULT WindowProc(UINT message, WPARAM wParam, LPARAM lParam)
{
if(message == WM_KEYDOWN)
{
if(wParam == VK_ESCAPE)
::PostQuitMessage(0);
}
else if(message == WM_LBUTTONDOWN)
{
::SendMessage(this->m_hWnd,WM_NCLBUTTONDOWN,HTCAPTION,NULL);
}
else
return CWnd::WindowProc(message, wParam, lParam);;
}
};
// 应用程序类
class ButtonApp : public CWinApp
{
public:
BOOL InitInstance()
{
ButtonWin *pFrame = new ButtonWin();
this->m_pMainWnd = pFrame;
pFrame->ShowWindow(SW_SHOWNORMAL);
return TRUE;
}
};
ButtonApp theApp;
以上代码里面,如果用CButton替换CWnd ,效果也一样。