Magic_Game/Easy2D/Win/winbase.cpp

43 lines
827 B
C++
Raw Normal View History

2017-10-10 01:14:03 +08:00
#include "winbase.h"
2017-10-12 02:44:44 +08:00
#include "..\emacros.h"
2017-10-10 01:14:03 +08:00
2017-10-13 11:42:36 +08:00
HWND hwnd = nullptr;
ID2D1Factory * pDirect2dFactory = nullptr;
ID2D1HwndRenderTarget * pRenderTarget = nullptr;
2017-10-10 01:14:03 +08:00
2017-10-12 02:44:44 +08:00
HWND &GetHWnd()
2017-10-10 01:14:03 +08:00
{
2017-10-13 11:42:36 +08:00
return hwnd;
2017-10-10 01:14:03 +08:00
}
2017-10-12 02:44:44 +08:00
ID2D1Factory * &GetFactory()
2017-10-10 01:14:03 +08:00
{
2017-10-13 11:42:36 +08:00
return pDirect2dFactory;
2017-10-11 11:15:17 +08:00
}
2017-10-12 02:44:44 +08:00
ID2D1HwndRenderTarget * &GetRenderTarget()
2017-10-11 11:15:17 +08:00
{
2017-10-13 11:42:36 +08:00
return pRenderTarget;
2017-10-11 11:15:17 +08:00
}
void WindowCenter(HWND hWnd)
{
// <20><>ȡ<EFBFBD><C8A1>Ļ<EFBFBD>ֱ<EFBFBD><D6B1><EFBFBD>
int screenWidth = GetSystemMetrics(SM_CXSCREEN);
int screenHeight = GetSystemMetrics(SM_CYSCREEN);
// <20><>ȡ<EFBFBD><C8A1><EFBFBD>ڴ<EFBFBD>С
2017-10-12 02:44:44 +08:00
tagRECT rcWindow;
2017-10-11 11:15:17 +08:00
GetWindowRect(hWnd, &rcWindow);
// <20><><EFBFBD>ô<EFBFBD><C3B4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ļ<EFBFBD><C4BB><EFBFBD><EFBFBD>
2017-10-12 02:44:44 +08:00
SetWindowPos(
hWnd,
HWND_TOP,
(screenWidth - (rcWindow.left - rcWindow.right)) / 2,
(screenHeight - (rcWindow.top - rcWindow.bottom)) / 2,
(rcWindow.left - rcWindow.right),
(rcWindow.top - rcWindow.bottom),
SWP_SHOWWINDOW | SWP_NOSIZE
);
2017-10-11 11:15:17 +08:00
}