.cpp的:
#include "MSWindow.h"
#include <assert.h>
namespace kindow {
MSWindow::MSWindow(HINSTANCE instance,const std::string &name, int x, int y, int width, int height) {
hInstance_ = instance;
name_ = name;
x_ = x;
y_ = y;
width_ = width;
height_ = height;
hWnd_ = NULL;
}
MSWindow::~MSWindow() {
}
void MSWindow::RegisterClass() {
WNDCLASSEX wcex;
wcex.cbSize = sizeof(WNDCLASSEX);
wcex.style = CS_HREDRAW | CS_VREDRAW;
wcex.lpfnWndProc = (WNDPROC)WndProc;
wcex.cbClsExtra = 0;
wcex.cbWndExtra = 0;
wcex.hInstance = hInstance_;
wcex.hIcon = NULL;
wcex.hCursor = NULL;
wcex.hCursor = LoadCursor(NULL, IDC_ARROW);
wcex.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
wcex.lpszMenuName = NULL;
wcex.lpszClassName = name_.data();
wcex.hIconSm = NULL;
RegisterClassEx(&wcex);
}
BOOL MSWindow::CreateMSWindow() {
hWnd_ = CreateWindow(name_.data(), name_.data() , WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT, 0, CW_USEDEFAULT, 0, NULL, NULL, hInstance_, NULL);
if (!hWnd_) {
return FALSE;
}
MoveWindow(hWnd_,x_,y_,width_,height_,true);
ShowWindow(hWnd_, true);
UpdateWindow(hWnd_);
return TRUE;
}
// 多个窗口怎么处理
LRESULT CALLBACK MSWindow::WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) {
switch (message) {
case WM_DESTROY:
PostQuitMessage(0);
break;
default:
return DefWindowProc(hWnd, message, wParam, lParam);
}
return 0;
}
void MSWindow::Start() {
assert(hWnd_ == NULL);
RegisterClass();
// 如果这边创建失败,怎么通知“业务层”呢?
if (!CreateMSWindow()) {
return;
}
MSG msg;
while(true) {
if( PeekMessage( &msg, NULL, 0,0 ,PM_REMOVE)) {
if (msg.message == WM_QUIT) {
break;
}
TranslateMessage( &msg );
DispatchMessage( &msg );
}
else {
/*g_paint.m_nowOfPaint = GetTickCount();
if(g_paint.m_nowOfPaint - g_paint.m_passOfPaint >= 40)
{
g_hDC = GetDC(hWnd);
g_paint.Paint(g_snake, g_hDC);
ReleaseDC(hWnd, g_hDC);
} */
}
}
}
void MSWindow::Close() {
}
Timer *MSWindow::CreateTimer() {
return NULL;
}
void MSWindow::Draw(Drawable *drawable, int x, int y) {
}
void MSWindow::AddEventListener(EventListener *listener) {
}
void MSWindow::RemoveEventListener(EventListener *listenr) {
}
}