1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59
|
#include <Windows.h>;
LRESULT CALLBACK WindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
int WINAPI wWinMain(HINSTANCE hInstance,HINSTANCE,PWSTR nCmdLine, int nCmdShow)
{
const LPCSTR CLASS_NAME = "WindowClass";
WNDCLASS wc = { };
wc.lpfnWndProc = WindowProc;
wc.lpszClassName = CLASS_NAME;
wc.hInstance = hInstance;
RegisterClass(&wc);
HWND hwnd = CreateWindowEx(
0,
CLASS_NAME,
"My First Window",
WS_OVERLAPPEDWINDOW,
500,
500,
200,
200,
NULL,
NULL,
hInstance,
NULL);
if(hwnd==0) {
return 0;
}
ShowWindow(hwnd,nCmdShow);
nCmdShow=1;
MSG msg = { };
while(GetMessage(&msg,NULL,0,0)) {
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return 0;
}
LRESULT CALLBACK WindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam) {
switch(uMsg) {
case WM_DESTROY: {}PostQuitMessage(0); return 0;
case WM_PAINT:
{
PAINTSTRUCT ps;
HDC hdc = BeginPaint(hwnd,&ps);
FillRect(hdc,&ps.rcPaint,(HBRUSH)(COLOR_WINDOW+5));
EndPaint(hwnd,&ps);
}return 0;
case WM_CLOSE:
{
if(MessageBox(hwnd,"Close Window?","Close",MB_OKCANCEL)==IDOK) {
DestroyWindow(hwnd);
}
}return 0;
}
return DefWindowProc(hwnd,uMsg,wParam,lParam);
}
|