[20140101_Example05(Supplication)]基本的Windows应用程序、类的继承

#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);
	}
}



  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值