其实按照创建窗口的方法就可以了。
过后包装一下子。
#include <cstdio>
#include <Windows.h>
WNDCLASSA wc = { };
HINSTANCE hInst;
HWND hWnd;
MSG msg = { };
LRESULT CALLBACK WindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
int main(int count, char** strings) {
hInst = GetModuleHandleA(NULL);
wc.hInstance = hInst;
wc.lpfnWndProc = WindowProc;
wc.lpszClassName = "TEST";
RegisterClassA(&wc);
hWnd = CreateWindowExA(
0, "TEST",
(LPCSTR)L"TEST", // 我不知道这里到底发生了什么,字符串乱码
WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT, CW_USEDEFAULT,
CW_USEDEFAULT, CW_USEDEFAULT,
NULL, NULL,
hInst,
NULL
);
if (hWnd == NULL)return -1;
ShowWindow(hWnd, SW_SHOW);
UpdateWindow(hWnd);
while (GetMessage(&msg, NULL, 0, 0) > 0)
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return 0;
}
LRESULT CALLBACK WindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
switch (uMsg)
{
case WM_DESTROY:
PostQuitMessage(0);
return 0;
case WM_PAINT:
{
PAINTSTRUCT ps;
HDC hdc = BeginPaint(hwnd, &ps);
// TODO
FillRect(hdc, &ps.rcPaint, (HBRUSH)(COLOR_WINDOW + 1));
EndPaint(hwnd, &ps);
}
return 0;
}
return DefWindowProc(hwnd, uMsg, wParam, lParam);
}
效果: