WinApp
Visual C++ 2005 Express Edition
Windows Server 2003 SP1 Platform SDK
Windowsアプリケーション / 空のプロジェクト
WinApp.c
// マルチバイト文字セット #include
#define APPNAME "WinApp" // グローバル変数 static HINSTANCE g_hInstance; // プロトタイプ宣言 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) { char acAppName[] = APPNAME; WNDCLASSEX wcex; HWND hWnd; MSG msg; g_hInstance = hInstance; wcex.cbSize = sizeof(WNDCLASSEX); wcex.style = CS_HREDRAW | CS_VREDRAW; wcex.lpfnWndProc = WndProc; wcex.cbClsExtra = 0; wcex.cbWndExtra = 0; wcex.hInstance = g_hInstance; wcex.hIcon = LoadIcon(NULL, IDI_APPLICATION); wcex.hCursor = LoadCursor(NULL, IDC_ARROW); wcex.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1); wcex.lpszMenuName = NULL; wcex.lpszClassName = acAppName; wcex.hIconSm = LoadIcon(NULL, IDI_APPLICATION); RegisterClassEx(&wcex); hWnd = CreateWindow( acAppName, // ClassName acAppName, // WindowName WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, // x CW_USEDEFAULT, // y CW_USEDEFAULT, // Width CW_USEDEFAULT, // Height NULL, // WndParent NULL, // Menu g_hInstance, NULL); // Param 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; hdc = BeginPaint(hWnd, &ps); TextOut(hdc, 0, 0, "hello, world", 12); EndPaint(hWnd, &ps); }