| 
									
										
										
										
											2018-04-21 21:24:46 +08:00
										 |  |  |  | #include "..\e2dbase.h"
 | 
					
						
							|  |  |  |  | #include "..\e2dmanager.h"
 | 
					
						
							| 
									
										
										
										
											2018-08-13 23:47:10 +08:00
										 |  |  |  | #include "..\e2dnode.h"
 | 
					
						
							| 
									
										
										
										
											2018-01-30 16:45:38 +08:00
										 |  |  |  | #include <imm.h>
 | 
					
						
							|  |  |  |  | #pragma comment (lib ,"imm32.lib")
 | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-08-02 00:27:45 +08:00
										 |  |  |  | #define WINDOW_STYLE	WS_OVERLAPPEDWINDOW & ~WS_MAXIMIZEBOX & ~WS_THICKFRAME
 | 
					
						
							|  |  |  |  | #define REGISTER_CLASS	L"Easy2DApp"
 | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-01-30 16:45:38 +08:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-08-15 00:06:03 +08:00
										 |  |  |  | e2d::Window::Window(const String & title, int width, int height, int iconID) | 
					
						
							| 
									
										
										
										
											2018-07-03 18:16:26 +08:00
										 |  |  |  | 	: _hWnd(nullptr) | 
					
						
							| 
									
										
										
										
											2018-08-15 00:06:03 +08:00
										 |  |  |  | 	, _width(width) | 
					
						
							|  |  |  |  | 	, _height(height) | 
					
						
							|  |  |  |  | 	, _title(title) | 
					
						
							|  |  |  |  | 	, _iconID(iconID) | 
					
						
							| 
									
										
										
										
											2018-07-28 22:22:58 +08:00
										 |  |  |  | 	, _dpi(0.f) | 
					
						
							| 
									
										
										
										
											2018-07-03 18:16:26 +08:00
										 |  |  |  | { | 
					
						
							| 
									
										
										
										
											2018-08-15 00:06:03 +08:00
										 |  |  |  | 	CoInitialize(nullptr); | 
					
						
							| 
									
										
										
										
											2018-07-03 18:16:26 +08:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-08-19 15:11:20 +08:00
										 |  |  |  | 	// <20><>ȡϵͳ DPI
 | 
					
						
							|  |  |  |  | 	_dpi = static_cast<float>(::GetDpiForSystem()); | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-03-01 00:19:09 +08:00
										 |  |  |  | 	WNDCLASSEX wcex = { 0 }; | 
					
						
							| 
									
										
										
										
											2018-08-15 00:06:03 +08:00
										 |  |  |  | 	wcex.cbSize = sizeof(WNDCLASSEX); | 
					
						
							|  |  |  |  | 	wcex.lpszClassName = REGISTER_CLASS; | 
					
						
							|  |  |  |  | 	wcex.style = CS_HREDRAW | CS_VREDRAW | CS_DBLCLKS; | 
					
						
							|  |  |  |  | 	wcex.lpfnWndProc = Window::WndProc; | 
					
						
							|  |  |  |  | 	wcex.hIcon = nullptr; | 
					
						
							|  |  |  |  | 	wcex.cbClsExtra = 0; | 
					
						
							|  |  |  |  | 	wcex.cbWndExtra = sizeof(LONG_PTR); | 
					
						
							|  |  |  |  | 	wcex.hInstance = HINST_THISCOMPONENT; | 
					
						
							|  |  |  |  | 	wcex.hbrBackground = nullptr; | 
					
						
							|  |  |  |  | 	wcex.lpszMenuName = nullptr; | 
					
						
							|  |  |  |  | 	wcex.hCursor = ::LoadCursor(nullptr, IDC_ARROW); | 
					
						
							| 
									
										
										
										
											2018-08-02 00:27:45 +08:00
										 |  |  |  | 
 | 
					
						
							|  |  |  |  | 	if (_iconID != 0) | 
					
						
							| 
									
										
										
										
											2018-07-03 23:39:00 +08:00
										 |  |  |  | 	{ | 
					
						
							|  |  |  |  | 		wcex.hIcon = (HICON)::LoadImage( | 
					
						
							|  |  |  |  | 			HINST_THISCOMPONENT, | 
					
						
							| 
									
										
										
										
											2018-08-02 00:27:45 +08:00
										 |  |  |  | 			MAKEINTRESOURCE(_iconID), | 
					
						
							| 
									
										
										
										
											2018-07-03 23:39:00 +08:00
										 |  |  |  | 			IMAGE_ICON, | 
					
						
							|  |  |  |  | 			0, | 
					
						
							|  |  |  |  | 			0, | 
					
						
							|  |  |  |  | 			LR_DEFAULTCOLOR | LR_CREATEDIBSECTION | LR_DEFAULTSIZE | 
					
						
							|  |  |  |  | 		); | 
					
						
							|  |  |  |  | 	} | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-08-02 00:27:45 +08:00
										 |  |  |  | 	// ע<>ᴰ<EFBFBD><E1B4B0><EFBFBD><EFBFBD>
 | 
					
						
							| 
									
										
										
										
											2018-01-30 16:45:38 +08:00
										 |  |  |  | 	RegisterClassEx(&wcex); | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-04-13 00:39:27 +08:00
										 |  |  |  | 	// <20><><EFBFBD>㴰<EFBFBD>ڴ<EFBFBD>С
 | 
					
						
							| 
									
										
										
										
											2018-08-19 15:11:20 +08:00
										 |  |  |  | 	Rect clientRect = _locate(_width, _height); | 
					
						
							| 
									
										
										
										
											2018-04-13 00:39:27 +08:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-01-30 16:45:38 +08:00
										 |  |  |  | 	// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
 | 
					
						
							| 
									
										
										
										
											2018-08-15 23:30:23 +08:00
										 |  |  |  | 	_hWnd = ::CreateWindowEx( | 
					
						
							| 
									
										
										
										
											2018-04-13 00:39:27 +08:00
										 |  |  |  | 		NULL, | 
					
						
							| 
									
										
										
										
											2018-08-02 00:27:45 +08:00
										 |  |  |  | 		REGISTER_CLASS, | 
					
						
							| 
									
										
										
										
											2018-07-17 18:07:17 +08:00
										 |  |  |  | 		(LPCTSTR)_title, | 
					
						
							| 
									
										
										
										
											2018-08-02 00:27:45 +08:00
										 |  |  |  | 		WINDOW_STYLE, | 
					
						
							| 
									
										
										
										
											2018-08-15 00:06:03 +08:00
										 |  |  |  | 		int(clientRect.origin.x), | 
					
						
							|  |  |  |  | 		int(clientRect.origin.y), | 
					
						
							|  |  |  |  | 		int(clientRect.size.width), | 
					
						
							|  |  |  |  | 		int(clientRect.size.height), | 
					
						
							| 
									
										
										
										
											2018-05-17 15:22:14 +08:00
										 |  |  |  | 		nullptr, | 
					
						
							|  |  |  |  | 		nullptr, | 
					
						
							| 
									
										
										
										
											2018-01-30 16:45:38 +08:00
										 |  |  |  | 		HINST_THISCOMPONENT, | 
					
						
							| 
									
										
										
										
											2018-08-15 00:06:03 +08:00
										 |  |  |  | 		this | 
					
						
							| 
									
										
										
										
											2018-01-30 16:45:38 +08:00
										 |  |  |  | 	); | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-08-15 23:30:23 +08:00
										 |  |  |  | 	if (_hWnd) | 
					
						
							| 
									
										
										
										
											2018-01-30 16:45:38 +08:00
										 |  |  |  | 	{ | 
					
						
							|  |  |  |  | 		// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>뷨
 | 
					
						
							| 
									
										
										
										
											2018-08-02 00:27:45 +08:00
										 |  |  |  | 		setTypewritingEnabled(false); | 
					
						
							| 
									
										
										
										
											2018-05-03 22:21:01 +08:00
										 |  |  |  | 		// <20><><EFBFBD>ÿ<EFBFBD><C3BF><EFBFBD>̨<EFBFBD>رհ<D8B1>ť
 | 
					
						
							|  |  |  |  | 		HWND consoleHWnd = ::GetConsoleWindow(); | 
					
						
							|  |  |  |  | 		if (consoleHWnd) | 
					
						
							| 
									
										
										
										
											2018-01-30 16:45:38 +08:00
										 |  |  |  | 		{ | 
					
						
							| 
									
										
										
										
											2018-05-03 22:21:01 +08:00
										 |  |  |  | 			HMENU hmenu = ::GetSystemMenu(consoleHWnd, FALSE); | 
					
						
							| 
									
										
										
										
											2018-01-30 16:45:38 +08:00
										 |  |  |  | 			::RemoveMenu(hmenu, SC_CLOSE, MF_BYCOMMAND); | 
					
						
							|  |  |  |  | 		} | 
					
						
							|  |  |  |  | 	} | 
					
						
							|  |  |  |  | 	else | 
					
						
							|  |  |  |  | 	{ | 
					
						
							| 
									
										
										
										
											2018-08-02 00:27:45 +08:00
										 |  |  |  | 		::UnregisterClass(REGISTER_CLASS, HINST_THISCOMPONENT); | 
					
						
							| 
									
										
										
										
											2018-08-15 00:06:03 +08:00
										 |  |  |  | 		throw SystemException("Create window failed"); | 
					
						
							|  |  |  |  | 	} | 
					
						
							|  |  |  |  | } | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | e2d::Window::~Window() | 
					
						
							|  |  |  |  | { | 
					
						
							|  |  |  |  | 	// <20>رտ<D8B1><D5BF><EFBFBD>̨
 | 
					
						
							|  |  |  |  | 	if (::GetConsoleWindow()) | 
					
						
							|  |  |  |  | 		::FreeConsole(); | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | 	// <20>رմ<D8B1><D5B4><EFBFBD>
 | 
					
						
							|  |  |  |  | 	if (_hWnd) | 
					
						
							|  |  |  |  | 		::DestroyWindow(_hWnd); | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | 	CoUninitialize(); | 
					
						
							|  |  |  |  | } | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | bool e2d::Window::createMutex(const String & mutex) | 
					
						
							|  |  |  |  | { | 
					
						
							|  |  |  |  | 	if (mutex.isEmpty()) | 
					
						
							|  |  |  |  | 		return false; | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | 	HANDLE hMutex = ::CreateMutex(nullptr, TRUE, LPCWSTR(L"Easy2DApp-" + mutex)); | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | 	if (hMutex == nullptr) | 
					
						
							|  |  |  |  | 	{ | 
					
						
							|  |  |  |  | 		WARN("CreateMutex Failed!"); | 
					
						
							|  |  |  |  | 		return false; | 
					
						
							| 
									
										
										
										
											2018-04-13 00:39:27 +08:00
										 |  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2018-08-15 00:06:03 +08:00
										 |  |  |  | 	else if (::GetLastError() == ERROR_ALREADY_EXISTS) | 
					
						
							|  |  |  |  | 	{ | 
					
						
							|  |  |  |  | 		// <20>رս<D8B1><D5BD>̻<EFBFBD><CCBB><EFBFBD><EFBFBD><EFBFBD>
 | 
					
						
							|  |  |  |  | 		::CloseHandle(hMutex); | 
					
						
							|  |  |  |  | 		// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϸ<EFBFBD><CFB7><EFBFBD><EFBFBD>
 | 
					
						
							|  |  |  |  | 		if (!this->_title.isEmpty()) | 
					
						
							|  |  |  |  | 		{ | 
					
						
							|  |  |  |  | 			// <20><>ȡ<EFBFBD><C8A1><EFBFBD>ھ<EFBFBD><DABE><EFBFBD>
 | 
					
						
							|  |  |  |  | 			HWND hProgramWnd = ::FindWindow(REGISTER_CLASS, (LPCTSTR)_title); | 
					
						
							|  |  |  |  | 			if (hProgramWnd) | 
					
						
							|  |  |  |  | 			{ | 
					
						
							|  |  |  |  | 				// <20><>ȡ<EFBFBD><C8A1><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʾ״̬
 | 
					
						
							|  |  |  |  | 				WINDOWPLACEMENT wpm; | 
					
						
							|  |  |  |  | 				::GetWindowPlacement(hProgramWnd, &wpm); | 
					
						
							|  |  |  |  | 				// <20><><EFBFBD><EFBFBD><EFBFBD>еij<D0B5><C4B3>ڻ<F2B4B0BF>ԭ<EFBFBD><D4AD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>״̬
 | 
					
						
							|  |  |  |  | 				wpm.showCmd = SW_SHOW; | 
					
						
							|  |  |  |  | 				::SetWindowPlacement(hProgramWnd, &wpm); | 
					
						
							|  |  |  |  | 				::SetWindowPos(hProgramWnd, HWND_TOP, 0, 0, 0, 0, SWP_NOSIZE | SWP_NOMOVE); | 
					
						
							|  |  |  |  | 			} | 
					
						
							|  |  |  |  | 		} | 
					
						
							|  |  |  |  | 		return false; | 
					
						
							|  |  |  |  | 	} | 
					
						
							|  |  |  |  | 	return true; | 
					
						
							| 
									
										
										
										
											2018-01-30 16:45:38 +08:00
										 |  |  |  | } | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-08-19 15:11:20 +08:00
										 |  |  |  | e2d::Rect e2d::Window::_locate(int width, int height) | 
					
						
							| 
									
										
										
										
											2018-08-02 00:27:45 +08:00
										 |  |  |  | { | 
					
						
							|  |  |  |  | 	Rect result; | 
					
						
							| 
									
										
										
										
											2018-08-19 15:11:20 +08:00
										 |  |  |  | 	RECT wRECT		= { 0, 0, LONG(ceil(width * _dpi / 96.f)), LONG(ceil(height * _dpi / 96.f)) }; | 
					
						
							| 
									
										
										
										
											2018-08-02 00:27:45 +08:00
										 |  |  |  | 	int maxWidth	= ::GetSystemMetrics(SM_CXSCREEN); | 
					
						
							|  |  |  |  | 	int maxHeight	= ::GetSystemMetrics(SM_CYSCREEN); | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | 	// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʵĴ<CAB5><C4B4>ڴ<EFBFBD>С
 | 
					
						
							|  |  |  |  | 	::AdjustWindowRectEx(&wRECT, WINDOW_STYLE, FALSE, NULL); | 
					
						
							|  |  |  |  | 	width = static_cast<int>(wRECT.right - wRECT.left); | 
					
						
							|  |  |  |  | 	height = static_cast<int>(wRECT.bottom - wRECT.top); | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | 	// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ĵ<EFBFBD><C4B4>ڴ<EFBFBD>С<EFBFBD>ȷֱ<C8B7><D6B1>ʴ<EFBFBD>ʱ<EFBFBD><CAB1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
 | 
					
						
							|  |  |  |  | 	WARN_IF(maxWidth < width || maxHeight < height, "The window is larger than screen!"); | 
					
						
							|  |  |  |  | 	width = std::min(width, maxWidth); | 
					
						
							|  |  |  |  | 	height = std::min(height, maxHeight); | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | 	float x = float((maxWidth - width) / 2), y = float((maxHeight - height) / 2); | 
					
						
							|  |  |  |  | 	return std::move(Rect(x, y, float(width), float(height))); | 
					
						
							|  |  |  |  | } | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-07-05 22:05:23 +08:00
										 |  |  |  | void e2d::Window::poll() | 
					
						
							| 
									
										
										
										
											2018-01-30 16:45:38 +08:00
										 |  |  |  | { | 
					
						
							| 
									
										
										
										
											2018-07-05 22:05:23 +08:00
										 |  |  |  | 	while (::PeekMessage(&_msg, nullptr, 0, 0, PM_REMOVE)) | 
					
						
							| 
									
										
										
										
											2018-01-30 16:45:38 +08:00
										 |  |  |  | 	{ | 
					
						
							| 
									
										
										
										
											2018-07-05 22:05:23 +08:00
										 |  |  |  | 		::TranslateMessage(&_msg); | 
					
						
							|  |  |  |  | 		::DispatchMessage(&_msg); | 
					
						
							| 
									
										
										
										
											2018-01-30 16:45:38 +08:00
										 |  |  |  | 	} | 
					
						
							|  |  |  |  | } | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-08-15 00:06:03 +08:00
										 |  |  |  | int e2d::Window::getWidth() const | 
					
						
							| 
									
										
										
										
											2018-01-30 16:45:38 +08:00
										 |  |  |  | { | 
					
						
							| 
									
										
										
										
											2018-08-15 00:06:03 +08:00
										 |  |  |  | 	return _width; | 
					
						
							| 
									
										
										
										
											2018-01-30 16:45:38 +08:00
										 |  |  |  | } | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-08-15 00:06:03 +08:00
										 |  |  |  | int e2d::Window::getHeight() const | 
					
						
							| 
									
										
										
										
											2018-01-30 16:45:38 +08:00
										 |  |  |  | { | 
					
						
							| 
									
										
										
										
											2018-08-15 00:06:03 +08:00
										 |  |  |  | 	return _height; | 
					
						
							| 
									
										
										
										
											2018-01-30 16:45:38 +08:00
										 |  |  |  | } | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-08-15 00:06:03 +08:00
										 |  |  |  | e2d::Size e2d::Window::getSize() const | 
					
						
							| 
									
										
										
										
											2018-01-30 16:45:38 +08:00
										 |  |  |  | { | 
					
						
							| 
									
										
										
										
											2018-08-15 00:06:03 +08:00
										 |  |  |  | 	return Size(float(_width), float(_height)); | 
					
						
							| 
									
										
										
										
											2018-07-03 18:16:26 +08:00
										 |  |  |  | } | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-08-15 00:06:03 +08:00
										 |  |  |  | float e2d::Window::getDpi() const | 
					
						
							| 
									
										
										
										
											2018-07-28 22:22:58 +08:00
										 |  |  |  | { | 
					
						
							|  |  |  |  | 	return _dpi; | 
					
						
							|  |  |  |  | } | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-08-15 00:06:03 +08:00
										 |  |  |  | e2d::String e2d::Window::getTitle() const | 
					
						
							| 
									
										
										
										
											2018-07-03 18:16:26 +08:00
										 |  |  |  | { | 
					
						
							|  |  |  |  | 	return _title; | 
					
						
							| 
									
										
										
										
											2018-01-30 16:45:38 +08:00
										 |  |  |  | } | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-08-15 00:06:03 +08:00
										 |  |  |  | HWND e2d::Window::getHWnd() const | 
					
						
							| 
									
										
										
										
											2018-01-30 16:45:38 +08:00
										 |  |  |  | { | 
					
						
							| 
									
										
										
										
											2018-07-03 18:16:26 +08:00
										 |  |  |  | 	return _hWnd; | 
					
						
							| 
									
										
										
										
											2018-01-30 16:45:38 +08:00
										 |  |  |  | } | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-05-05 22:58:35 +08:00
										 |  |  |  | void e2d::Window::setSize(int width, int height) | 
					
						
							| 
									
										
										
										
											2018-01-30 16:45:38 +08:00
										 |  |  |  | { | 
					
						
							| 
									
										
										
										
											2018-08-15 00:06:03 +08:00
										 |  |  |  | 	if (_width == width && _height == height) | 
					
						
							|  |  |  |  | 		return; | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | 	_width = width; | 
					
						
							|  |  |  |  | 	_height = height; | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-07-03 23:39:00 +08:00
										 |  |  |  | 	if (_hWnd) | 
					
						
							|  |  |  |  | 	{ | 
					
						
							| 
									
										
										
										
											2018-08-19 15:11:20 +08:00
										 |  |  |  | 		Rect wRect = _locate(width, height); | 
					
						
							| 
									
										
										
										
											2018-08-02 00:27:45 +08:00
										 |  |  |  | 		::MoveWindow( | 
					
						
							|  |  |  |  | 			_hWnd, | 
					
						
							|  |  |  |  | 			int(wRect.origin.x), | 
					
						
							|  |  |  |  | 			int(wRect.origin.y), | 
					
						
							|  |  |  |  | 			int(wRect.size.width), | 
					
						
							|  |  |  |  | 			int(wRect.size.height), | 
					
						
							|  |  |  |  | 			TRUE | 
					
						
							|  |  |  |  | 		); | 
					
						
							| 
									
										
										
										
											2018-07-03 23:39:00 +08:00
										 |  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2018-01-30 16:45:38 +08:00
										 |  |  |  | } | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-05-07 15:48:06 +08:00
										 |  |  |  | void e2d::Window::setTitle(const String& title) | 
					
						
							| 
									
										
										
										
											2018-01-30 16:45:38 +08:00
										 |  |  |  | { | 
					
						
							| 
									
										
										
										
											2018-08-02 00:27:45 +08:00
										 |  |  |  | 	_title = title; | 
					
						
							| 
									
										
										
										
											2018-07-03 23:39:00 +08:00
										 |  |  |  | 	if (_hWnd) | 
					
						
							|  |  |  |  | 	{ | 
					
						
							|  |  |  |  | 		::SetWindowText(_hWnd, (LPCWSTR)title); | 
					
						
							|  |  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2018-01-30 16:45:38 +08:00
										 |  |  |  | } | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-05-07 15:48:06 +08:00
										 |  |  |  | void e2d::Window::setIcon(int iconID) | 
					
						
							| 
									
										
										
										
											2018-04-13 00:39:27 +08:00
										 |  |  |  | { | 
					
						
							| 
									
										
										
										
											2018-07-03 23:39:00 +08:00
										 |  |  |  | 	this->_iconID = iconID; | 
					
						
							|  |  |  |  | 	if (_hWnd) | 
					
						
							|  |  |  |  | 	{ | 
					
						
							|  |  |  |  | 		HICON hIcon = (HICON)::LoadImage(HINST_THISCOMPONENT, MAKEINTRESOURCE(iconID), IMAGE_ICON, 0, 0, LR_DEFAULTCOLOR | LR_CREATEDIBSECTION | LR_DEFAULTSIZE); | 
					
						
							|  |  |  |  | 		// <20><><EFBFBD>ô<EFBFBD><C3B4>ڵ<EFBFBD>ͼ<EFBFBD><CDBC>
 | 
					
						
							|  |  |  |  | 		::SendMessage(_hWnd, WM_SETICON, ICON_BIG, (LPARAM)hIcon); | 
					
						
							|  |  |  |  | 		::SendMessage(_hWnd, WM_SETICON, ICON_SMALL, (LPARAM)hIcon); | 
					
						
							|  |  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2018-04-13 00:39:27 +08:00
										 |  |  |  | } | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-05-07 17:03:59 +08:00
										 |  |  |  | void e2d::Window::setCursor(Cursor cursor) | 
					
						
							|  |  |  |  | { | 
					
						
							| 
									
										
										
										
											2018-05-17 15:22:14 +08:00
										 |  |  |  | 	LPCWSTR pCursorName = nullptr; | 
					
						
							| 
									
										
										
										
											2018-05-07 17:03:59 +08:00
										 |  |  |  | 	switch (cursor) | 
					
						
							|  |  |  |  | 	{ | 
					
						
							| 
									
										
										
										
											2018-05-24 20:37:34 +08:00
										 |  |  |  | 	case Cursor::Normal: | 
					
						
							| 
									
										
										
										
											2018-05-07 17:03:59 +08:00
										 |  |  |  | 		pCursorName = IDC_ARROW; | 
					
						
							|  |  |  |  | 		break; | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-05-24 20:37:34 +08:00
										 |  |  |  | 	case Cursor::Hand: | 
					
						
							| 
									
										
										
										
											2018-05-07 17:03:59 +08:00
										 |  |  |  | 		pCursorName = IDC_HAND; | 
					
						
							|  |  |  |  | 		break; | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-05-24 20:37:34 +08:00
										 |  |  |  | 	case Cursor::No: | 
					
						
							| 
									
										
										
										
											2018-05-07 17:03:59 +08:00
										 |  |  |  | 		pCursorName = IDC_NO; | 
					
						
							|  |  |  |  | 		break; | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-05-24 20:37:34 +08:00
										 |  |  |  | 	case Cursor::Wait: | 
					
						
							| 
									
										
										
										
											2018-05-07 17:03:59 +08:00
										 |  |  |  | 		pCursorName = IDC_WAIT; | 
					
						
							|  |  |  |  | 		break; | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-05-24 20:37:34 +08:00
										 |  |  |  | 	case Cursor::ArrowWait: | 
					
						
							| 
									
										
										
										
											2018-05-07 17:03:59 +08:00
										 |  |  |  | 		pCursorName = IDC_APPSTARTING; | 
					
						
							|  |  |  |  | 		break; | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | 	default: | 
					
						
							|  |  |  |  | 		break; | 
					
						
							|  |  |  |  | 	} | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-05-17 15:22:14 +08:00
										 |  |  |  | 	HCURSOR hCursor = ::LoadCursor(nullptr, pCursorName); | 
					
						
							| 
									
										
										
										
											2018-05-07 17:03:59 +08:00
										 |  |  |  | 	::SetCursor(hCursor); | 
					
						
							|  |  |  |  | } | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-07-13 01:33:53 +08:00
										 |  |  |  | void e2d::Window::setConsoleEnabled(bool enabled) | 
					
						
							| 
									
										
										
										
											2018-01-30 16:45:38 +08:00
										 |  |  |  | { | 
					
						
							|  |  |  |  | 	// <20><><EFBFBD><EFBFBD><EFBFBD>Ѵ<EFBFBD><D1B4>ڵĿ<DAB5><C4BF><EFBFBD>̨<EFBFBD><CCA8><EFBFBD><EFBFBD>
 | 
					
						
							|  |  |  |  | 	HWND hwnd = ::GetConsoleWindow(); | 
					
						
							|  |  |  |  | 	// <20>رտ<D8B1><D5BF><EFBFBD>̨
 | 
					
						
							| 
									
										
										
										
											2018-07-13 01:33:53 +08:00
										 |  |  |  | 	if (enabled) | 
					
						
							| 
									
										
										
										
											2018-01-30 16:45:38 +08:00
										 |  |  |  | 	{ | 
					
						
							|  |  |  |  | 		if (hwnd) | 
					
						
							|  |  |  |  | 		{ | 
					
						
							|  |  |  |  | 			::ShowWindow(hwnd, SW_SHOWNORMAL); | 
					
						
							|  |  |  |  | 		} | 
					
						
							|  |  |  |  | 		else | 
					
						
							|  |  |  |  | 		{ | 
					
						
							|  |  |  |  | 			// <20><>ʾһ<CABE><D2BB><EFBFBD>¿<EFBFBD><C2BF><EFBFBD>̨
 | 
					
						
							|  |  |  |  | 			if (::AllocConsole()) | 
					
						
							|  |  |  |  | 			{ | 
					
						
							|  |  |  |  | 				hwnd = ::GetConsoleWindow(); | 
					
						
							|  |  |  |  | 				// <20>ض<EFBFBD><D8B6><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
 | 
					
						
							|  |  |  |  | 				FILE * stdoutStream, * stdinStream, * stderrStream; | 
					
						
							| 
									
										
										
										
											2018-08-19 15:11:20 +08:00
										 |  |  |  | 				freopen_s(&stdoutStream, "conout$", "w+t", stdout); | 
					
						
							|  |  |  |  | 				freopen_s(&stdinStream, "conin$", "r+t", stdin); | 
					
						
							|  |  |  |  | 				freopen_s(&stderrStream, "conout$", "w+t", stderr); | 
					
						
							| 
									
										
										
										
											2018-01-30 16:45:38 +08:00
										 |  |  |  | 				// <20><><EFBFBD>ÿ<EFBFBD><C3BF><EFBFBD>̨<EFBFBD>رհ<D8B1>ť
 | 
					
						
							|  |  |  |  | 				HMENU hmenu = ::GetSystemMenu(hwnd, FALSE); | 
					
						
							|  |  |  |  | 				::RemoveMenu(hmenu, SC_CLOSE, MF_BYCOMMAND); | 
					
						
							|  |  |  |  | 			} | 
					
						
							|  |  |  |  | 		} | 
					
						
							|  |  |  |  | 	} | 
					
						
							|  |  |  |  | 	else  | 
					
						
							|  |  |  |  | 	{ | 
					
						
							|  |  |  |  | 		if (hwnd) | 
					
						
							|  |  |  |  | 		{ | 
					
						
							|  |  |  |  | 			::ShowWindow(hwnd, SW_HIDE); | 
					
						
							|  |  |  |  | 		} | 
					
						
							|  |  |  |  | 	} | 
					
						
							|  |  |  |  | } | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-07-04 17:00:21 +08:00
										 |  |  |  | void e2d::Window::setTypewritingEnabled(bool enabled) | 
					
						
							| 
									
										
										
										
											2018-01-30 16:45:38 +08:00
										 |  |  |  | { | 
					
						
							|  |  |  |  | 	static HIMC hImc = nullptr; | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-07-04 17:00:21 +08:00
										 |  |  |  | 	if (enabled) | 
					
						
							| 
									
										
										
										
											2018-01-30 16:45:38 +08:00
										 |  |  |  | 	{ | 
					
						
							|  |  |  |  | 		if (hImc != nullptr) | 
					
						
							|  |  |  |  | 		{ | 
					
						
							| 
									
										
										
										
											2018-07-03 18:16:26 +08:00
										 |  |  |  | 			::ImmAssociateContext(_hWnd, hImc); | 
					
						
							| 
									
										
										
										
											2018-01-30 16:45:38 +08:00
										 |  |  |  | 			hImc = nullptr; | 
					
						
							|  |  |  |  | 		} | 
					
						
							|  |  |  |  | 	} | 
					
						
							|  |  |  |  | 	else | 
					
						
							|  |  |  |  | 	{ | 
					
						
							|  |  |  |  | 		if (hImc == nullptr) | 
					
						
							|  |  |  |  | 		{ | 
					
						
							| 
									
										
										
										
											2018-07-03 18:16:26 +08:00
										 |  |  |  | 			hImc = ::ImmAssociateContext(_hWnd, nullptr); | 
					
						
							| 
									
										
										
										
											2018-01-30 16:45:38 +08:00
										 |  |  |  | 		} | 
					
						
							|  |  |  |  | 	} | 
					
						
							|  |  |  |  | } | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-07-17 10:34:16 +08:00
										 |  |  |  | bool e2d::Window::popup(const String & text, const String & title, Popup style, bool hasCancel) | 
					
						
							| 
									
										
										
										
											2018-05-10 18:18:02 +08:00
										 |  |  |  | { | 
					
						
							| 
									
										
										
										
											2018-07-17 00:35:27 +08:00
										 |  |  |  | 	UINT type = 0; | 
					
						
							|  |  |  |  | 	switch (style) | 
					
						
							|  |  |  |  | 	{ | 
					
						
							| 
									
										
										
										
											2018-07-17 10:34:16 +08:00
										 |  |  |  | 	case e2d::Window::Popup::Information: | 
					
						
							| 
									
										
										
										
											2018-07-17 00:35:27 +08:00
										 |  |  |  | 		type = MB_ICONINFORMATION; | 
					
						
							|  |  |  |  | 		break; | 
					
						
							| 
									
										
										
										
											2018-07-17 10:34:16 +08:00
										 |  |  |  | 	case e2d::Window::Popup::Warning: | 
					
						
							| 
									
										
										
										
											2018-07-17 00:35:27 +08:00
										 |  |  |  | 		type = MB_ICONWARNING; | 
					
						
							|  |  |  |  | 		break; | 
					
						
							| 
									
										
										
										
											2018-07-17 10:34:16 +08:00
										 |  |  |  | 	case e2d::Window::Popup::Error: | 
					
						
							| 
									
										
										
										
											2018-07-17 00:35:27 +08:00
										 |  |  |  | 		type = MB_ICONERROR; | 
					
						
							|  |  |  |  | 		break; | 
					
						
							|  |  |  |  | 	default: | 
					
						
							|  |  |  |  | 		break; | 
					
						
							|  |  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2018-05-10 18:18:02 +08:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-07-17 00:35:27 +08:00
										 |  |  |  | 	if (hasCancel) | 
					
						
							|  |  |  |  | 	{ | 
					
						
							|  |  |  |  | 		type |= MB_OKCANCEL; | 
					
						
							|  |  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2018-05-10 18:18:02 +08:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-07-05 16:44:47 +08:00
										 |  |  |  | 	Game::getInstance()->pause(); | 
					
						
							| 
									
										
										
										
											2018-07-17 00:35:27 +08:00
										 |  |  |  | 	int ret = ::MessageBox(_hWnd, (LPCWSTR)text, (LPCWSTR)title, type); | 
					
						
							| 
									
										
										
										
											2018-07-05 16:44:47 +08:00
										 |  |  |  | 	Game::getInstance()->resume(); | 
					
						
							| 
									
										
										
										
											2018-07-17 00:35:27 +08:00
										 |  |  |  | 	return ret == IDOK; | 
					
						
							| 
									
										
										
										
											2018-05-10 18:18:02 +08:00
										 |  |  |  | } | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-01-30 16:45:38 +08:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-08-15 00:06:03 +08:00
										 |  |  |  | LRESULT e2d::Window::WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) | 
					
						
							| 
									
										
										
										
											2018-01-30 16:45:38 +08:00
										 |  |  |  | { | 
					
						
							|  |  |  |  | 	LRESULT result = 0; | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-08-15 00:06:03 +08:00
										 |  |  |  | 	if (uMsg == WM_CREATE) | 
					
						
							| 
									
										
										
										
											2018-01-30 16:45:38 +08:00
										 |  |  |  | 	{ | 
					
						
							| 
									
										
										
										
											2018-08-15 00:06:03 +08:00
										 |  |  |  | 		LPCREATESTRUCT pcs = (LPCREATESTRUCT)lParam; | 
					
						
							|  |  |  |  | 		Window *window = (Window *)pcs->lpCreateParams; | 
					
						
							| 
									
										
										
										
											2018-05-03 22:21:01 +08:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-08-15 00:06:03 +08:00
										 |  |  |  | 		::SetWindowLongPtrW( | 
					
						
							|  |  |  |  | 			hWnd, | 
					
						
							|  |  |  |  | 			GWLP_USERDATA, | 
					
						
							|  |  |  |  | 			PtrToUlong(window) | 
					
						
							|  |  |  |  | 		); | 
					
						
							| 
									
										
										
										
											2018-07-16 22:11:27 +08:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-08-15 00:06:03 +08:00
										 |  |  |  | 		result = 1; | 
					
						
							| 
									
										
										
										
											2018-07-16 22:11:27 +08:00
										 |  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2018-08-15 00:06:03 +08:00
										 |  |  |  | 	else | 
					
						
							| 
									
										
										
										
											2018-01-30 16:45:38 +08:00
										 |  |  |  | 	{ | 
					
						
							| 
									
										
										
										
											2018-08-15 00:06:03 +08:00
										 |  |  |  | 		bool hasHandled = false; | 
					
						
							|  |  |  |  | 		Window *window = reinterpret_cast<Window *>( | 
					
						
							|  |  |  |  | 			static_cast<LONG_PTR>( | 
					
						
							|  |  |  |  | 				::GetWindowLongPtrW(hWnd, GWLP_USERDATA) | 
					
						
							|  |  |  |  | 			) | 
					
						
							|  |  |  |  | 		); | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | 		switch (uMsg) | 
					
						
							|  |  |  |  | 		{ | 
					
						
							| 
									
										
										
										
											2018-07-04 00:27:14 +08:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-08-15 00:06:03 +08:00
										 |  |  |  | 		// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϣ
 | 
					
						
							|  |  |  |  | 		case WM_LBUTTONUP: | 
					
						
							|  |  |  |  | 		case WM_LBUTTONDOWN: | 
					
						
							|  |  |  |  | 		case WM_LBUTTONDBLCLK: | 
					
						
							|  |  |  |  | 		case WM_MBUTTONUP: | 
					
						
							|  |  |  |  | 		case WM_MBUTTONDOWN: | 
					
						
							|  |  |  |  | 		case WM_MBUTTONDBLCLK: | 
					
						
							|  |  |  |  | 		case WM_RBUTTONUP: | 
					
						
							|  |  |  |  | 		case WM_RBUTTONDOWN: | 
					
						
							|  |  |  |  | 		case WM_RBUTTONDBLCLK: | 
					
						
							|  |  |  |  | 		case WM_MOUSEMOVE: | 
					
						
							|  |  |  |  | 		case WM_MOUSEWHEEL: | 
					
						
							| 
									
										
										
										
											2018-07-04 00:27:14 +08:00
										 |  |  |  | 		{ | 
					
						
							| 
									
										
										
										
											2018-08-15 23:30:23 +08:00
										 |  |  |  | 			auto game = Game::getInstance(); | 
					
						
							|  |  |  |  | 			if (game->isTransitioning()) | 
					
						
							|  |  |  |  | 				break; | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | 			if (game->getCurrentScene()) | 
					
						
							|  |  |  |  | 			{ | 
					
						
							|  |  |  |  | 				game->getCurrentScene()->dispatch(MouseEvent(hWnd, uMsg, wParam, lParam, window->_dpi), false); | 
					
						
							|  |  |  |  | 			} | 
					
						
							| 
									
										
										
										
											2018-07-04 00:27:14 +08:00
										 |  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2018-08-15 00:06:03 +08:00
										 |  |  |  | 		result = 0; | 
					
						
							|  |  |  |  | 		hasHandled = true; | 
					
						
							|  |  |  |  | 		break; | 
					
						
							| 
									
										
										
										
											2018-07-03 18:16:26 +08:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-08-15 00:06:03 +08:00
										 |  |  |  | 		// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϣ
 | 
					
						
							|  |  |  |  | 		case WM_KEYDOWN: | 
					
						
							|  |  |  |  | 		case WM_KEYUP: | 
					
						
							| 
									
										
										
										
											2018-07-04 00:27:14 +08:00
										 |  |  |  | 		{ | 
					
						
							| 
									
										
										
										
											2018-08-15 23:30:23 +08:00
										 |  |  |  | 			auto game = Game::getInstance(); | 
					
						
							|  |  |  |  | 			if (game->isTransitioning()) | 
					
						
							|  |  |  |  | 				break; | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | 			if (game->getCurrentScene()) | 
					
						
							|  |  |  |  | 			{ | 
					
						
							|  |  |  |  | 				game->getCurrentScene()->dispatch(KeyEvent(hWnd, uMsg, wParam, lParam), false); | 
					
						
							|  |  |  |  | 			} | 
					
						
							| 
									
										
										
										
											2018-07-04 00:27:14 +08:00
										 |  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2018-08-15 00:06:03 +08:00
										 |  |  |  | 		result = 0; | 
					
						
							|  |  |  |  | 		hasHandled = true; | 
					
						
							|  |  |  |  | 		break; | 
					
						
							| 
									
										
										
										
											2018-07-03 18:16:26 +08:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-08-15 00:06:03 +08:00
										 |  |  |  | 		// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ڴ<EFBFBD>С<EFBFBD>仯<EFBFBD><E4BBAF>Ϣ
 | 
					
						
							|  |  |  |  | 		case WM_SIZE: | 
					
						
							|  |  |  |  | 		{ | 
					
						
							|  |  |  |  | 			UINT width = LOWORD(lParam); | 
					
						
							|  |  |  |  | 			UINT height = HIWORD(lParam); | 
					
						
							| 
									
										
										
										
											2018-01-30 16:45:38 +08:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-08-15 00:06:03 +08:00
										 |  |  |  | 			if (wParam == SIZE_RESTORED) | 
					
						
							|  |  |  |  | 			{ | 
					
						
							|  |  |  |  | 				window->_width = static_cast<int>(width * 96.f / window->_dpi); | 
					
						
							|  |  |  |  | 				window->_height = static_cast<int>(height * 96.f / window->_dpi); | 
					
						
							|  |  |  |  | 			} | 
					
						
							| 
									
										
										
										
											2018-01-30 16:45:38 +08:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-08-15 00:06:03 +08:00
										 |  |  |  | 			// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>յ<EFBFBD>һ<EFBFBD><D2BB> WM_SIZE <20><>Ϣ<EFBFBD><CFA2><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ⱦ
 | 
					
						
							|  |  |  |  | 			// Ŀ<><C4BF><EFBFBD>ʵ<EFBFBD><CAB5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ܻ<EFBFBD><DCBB><EFBFBD><EFBFBD><EFBFBD>ʧ<EFBFBD>ܣ<EFBFBD><DCA3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ժ<EFBFBD><D4BA><EFBFBD><EFBFBD>п<EFBFBD><D0BF>ܵ<EFBFBD>
 | 
					
						
							|  |  |  |  | 			// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϊ<EFBFBD><CEAA><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>һ<EFBFBD>ε<EFBFBD><CEB5><EFBFBD> EndDraw ʱ<><CAB1><EFBFBD><EFBFBD>
 | 
					
						
							|  |  |  |  | 			auto renderer = Game::getInstance()->getRenderer(); | 
					
						
							|  |  |  |  | 			auto pRT = renderer->getRenderTarget(); | 
					
						
							|  |  |  |  | 			if (pRT) | 
					
						
							|  |  |  |  | 			{ | 
					
						
							|  |  |  |  | 				pRT->Resize(D2D1::SizeU(width, height)); | 
					
						
							|  |  |  |  | 			} | 
					
						
							|  |  |  |  | 		} | 
					
						
							|  |  |  |  | 		break; | 
					
						
							| 
									
										
										
										
											2018-01-30 16:45:38 +08:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-08-15 00:06:03 +08:00
										 |  |  |  | 		// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ڱ<EFBFBD><DAB1><EFBFBD><EFBFBD>仯<EFBFBD><E4BBAF>Ϣ
 | 
					
						
							|  |  |  |  | 		case WM_SETTEXT: | 
					
						
							| 
									
										
										
										
											2018-01-30 16:45:38 +08:00
										 |  |  |  | 		{ | 
					
						
							| 
									
										
										
										
											2018-08-15 00:06:03 +08:00
										 |  |  |  | 			window->_title = (const wchar_t*)lParam; | 
					
						
							| 
									
										
										
										
											2018-01-30 16:45:38 +08:00
										 |  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2018-08-15 00:06:03 +08:00
										 |  |  |  | 		break; | 
					
						
							| 
									
										
										
										
											2018-01-30 16:45:38 +08:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-08-15 00:06:03 +08:00
										 |  |  |  | 		// <20><><EFBFBD><EFBFBD><EFBFBD>ֱ<EFBFBD><D6B1>ʱ仯<CAB1><E4BBAF>Ϣ
 | 
					
						
							|  |  |  |  | 		case WM_DISPLAYCHANGE: | 
					
						
							|  |  |  |  | 		{ | 
					
						
							|  |  |  |  | 			// <20>ػ<EFBFBD><D8BB>ͻ<EFBFBD><CDBB><EFBFBD>
 | 
					
						
							|  |  |  |  | 			InvalidateRect(hWnd, nullptr, FALSE); | 
					
						
							|  |  |  |  | 		} | 
					
						
							|  |  |  |  | 		result = 0; | 
					
						
							|  |  |  |  | 		hasHandled = true; | 
					
						
							|  |  |  |  | 		break; | 
					
						
							| 
									
										
										
										
											2018-01-30 16:45:38 +08:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-08-15 00:06:03 +08:00
										 |  |  |  | 		// <20>ػ洰<D8BB><E6B4B0>
 | 
					
						
							|  |  |  |  | 		case WM_PAINT: | 
					
						
							|  |  |  |  | 		{ | 
					
						
							| 
									
										
										
										
											2018-08-15 23:30:23 +08:00
										 |  |  |  | 			Game::getInstance()->drawScene(); | 
					
						
							| 
									
										
										
										
											2018-08-15 00:06:03 +08:00
										 |  |  |  | 			ValidateRect(hWnd, nullptr); | 
					
						
							|  |  |  |  | 		} | 
					
						
							|  |  |  |  | 		result = 0; | 
					
						
							|  |  |  |  | 		hasHandled = true; | 
					
						
							|  |  |  |  | 		break; | 
					
						
							| 
									
										
										
										
											2018-01-30 16:45:38 +08:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-08-15 00:06:03 +08:00
										 |  |  |  | 		// <20><><EFBFBD>ڹر<DAB9><D8B1><EFBFBD>Ϣ
 | 
					
						
							|  |  |  |  | 		case WM_CLOSE: | 
					
						
							|  |  |  |  | 		{ | 
					
						
							| 
									
										
										
										
											2018-08-15 23:30:23 +08:00
										 |  |  |  | 			auto game = Game::getInstance(); | 
					
						
							|  |  |  |  | 			auto currScene = game->getCurrentScene(); | 
					
						
							|  |  |  |  | 			if (!currScene || currScene->onCloseWindow()) | 
					
						
							| 
									
										
										
										
											2018-08-15 00:06:03 +08:00
										 |  |  |  | 			{ | 
					
						
							| 
									
										
										
										
											2018-08-15 23:30:23 +08:00
										 |  |  |  | 				game->quit(); | 
					
						
							| 
									
										
										
										
											2018-08-15 00:06:03 +08:00
										 |  |  |  | 			} | 
					
						
							|  |  |  |  | 		} | 
					
						
							|  |  |  |  | 		result = 0; | 
					
						
							|  |  |  |  | 		hasHandled = true; | 
					
						
							|  |  |  |  | 		break; | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | 		// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϣ
 | 
					
						
							|  |  |  |  | 		case WM_DESTROY: | 
					
						
							|  |  |  |  | 		{ | 
					
						
							|  |  |  |  | 			PostQuitMessage(0); | 
					
						
							|  |  |  |  | 		} | 
					
						
							|  |  |  |  | 		result = 1; | 
					
						
							|  |  |  |  | 		hasHandled = true; | 
					
						
							|  |  |  |  | 		break; | 
					
						
							| 
									
										
										
										
											2018-01-30 16:45:38 +08:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-08-15 00:06:03 +08:00
										 |  |  |  | 		} | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | 		if (!hasHandled) | 
					
						
							|  |  |  |  | 		{ | 
					
						
							|  |  |  |  | 			result = DefWindowProc(hWnd, uMsg, wParam, lParam); | 
					
						
							|  |  |  |  | 		} | 
					
						
							|  |  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2018-01-30 16:45:38 +08:00
										 |  |  |  | 	return result; | 
					
						
							|  |  |  |  | } |