#include "windows.h"
#pragma comment(linker,"/WinMainCRTStartup")
class wRect
{
public:
wRect(int left, int top,int width, int height);
int Left() const;
int Top() const;
int Width() const;
int Height() const;
private:
int left, top, width, height;
};
wRect::wRect(int left, int top, int width, int height)
{
this->left = left;
this->top = top;
this->width = width;
this->height = height;
}
int wRect::Left() const
{
return left;
}
int wRect::Top() const
{
return top;
}
int wRect::Width() const
{
return width;
}
int wRect::Height() const
{
return height;
}
class BaseWindow
{
public:
BaseWindow(HINSTANCE hInst,LPSTR lpszTitle, wRect wndRect, WNDPROC wndProc);
HWND GetHwnd() const;
private:
HWND hWnd;
};
BaseWindow::BaseWindow(HINSTANCE hInst,LPSTR lpszTitle, wRect wndRect, WNDPROC wndProc)
{
LPSTR lpszwcName = TEXT("MyWindowClass");
WNDCLASS wndcls;
wndcls.hInstance = hInst;
wndcls.hbrBackground = CreateSolidBrush(RGB(200, 250, 200));
wndcls.hCursor = LoadCursor(hInst, IDC_ARROW);
wndcls.hIcon = LoadIcon(hInst, IDI_WINLOGO);
wndcls.lpszClassName = lpszwcName;
wndcls.lpszMenuName = NULL;
wndcls.lpfnWndProc = wndProc;
wndcls.style = CS_HREDRAW | CS_VREDRAW;
wndcls.cbClsExtra = 0;
wndcls.cbWndExtra = 0;
RegisterClass(&wndcls);
HWND hWnd = CreateWindow(lpszwcName, lpszTitle, WS_SYSMENU,
wndRect.Left(), wndRect.Top(), wndRect.Width(), wndRect.Height(),
NULL, NULL, hInst, NULL);
ShowWindow(hWnd, SW_SHOWNORMAL);
UpdateWindow(hWnd);
MSG msg;
while (GetMessage(&msg, NULL, NULL, NULL))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
}
HWND BaseWindow::GetHwnd() const
{
return hWnd;
}
class Example05Window : public BaseWindow
{
public:
Example05Window(HINSTANCE hInst, wRect wndRect, WNDPROC wndProc);
};
Example05Window::Example05Window(HINSTANCE hInst, wRect wndRect, WNDPROC wndProc)
:BaseWindow(hInst, TEXT("Example05"), wndRect, wndProc)
{
}
LONG CALLBACK MyWindowProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam);
INT APIENTRY WinMain(HINSTANCE hInst, HINSTANCE hPrevInst, LPSTR lpCmdLine, int nCmdShow)
{
wRect wndRect=wRect(200,100,800,500);
Example05Window window = Example05Window(hInst, wndRect, MyWindowProc);
return 0;
}
LONG CALLBACK MyWindowProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
switch (msg)
{
case WM_KEYUP:
MessageBox(hWnd, "You pressed a key", "Information", MB_OK);
break;
case WM_DESTROY:
PostQuitMessage(0);
break;
default:
return DefWindowProc(hWnd, msg, wParam, lParam);
}
}