// マルチバイト文字セット #include #include #include LRESULT CALLBACK WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam); void OnPaint(HWND hWnd); int WINAPI WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) { const char acClassName[] = "HelloWin"; WNDCLASSEX wcex; HWND hWnd; MSG msg; // ウィンドウクラスの登録 wcex.cbSize = sizeof wcex; wcex.style = CS_HREDRAW | CS_VREDRAW; wcex.lpfnWndProc = WndProc; wcex.cbClsExtra = 0; wcex.cbWndExtra = 0; wcex.hInstance = hInstance; wcex.hIcon = LoadIcon(NULL, IDI_APPLICATION); wcex.hCursor = LoadCursor(NULL, IDC_ARROW); wcex.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1); wcex.lpszMenuName = NULL; wcex.lpszClassName = acClassName; wcex.hIconSm = LoadIcon(NULL, IDI_APPLICATION); if (RegisterClassEx(&wcex) == 0) { return 0; } // ウィンドウの作成 hWnd = CreateWindow( acClassName, // ClassName "Hello Windows", // WindowName WS_OVERLAPPEDWINDOW,// Style CW_USEDEFAULT, // x 0, // y CW_USEDEFAULT, // Width 0, // Height NULL, // WndParent NULL, // Menu hInstance, NULL); if (hWnd == NULL) { return 0; } ShowWindow(hWnd, nCmdShow); UpdateWindow(hWnd); while (GetMessage(&msg, NULL, 0, 0)) { TranslateMessage(&msg); DispatchMessage(&msg); } return (int)msg.wParam; } LRESULT CALLBACK WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) { switch (uMsg) { case WM_PAINT: OnPaint(hWnd); break; case WM_DESTROY: PostQuitMessage(0); break; default: return DefWindowProc(hWnd, uMsg, wParam, lParam); } return 0; } void OnPaint(HWND hWnd) { HDC hdc; PAINTSTRUCT ps; RECT rect; char acString[64]; hdc = BeginPaint(hWnd, &ps); GetClientRect(hWnd, &rect); DrawText(hdc, "hello, world", -1, &rect, DT_SINGLELINE | DT_CENTER | DT_VCENTER); sprintf_s(acString, sizeof acString, "W=%d H=%d", rect.right, rect.bottom); TextOut(hdc, 0, 0, acString, strlen(acString)); EndPaint(hWnd, &ps); }