|

楼主 |
发表于 2020-6-27 20:30:14
|
显示全部楼层
- #include <Windows.h>
- LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
- int WINAPI WinMain(HINSTANCE hInstance,
- HINSTANCE hPrevInstance,
- PSTR szCmdLine,
- int iCmdShow)
- {
- WNDCLASS wndclass;
- TCHAR szAppName[] = TEXT("MyWindows");
- wndclass.hInstance = hInstance;
- wndclass.lpfnWndProc = WndProc;
- wndclass.style = CS_VREDRAW | CS_HREDRAW;
- wndclass.cbClsExtra = wndclass.cbWndExtra = 0;
- wndclass.hIcon = LoadIcon(NULL, IDI_APPLICATION);
- wndclass.hCursor = LoadCursor(NULL, IDC_ARROW);
- wndclass.hInstance = hInstance;
- wndclass.lpszClassName = szAppName;
- wndclass.lpszMenuName = NULL;
- wndclass.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH);
- if (!RegisterClass(&wndclass))
- {
- MessageBox(NULL, TEXT("J"),szAppName,MB_OK | MB_ICONERROR);
- return 0;
- }
- HWND hwnd;
- hwnd = FindWindow(szAppName, TEXT("沙雕工作室"));
- if (hwnd != NULL)
- {
- ShowWindow(hwnd,SW_SHOW);
- return 0;
- }
- do
- {
- hwnd = CreateWindowEx(WS_EX_LEFT,
- szAppName,
- TEXT("沙雕工作室"),
- WS_OVERLAPPEDWINDOW,
- CW_USEDEFAULT,
- CW_USEDEFAULT,
- CW_USEDEFAULT,
- CW_USEDEFAULT,
- NULL,
- NULL,
- hInstance,
- NULL);
- } while (hwnd == NULL);
- ShowWindow(hwnd, iCmdShow);
- UpdateWindow(hwnd);
- MSG msg;
- while (GetMessage(&msg, hwnd, 0, 0))
- {
- TranslateMessage(&msg);
- DispatchMessage(&msg);
- }
- return msg.wParam;
- }
- LRESULT CALLBACK WndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
- {
- HDC hdc;
- PAINTSTRUCT ps;
- RECT rect;
- switch (message)
- {
- case WM_PAINT:
- hdc = BeginPaint(hwnd, &ps);
- GetClientRect(hwnd, &rect);
- DrawText(hdc, TEXT("Hello World!"), -1, &rect, DT_VCENTER | DT_CENTER | DT_SINGLELINE);
-
- EndPaint(hwnd, &ps);
- return 0;
- case WM_DESTROY:
- PostQuitMessage(0);
- exit(0);
- return 0;
- default:
- return DefWindowProc(hwnd, message, wParam, lParam);
- }
-
- }
复制代码 |
|