Magic_Game/Easy2D/Win/winbase.cpp

43 lines
839 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-12 02:44:44 +08:00
HWND m_hwnd = nullptr;
ID2D1Factory * m_pDirect2dFactory = nullptr;
ID2D1HwndRenderTarget * m_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-12 02:44:44 +08:00
return m_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-12 02:44:44 +08:00
return m_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-12 02:44:44 +08:00
return m_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
}