新建一个窗口程序
消息机制
创建窗口的几个步骤
- 创建窗口类
- 注册窗口类
- 创建窗口
- 显示窗口
- 构建消息循环
创建过程
demo : https://github.com/luodaoyi/cpp_code/tree/master/MemoryInjectTool/CreateWindows
//1 创建窗口类型模板
WNDCLASS wndclass = { 0 };
wndclass.lpszClassName = className; //名字
wndclass.hbrBackground = (HBRUSH)COLOR_BACKGROUND; //背景画笔句柄
wndclass.hInstance = hInstance; //窗口过程的实例句柄
wndclass.lpfnWndProc = WndProc; //窗口过程函数
//2 注册窗口
RegisterClass(&wndclass);
//3 创建窗口
HWND hwindows = CreateWindow(className, TEXT("MYWINDOWS"), WS_OVERLAPPEDWINDOW, 500, 300, 300, 250, NULL, NULL, hInstance,NULL);
//创建窗口
HWND hsitc1 = CreateWindow(L"STATIC", TEXT("账号:"), WS_CHILD | WS_VISIBLE, 10, 30, 50, 20, hwindows, HMENU(IDC_STATIC1), hInstance, NULL);
HWND hstic2 = CreateWindow(L"STATIC", TEXT("密码"), WS_CHILD | WS_VISIBLE, 10, 80, 50, 20, hwindows, HMENU(IDC_STATIC2), hInstance, NULL);
HWND hedit1 = CreateWindow(L"EDIT", NULL, WS_CHILD | WS_VISIBLE, 80, 30, 100, 20, hwindows, HMENU(IDC_EDIT1), hInstance, NULL);
HWND hedit2 = CreateWindow(L"EDIT", NULL, WS_CHILD | WS_VISIBLE, 80, 80, 100, 20, hwindows, HMENU(IDC_EDIT2), hInstance, NULL);
HWND hbutt1 = CreateWindow(L"BUTTON", TEXT("登录"), WS_CHILD | WS_VISIBLE, 50, 120, 50, 25, hwindows, HMENU(IDC_BUTTM1), hInstance, NULL);
HWND hbutt2 = CreateWindow(L"BUTTON", TEXT("取消"), WS_CHILD | WS_VISIBLE, 110, 120, 50, 25, hwindows, HMENU(IDC_BUTTM2), hInstance, NULL);
//4 显示窗口
ShowWindow(hwindows,SW_SHOW);
//5 构建消息循环
MSG msg = { NULL };
while (GetMessage(&msg,NULL,NULL,NULL))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}