From 5b3e83cb6b95dda7db4d1ced5621090a03bfd37d Mon Sep 17 00:00:00 2001 From: Nomango <569629550@qq.com> Date: Wed, 11 Oct 2017 11:15:17 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E5=88=9B=E5=BB=BA=E7=AA=97?= =?UTF-8?q?=E5=8F=A3=E5=87=BD=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Easy2D/Win/winbase.cpp | 72 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 72 insertions(+) diff --git a/Easy2D/Win/winbase.cpp b/Easy2D/Win/winbase.cpp index b7b7004f..64d436cb 100644 --- a/Easy2D/Win/winbase.cpp +++ b/Easy2D/Win/winbase.cpp @@ -1,4 +1,7 @@ #include "winbase.h" +#include +#include +#include static steady_clock::time_point nNow; @@ -10,4 +13,73 @@ steady_clock::time_point GetNow() void FlushSteadyClock() { nNow = steady_clock::now(); // 获取当前时间 +} + +LONGLONG GetInterval(steady_clock::time_point nLast) +{ + return duration_cast(nNow - nLast).count(); +} + +void WindowCenter(HWND hWnd) +{ + // 获取屏幕分辨率 + int screenWidth = GetSystemMetrics(SM_CXSCREEN); + int screenHeight = GetSystemMetrics(SM_CYSCREEN); + // 获取窗口大小 + CRect rcWindow; + GetWindowRect(hWnd, &rcWindow); + // 设置窗口在屏幕居中 + SetWindowPos(hWnd, HWND_TOP, + (screenWidth - rcWindow.Size().cx) / 2, + (screenHeight - rcWindow.Size().cy) / 2, + rcWindow.Size().cx, + rcWindow.Size().cy, + SWP_SHOWWINDOW | SWP_NOSIZE); +} + +void CreateGameWindow() +{ + HWND _wnd; + HINSTANCE s_hInstance; + if (!s_hInstance) + { + s_hInstance = GetModuleHandle(NULL); // Grab An Instance For Our Window + + WNDCLASS wc; // Windows Class Structure + + // Redraw On Size, And Own DC For Window. + wc.style = 0; + wc.lpfnWndProc = _SoundPlayProc; // WndProc Handles Messages + wc.cbClsExtra = 0; // No Extra Window Data + wc.cbWndExtra = 0; // No Extra Window Data + wc.hInstance = s_hInstance; // Set The Instance + wc.hIcon = 0; // Load The Default Icon + wc.hCursor = LoadCursor(NULL, IDC_ARROW); // Load The Arrow Pointer + wc.hbrBackground = NULL; // No Background Required For GL + wc.lpszMenuName = NULL; // We Don't Want A Menu + wc.lpszClassName = _T("Easy2dCallbackWnd"); // Set The Class Name + + if (!RegisterClass(&wc) // Register Our Class + && GetLastError() != 1410) // Class is Already Existent + { + return; + } + } + + _wnd = CreateWindowEx( + WS_EX_APPWINDOW, // Extended Style For The Window + _T("Easy2dCallbackWnd"), // Class Name + NULL, // Window Title + WS_POPUPWINDOW, // Defined Window Style + 0, 0, // Window Position + 0, 0, // Window Width And Height + NULL, // No Parent Window + NULL, // No Menu + s_hInstance, // Instance + NULL); // No Param + + if (_wnd) + { + //SetWindowLongPtr(_wnd, GWLP_USERDATA, (LONG_PTR)this); + } } \ No newline at end of file