クラスを使ってみます。
ファイルは、"win134.cpp" です。
/* よくあるウィンドウズプログラム */ #include <windows.h> #include <tchar.h> #include <MyWndClass.h> #include <MyCreateStruct.h> // アプリケーション開始位置 int APIENTRY _tWinMain(HINSTANCE hInstance, HINSTANCE, LPTSTR, int nCmdShow) { hInst = hInstance; // インスタンスハンドル保存 TCHAR AppName[] = L"win134"; // メインウィンドウのクラス名 TCHAR AppTitle[] = L"よくあるウィンドウズプログラム"; // タイトル MSG msg; // MSG構造体 MyWndClass wc(AppName); // WNDCLASSEX構造体 MyCreateStruct cs; // CREATESTRUCT構造体 cs.Name(AppName); // クラス名 cs.Text(AppTitle); // キャプション // ToDo ウィンドウの定義 // ウインドウクラスの登録 if(RegisterClassEx(&wc) == 0) return 0; // ウインドウの作成 hWnd = cs.Create(); if(hWnd == NULL) return 0; // ウィンドウの表示 ShowWindow(hWnd, nCmdShow); UpdateWindow(hWnd); // メッセージループ while(GetMessage(&msg, NULL, 0, 0)) { TranslateMessage(&msg); DispatchMessage(&msg); } return msg.wParam; } // ウインドウプロシージャ LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wp, LPARAM lp) { hWnd = hwnd; switch(msg) { case WM_DESTROY: PostQuitMessage(0); // メッセージループの終了 break; default: return DefWindowProc(hWnd, msg, wp, lp); // 既定のウィンドウプロシージャ } return 0; }
実行画面です。