1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62
| #include "tchar.h" #include <windows.h>
LRESULT CALLBACK WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) { switch (uMsg) { case WM_CLOSE: { ::DestroyWindow(hWnd); } break; case WM_DESTROY: { ::PostQuitMessage(0); } break; } return DefWindowProc(hWnd, uMsg, wParam, lParam); } int WINAPI _tWinMain(IN HINSTANCE hInstance, IN HINSTANCE hPrevInstance, IN LPTSTR lpCmdLine, IN int nShowCmd) { const TCHAR* pszClassName = _T("ITWnd");
WNDCLASSEX wcex; wcex.cbSize = sizeof(WNDCLASSEX); wcex.style = CS_HREDRAW | CS_VREDRAW; wcex.lpfnWndProc = WndProc; wcex.cbClsExtra = 0; wcex.cbWndExtra = 0; wcex.hInstance = hInstance; wcex.hIcon = (HICON)::LoadIcon(NULL, IDI_QUESTION); wcex.hIconSm = (HICON)::LoadIcon(NULL, IDI_QUESTION); wcex.hbrBackground = (HBRUSH)::GetStockObject(WHITE_BRUSH); wcex.hCursor = (HCURSOR)::LoadCursor(NULL, IDC_ARROW); wcex.lpszMenuName = NULL; wcex.lpszClassName = pszClassName; BOOL bRet = ::RegisterClassEx(&wcex); if (!bRet) { ::MessageBox(NULL, _T("注册窗口类失败"), _T("注册窗口"), 0); return FALSE; } HWND hWnd = ::CreateWindowEx(0, pszClassName, _T("模仿"), WS_VISIBLE | WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, NULL, NULL, hInstance,NULL); if (NULL == hWnd) { ::MessageBox(NULL, _T("创建窗口失败"), _T("创建窗口"), 0); return FALSE; }
::ShowWindow(hWnd,SW_SHOW); ::UpdateWindow(hWnd);
MSG msg; while (::GetMessage(&msg, NULL, NULL, NULL)) { ::TranslateMessage(&msg); ::DispatchMessageW(&msg); } }
|