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 81 82 83 84 85 86 87 88 89 90
|
#include <windows.h>
class WinClass
{
public:
WinClass(WNDPROC winProc, char const* className, HINSTANCE hInst);
void Register() {RegisterClass(&_class);}
private:
WNDCLASS _class;
};
WinClass::WinClass(WNDPROC winProc, char const* className, HINSTANCE hInst)
{
_class.style = 0;
_class.lpfnWndProc = winProc; // window procedure: mandatory
_class.cbClsExtra = 0;
_class.cbWndExtra = 0;
_class.hInstance = hInst; // owner of the class: mandatory
_class.hIcon = 0;
_class.hCursor = LoadCursor (0, IDC_ARROW); // optional
_class.hbrBackground = (HBRUSH) (COLOR_WINDOW + 1); // optional
_class.lpszMenuName = 0;
_class.lpszClassName = className; // mandatory
}
class WinMaker
{
public:
WinMaker (): _hwnd (0) {}
WinMaker(char const* caption, char const* className, HINSTANCE hInstance);
WinMaker(char const* caption, char const* classname, int x, int y, int cx, int cy, HINSTANCE hInstance);
void Show(int cmdShow)
{
ShowWindow (_hwnd, cmdShow);
UpdateWindow (_hwnd);
}
protected:
HWND _hwnd;
};
WinMaker::WinMaker(char const* caption, char const* className, HINSTANCE hInstance)
{
_hwnd=CreateWindow(className,caption,WS_OVERLAPPEDWINDOW,CW_USEDEFAULT,CW_USEDEFAULT,CW_USEDEFAULT,CW_USEDEFAULT,0,0,hInstance,0);
}
WinMaker::WinMaker(char const* caption, char const* className, int x, int y, int cx, int cy, HINSTANCE hInstance)
{
_hwnd=CreateWindow(className,caption,WS_OVERLAPPEDWINDOW,x,y,cx,cy,0,0,hInstance,0);
}
LRESULT CALLBACK WindowProcedure(HWND hwnd, unsigned int message, WPARAM wParam, LPARAM lParam)
{
switch (message)
{
case WM_DESTROY:
PostQuitMessage (0);
return 0;
}
return DefWindowProc (hwnd, message, wParam, lParam );
}
int WINAPI WinMain (HINSTANCE hInst, HINSTANCE hPrevInst, char* cmdParam, int cmdShow)
{
char className [] = "Winnie";
int status;
MSG msg;
WinClass winClass(WindowProcedure, className, hInst);
winClass.Register();
WinMaker win("Hello Windows!", className, 100, 100, 450, 400, hInst);
win.Show (cmdShow);
while ((status = GetMessage (& msg, 0, 0, 0)) != 0)
{
if(status == -1)
return -1;
DispatchMessage(& msg);
}
return msg.wParam;
}
|