#define _WIN32_WINNT 0x400 #define WINVER 0x400 #include <windows> using namespace std; long WINAPI WndProc(HWND hwnd,UINT msg,UINT wParam,LONG lParam) { PAINTSTRUCT ps; switch(msg){ case WM_CREATE: break; case WM_DESTROY: PostQuitMessage(0); break; case WM_SIZE: break; case WM_PAINT: BeginPaint(hwnd,&ps); TextOut(ps.hdc,0,0,"Hello World!",12); EndPaint(hwnd,&ps); break; default: return DefWindowProc(hwnd,msg,wParam,lParam); } return(0); } int WINAPI WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance, LPSTR, int nCmdShow) { HWND hwnd; MSG msg; WNDCLASS wc; /*window型のアプリを作る.*/ if(!hPrevInstance){ wc.style = CS_HREDRAW|CS_VREDRAW; /* Windowスタイル */ wc.lpfnWndProc = WndProc; /* イベントハンドラの定義 */ wc.cbClsExtra = 0; wc.cbWndExtra = 0; wc.hInstance = hInstance; /* 自分のインスタンスをセット */ wc.hIcon = NULL; /* ICONは使わないのでNULL */ wc.hCursor = LoadCursor(NULL,IDC_ARROW); wc.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH); wc.lpszMenuName = NULL; wc.lpszClassName = "HelloWorld" ; RegisterClass(&wc) ; /* winOsに通知・登録する.*/ } hwnd=CreateWindow( "HelloWorld", "Test Program Windows sample 001", WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, 400+GetSystemMetrics(SM_CXBORDER)*2, 200+GetSystemMetrics(SM_CYCAPTION) +GetSystemMetrics(SM_CYMENU) +GetSystemMetrics(SM_CYBORDER) * 2, NULL, NULL, hInstance, NULL); /*このhInstanceのポインターをhwndに渡す*/ ShowWindow(hwnd,nCmdShow); UpdateWindow(hwnd); while(GetMessage(&msg,NULL,0,0)){ /*msgループ*/ TranslateMessage(&msg); DispatchMessage(&msg); } return msg.wParam; } |