VS2019新建C++桌面向导:
// Project1.cpp : 定义应用程序的入口点。
//
#include "framework.h"
#include "Project1.h"
INT_PTR Dlgproc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam);
int APIENTRY wWinMain(_In_ HINSTANCE hInstance,
_In_opt_ HINSTANCE hPrevInstance,
_In_ LPWSTR lpCmdLine,
_In_ int nCmdShow)
{
DialogBox(hInstance, MAKEINTRESOURCE(ID_MAIN), NULL, (DLGPROC)Dlgproc);
return 0;
}
INT_PTR Dlgproc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
if (uMsg == WM_INITDIALOG) {
// MessageBox(NULL, "首次加载", "标题", 0);
}
if (uMsg == WM_CLOSE) {
EndDialog(hwndDlg, 0);
}
// 所有界面上按钮时间都走WM_COMMAND
if (uMsg == WM_COMMAND) {
if (wParam == ID_OK) {
MessageBox(NULL, "点击了确定按钮", "确定", 0);
}
if (wParam == ID_CANCEL) {
MessageBox(NULL, "点击了取消按钮", "取消", 0);
}
}
return 0;
}