/*★ 最もシンプルな Windows Program です 前田 稔 ★*/
#define NAME "Empty Program"
#define TITLE "Empty Sample Program"
#include <windows.h>
#pragma comment(lib, "user32.lib")
#pragma comment(lib, "gdi32.lib")
HINSTANCE g_hInst;
HWND g_hWnd;
// Function Prototype
LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
int APIENTRY WinMain(HINSTANCE, HINSTANCE, LPSTR, int);
//★ CALLBACK 関数
LRESULT CALLBACK WndProc(HWND hWnd,UINT msg,WPARAM wParam,LPARAM lParam)
{ PAINTSTRUCT ps;
HDC hdc;
//渡された message から、イベントの種類を解析する
switch(msg)
{ case WM_PAINT:
hdc= BeginPaint (hWnd, &ps);
TextOut(hdc, 40, 70, "Hello C++/CLI Windows!", 22);
EndPaint(hWnd, &ps);
break;
case WM_DESTROY:
PostQuitMessage(0);
return 0L;
}
//デフォルトの処理
return DefWindowProc(hWnd,msg,wParam,lParam);
}
//★ Windows Main 関数
int APIENTRY WinMain(HINSTANCE hInst, HINSTANCE, LPSTR, int nCmdShow)
{ MSG msg;
g_hInst= hInst;
WNDCLASS wc = { CS_CLASSDC,WndProc,0L,0L,hInst,NULL,LoadCursor(NULL,IDC_ARROW),
(HBRUSH)GetStockObject(WHITE_BRUSH),NULL,NAME };
if (RegisterClass(&wc)==0) return FALSE;
g_hWnd= CreateWindow(NAME,TITLE,WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT,CW_USEDEFAULT,400,200,
NULL,NULL,hInst,NULL);
if (!g_hWnd) return FALSE;
ShowWindow(g_hWnd,SW_SHOWDEFAULT);
UpdateWindow(g_hWnd);
SetFocus(g_hWnd);
while (GetMessage(&msg,NULL,0,0))
{ TranslateMessage(&msg);
DispatchMessage(&msg);
}
return S_OK; //return 0
}
|