代码
#include <iostream>
#include <Windows.h>
using namespace std;
LRESULT CALLBACK __WndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam) {
PAINTSTRUCT ps;
HDC hdc;
switch (msg) {
case WM_CLOSE:
MessageBox(NULL,"WM_CLOSE", "", NULL);
break;
default:
break;
}
return DefWindowProc(hWnd, msg, wParam, lParam);
}
int main()
{
HINSTANCE hIns = GetModuleHandle(0);
WNDCLASSEX wc;
wc.cbSize = sizeof(wc);
wc.style = CS_HREDRAW | CS_VREDRAW;
wc.cbClsExtra = 0;
wc.cbWndExtra = 0;
wc.hInstance = hIns;
wc.hIcon = NULL;
wc.hIconSm = NULL;
wc.hbrBackground = (HBRUSH)COLOR_WINDOW;
wc.hCursor = NULL;
wc.lpfnWndProc = __WndProc;
wc.lpszMenuName = NULL;
wc.lpszClassName = "LYSM_class";
if (!RegisterClassEx(&wc)) {
cout << "RegisterClassEx error : " << GetLastError() << endl;
}
HWND hWnd = CreateWindowEx(
WS_EX_TOPMOST,
"LYSM_class",
"LYSM_title",
WS_OVERLAPPEDWINDOW,
0,
0,
800,
600,
0,
0,
hIns,
0
);
if (hWnd == 0) {
cout << "CreateWindowEx error : " << GetLastError() << endl;
}
UpdateWindow(hWnd);
ShowWindow(hWnd, SW_SHOW);
MSG msg = { 0 };
while (msg.message != WM_QUIT) {
if (PeekMessage(&msg, 0, 0, 0, PM_REMOVE)) {
DispatchMessage(&msg);
}
}
cout << "finished." << endl;
getchar();
end:
getchar();
return 0;
}
效果图