ほぼ基本形。ほぼ。
ソースファイル
#include <Windows.h>
//ウィンドウプロシージャ
LRESULT CALLBACK WndProc( HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam )
{
switch(msg)
{
case WM_PAINT:
break;
case WM_CLOSE:
break;
case WM_DESTROY:
PostQuitMessage(0);
return 0;
}
return DefWindowProc( hWnd, msg, wParam, lParam );
}
//メイン関数
int WINAPI WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow )
{
int width = 640;
int height = 480;
int windowHeight = height + GetSystemMetrics( SM_CYFRAME ) * 2 + GetSystemMetrics( SM_CYCAPTION );
int windowWidth = width + GetSystemMetrics( SM_CXFRAME ) * 2 ;
WCHAR* className = L"class_win32_template";
WCHAR* titleName = L"title_win32_template";
MSG msg;
//ウィンドウクラス
WNDCLASSEX wc;
wc.cbSize = sizeof(wc);
wc.style = CS_HREDRAW | CS_VREDRAW;
wc.lpfnWndProc = WndProc;
wc.cbClsExtra = 0;
wc.cbWndExtra = 0;
wc.hInstance = hInstance;
wc.hIcon = (HICON)LoadImage( NULL, MAKEINTRESOURCE(IDI_APPLICATION), IMAGE_ICON, 0, 0, LR_SHARED );
wc.hCursor = (HCURSOR)LoadImage( NULL, MAKEINTRESOURCE(IDC_ARROW), IMAGE_CURSOR, 0, 0, LR_SHARED );
wc.hbrBackground = (HBRUSH)( COLOR_APPWORKSPACE + 1 );
wc.lpszMenuName = NULL;
wc.lpszClassName = className;
wc.hIconSm = (HICON)LoadIcon( NULL, IDI_APPLICATION );
//ウィンドウクラスの登録
if( !RegisterClassEx(&wc) ) return 0;
//ウィンドウの生成
HWND hWnd = CreateWindow( className, titleName, WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, windowWidth, windowHeight, NULL, NULL, hInstance, NULL );
//ウィンドウの表示・更新
ShowWindow(hWnd, SW_SHOW);
UpdateWindow(hWnd);
//メッセージループ
while( GetMessage(&msg, NULL, 0, 0) )
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return 0;
}