一、新建空项目,属性设置为窗口
二、新建一个CPP文件,添加一个dialog资源
三、编写主框架代码
#define _CRT_SECURE_NO_WARNINGS #include <Windows.h> #include <Windowsx.h> #include "resource.h" #include <tchar.h> INT WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, PSTR lpCmdLine, INT nCmdShow) { int n = DialogBox(hInstance, (LPCWCHAR)IDD_JISHIBEN, NULL, NULL); return 0; }
四、让项目居中显示
int 窗口初始化(HWND hDlg) { RECT rect; GetWindowRect(hDlg, &rect);//获取窗口高宽 int px = GetSystemMetrics(SM_CXFULLSCREEN);//获取屏幕高宽 int py = GetSystemMetrics(SM_CYFULLSCREEN); int wx = rect.right - rect.left; int wy = rect.bottom - rect.top; MoveWindow(hDlg, (px - wx) / 2, (py - wy) / 2, wx, wy, FALSE); return 0; } INT_PTR CALLBACK theProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam) { int x = GET_X_LPARAM(lParam); int y = GET_Y_LPARAM(lParam); switch (uMsg) { case WM_INITDIALOG: 窗口初始化(hwndDlg);//窗口启动时运行 break; } return 0; }
五、添加一个编辑框,运行看效果,记事本大致框架就出来了