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 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80
|
#ifdef UNICODE
#undef UNICODE
#endif
#include <windows.h>
WNDCLASSEX wnd;
HWND hWnd;
char lpszClassName[] = "MyWndClass";
MSG msg;
LRESULT CALLBACK WndProc(HWND hWnd, UINT Msg,WPARAM wParam, LPARAM lParam);
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShowCmd)
{
wnd.cbSize = sizeof(WNDCLASSEX);
wnd.style = CS_HREDRAW | CS_VREDRAW;
wnd.lpfnWndProc = WndProc;
wnd.cbClsExtra = 0;
wnd.cbWndExtra = 0;
wnd.hInstance = hInstance;
wnd.hIcon = LoadIcon(NULL, IDI_WINLOGO);
wnd.hCursor = LoadCursor(NULL, IDC_ARROW);
wnd.hbrBackground = (HBRUSH)GetStockObject(LTGRAY_BRUSH);
wnd.lpszMenuName = NULL;
wnd.lpszClassName = lpszClassName;
wnd.hIconSm = LoadIcon(NULL, IDI_WINLOGO);
if(!RegisterClassEx(&wnd))
{
MessageBox(NULL,"Error Registering Window Class", "Class Error", MB_ICONERROR | MB_OK);
return -1;
}
hWnd = CreateWindowEx(NULL,lpszClassName,"MyWindow",WS_OVERLAPPEDWINDOW, CW_USEDEFAULT,CW_USEDEFAULT, CW_USEDEFAULT,CW_USEDEFAULT,
NULL,NULL,hInstance,NULL);
if(!hWnd)
{
MessageBox(NULL,"Error Creating Window", "Window Error", MB_ICONERROR | MB_OK);
return -1;
}
ShowWindow(hWnd,nShowCmd);
while(GetMessage(&msg,hWnd,0,0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return 0;
}
LRESULT CALLBACK WndProc(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam)
{
PAINTSTRUCT ps;
HDC hDC;
switch(Msg)
{
case WM_DESTROY:
PostQuitMessage(0);
break;
case WM_CLOSE:
DestroyWindow(hWnd);
break;
case WM_PAINT:
{
hDC = BeginPaint(hWnd,&ps);
EndPaint(hWnd,&ps);
return 0;
}
break;
}
return DefWindowProc(hWnd,Msg,wParam,lParam);
}
|