7#include <alicorn/platform/windows.hpp>
48#define NODEFERWINDOWPOS
54inline bool operator== (
const MSG & _Left,
const MSG & _Right)
56 if (_Left.message != _Right.message)
return false;
57 if (_Left.hwnd != _Right.hwnd)
return false;
58 if (_Left.wParam != _Right.wParam)
return false;
59 if (_Left.lParam != _Right.lParam)
return false;
60 if (_Left.time != _Right.time)
return false;
61 if (_Left.pt.x != _Right.pt.x)
return false;
62 if (_Left.pt.y != _Right.pt.y)
return false;
70 public ::alicorn::extension::testing::Proxy<WindowsProxy>
73 MOCK_METHOD4(MessageBoxA,
int (HWND, ::std::string, ::std::string, UINT));
74 MOCK_METHOD1(PostQuitMessage,
void(
int));
75 MOCK_METHOD1(RegisterClassExW, ATOM(WNDCLASSEXW *));
76 MOCK_METHOD1(GetModuleHandleW, HMODULE(LPCWSTR));
77 MOCK_METHOD2(UnregisterClassW, BOOL(::std::wstring, HINSTANCE));
78 MOCK_METHOD2(GetWindowLongPtrW, LONG_PTR (HWND,
int));
79 MOCK_METHOD2(SetWindowLongPtrW, LONG_PTR (HWND,
int));
80 MOCK_METHOD4(DefWindowProcW, LRESULT(HWND, UINT, WPARAM, LPARAM));
81 MOCK_METHOD4(PeekMessageW, BOOL(HWND, UINT, UINT, UINT));
82 MOCK_METHOD3(GetMessageW, BOOL(HWND, UINT, UINT));
83 MOCK_METHOD0(BuildMessage, MSG(
void));
84 MOCK_METHOD1(TranslateMessage, BOOL(MSG));
85 MOCK_METHOD1(DispatchMessageW, LRESULT(MSG));
86 MOCK_METHOD1(Sleep,
void(DWORD));
87 MOCK_METHOD10(CreateWindowExW1,
void(DWORD, ::std::wstring, ::std::wstring,
88 DWORD,
int,
int,
int,
int, HWND, HMENU));
89 MOCK_METHOD2(CreateWindowExW2, HWND(HINSTANCE, LPVOID));
90 MOCK_METHOD1(DestroyWindow, BOOL(HWND));
91 MOCK_METHOD2(ShowWindow, BOOL(HWND,
int));
92 MOCK_METHOD1(GetUserDefaultLocaleName,
int(
int));
93 MOCK_METHOD0(GetLocaleName, ::std::wstring(
void));
94 MOCK_METHOD2(LoadCursorW, HCURSOR (HINSTANCE, ULONG_PTR));
95 MOCK_METHOD2(LoadIconW, HICON(HINSTANCE, ::std::wstring));
96 MOCK_METHOD1(GetDC, HDC (HWND));
97 MOCK_METHOD2(ReleaseDC,
int (HWND, HDC));
98 MOCK_METHOD2(ChoosePixelFormat,
int (HDC,
const PIXELFORMATDESCRIPTOR *));
99 MOCK_METHOD3(SetPixelFormat, BOOL (HDC,
int,
const PIXELFORMATDESCRIPTOR *));
100 MOCK_METHOD1(wglCreateContext, HGLRC (HDC));
101 MOCK_METHOD2(wglMakeCurrent, BOOL (HDC, HGLRC));
102 MOCK_METHOD1(wglDeleteContext, BOOL (HGLRC _hRc));
103 MOCK_METHOD0(BuildRect, RECT(
void));
104 MOCK_METHOD1(GetClientRect, BOOL (HWND));
105 MOCK_METHOD1(SwapBuffers, BOOL (HDC));
106 MOCK_METHOD0(GetCommandLineA, LPSTR (VOID));
107 MOCK_METHOD4(SetClientRect,
void(LONG, LONG, LONG, LONG));
108 MOCK_METHOD3(AdjustWindowRectEx, BOOL (DWORD, BOOL, DWORD));
109 MOCK_METHOD1(GetSystemMetrics,
int (
int));
112 LONG_PTR m_NewLongPtr = NULL;
115inline int MessageBoxA(HWND _hWnd, LPCSTR _Text, LPCSTR _Caption, UINT _Type)
117 return WindowsProxy::GetInstance()->MessageBoxA(_hWnd, _Text, _Caption, _Type);
120inline void PostQuitMessage(
int _ExitCode)
122 WindowsProxy::GetInstance()->PostQuitMessage(_ExitCode);
125inline HMODULE GetModuleHandleW(LPCWSTR _ModuleName)
127 return WindowsProxy::GetInstance()->GetModuleHandleW(_ModuleName);
130inline ATOM RegisterClassExW(WNDCLASSEXW * _pWindowClass)
132 return WindowsProxy::GetInstance()->RegisterClassExW(_pWindowClass);
135inline BOOL UnregisterClassW(LPCWSTR _ClassName, HINSTANCE _hInstance)
137 return WindowsProxy::GetInstance()->UnregisterClassW(_ClassName, _hInstance);
140inline LONG_PTR GetWindowLongPtrW(HWND _hWnd,
int _Index)
142 return WindowsProxy::GetInstance()->GetWindowLongPtrW(_hWnd, _Index);
145inline LONG_PTR SetWindowLongPtrW(HWND _hWnd,
int _Index, LONG_PTR _NewLong)
147 WindowsProxy::GetInstance()->m_NewLongPtr = _NewLong;
148 return WindowsProxy::GetInstance()->SetWindowLongPtrW(_hWnd, _Index);
151inline LRESULT DefWindowProcW(HWND _hWnd, UINT _Msg, WPARAM _wParam, LPARAM _lParam)
153 return WindowsProxy::GetInstance()->DefWindowProcW(_hWnd, _Msg, _wParam, _lParam);
156inline BOOL PeekMessageW(MSG * _pMsg, HWND _hWnd, UINT _MsgFilterMin,
157 UINT _MsgFilterMax, UINT _RemoveMsg)
159 const auto Result = WindowsProxy::GetInstance()->PeekMessageW(_hWnd,
160 _MsgFilterMin, _MsgFilterMax, _RemoveMsg);
164 (*_pMsg) = WindowsProxy::GetInstance()->BuildMessage();
170inline BOOL GetMessageW(MSG * _pMsg, HWND _hWnd,
171 UINT _MsgFilterMin, UINT _MsgFilterMax)
173 const auto Result = WindowsProxy::GetInstance()->GetMessageW(_hWnd,
174 _MsgFilterMin, _MsgFilterMax);
178 (*_pMsg) = WindowsProxy::GetInstance()->BuildMessage();
184inline VOID Sleep(DWORD _Milliseconds)
186 WindowsProxy::GetInstance()->Sleep(_Milliseconds);
189inline BOOL TranslateMessage(
const MSG * _pMsg)
191 return WindowsProxy::GetInstance()->TranslateMessage(*_pMsg);
194inline LRESULT DispatchMessageW(
const MSG * _pMsg)
196 return WindowsProxy::GetInstance()->DispatchMessageW(*_pMsg);
199inline HWND CreateWindowExW(DWORD _ExStyle, LPCWSTR _ClassName,
200 LPCWSTR _WindowName, DWORD _Style,
int _X,
int _Y,
int _Width,
int _Height,
201 HWND _hWndParent, HMENU _hMenu, HINSTANCE _hInstance, LPVOID _pParam)
203 WindowsProxy::GetInstance()->CreateWindowExW1(_ExStyle, _ClassName,
204 _WindowName, _Style, _X, _Y, _Width, _Height, _hWndParent, _hMenu);
205 return WindowsProxy::GetInstance()->CreateWindowExW2(_hInstance, _pParam);
208inline BOOL DestroyWindow(HWND _hWnd)
210 return WindowsProxy::GetInstance()->DestroyWindow(_hWnd);
213inline BOOL ShowWindow(HWND _hWnd,
int _CmdShow)
215 return WindowsProxy::GetInstance()->ShowWindow(_hWnd, _CmdShow);
218inline int GetUserDefaultLocaleName(LPWSTR _LocaleName,
int _LocaleNameCount)
220 const auto LocaleName = WindowsProxy::GetInstance()->GetLocaleName();
221 memcpy_s(_LocaleName, _LocaleNameCount *
sizeof(
wchar_t),
222 LocaleName.data(), LocaleName.size() *
sizeof(
wchar_t));
224 return WindowsProxy::GetInstance()->GetUserDefaultLocaleName(_LocaleNameCount);
227inline HCURSOR LoadCursorW(HINSTANCE _hInstance, LPCWSTR _pCursorName)
229 return WindowsProxy::GetInstance()->LoadCursorW(_hInstance, (ULONG_PTR)_pCursorName);
232inline HICON LoadIconW(HINSTANCE _hInstance, LPCWSTR _pIconName)
234 return WindowsProxy::GetInstance()->LoadIconW(_hInstance, _pIconName);
237inline HDC GetDC(HWND _hWnd)
239 return WindowsProxy::GetInstance()->GetDC(_hWnd);
242inline int ReleaseDC(HWND _hWnd, HDC _hDC)
244 return WindowsProxy::GetInstance()->ReleaseDC(_hWnd, _hDC);
247inline int ChoosePixelFormat(HDC _hDc,
const PIXELFORMATDESCRIPTOR * _pPfd)
249 return WindowsProxy::GetInstance()->ChoosePixelFormat(_hDc, _pPfd);
252inline BOOL SetPixelFormat(HDC _hDc,
int _PixelFormat,
253 const PIXELFORMATDESCRIPTOR * _pPfd)
255 return WindowsProxy::GetInstance()->SetPixelFormat(_hDc, _PixelFormat, _pPfd);
258inline HGLRC wglCreateContext(HDC _hDc)
260 return WindowsProxy::GetInstance()->wglCreateContext(_hDc);
263inline BOOL wglMakeCurrent(HDC _hDc, HGLRC _hRc)
265 return WindowsProxy::GetInstance()->wglMakeCurrent(_hDc, _hRc);
268inline BOOL wglDeleteContext(HGLRC _hRc)
270 return WindowsProxy::GetInstance()->wglDeleteContext(_hRc);
273inline BOOL GetClientRect(HWND _hWnd, LPRECT _pRect)
275 *_pRect = WindowsProxy::GetInstance()->BuildRect();
276 return WindowsProxy::GetInstance()->GetClientRect(_hWnd);
279inline BOOL SwapBuffers(HDC _hDc)
281 return WindowsProxy::GetInstance()->SwapBuffers(_hDc);
284inline LPSTR GetCommandLineA(VOID)
286 return WindowsProxy::GetInstance()->GetCommandLineA();
289inline BOOL AdjustWindowRectEx(RECT * _pRect, DWORD _Style, BOOL _IsMenu,
292 WindowsProxy::GetInstance()->SetClientRect(
293 _pRect->left, _pRect->top, _pRect->right, _pRect->bottom);
294 *_pRect = WindowsProxy::GetInstance()->BuildRect();
295 return WindowsProxy::GetInstance()->AdjustWindowRectEx(_Style, _IsMenu, _ExStyle);
298inline int GetSystemMetrics(
int _Index)
300 return WindowsProxy::GetInstance()->GetSystemMetrics(_Index);
311using ::mock::MessageBoxA;
312using ::mock::GetModuleHandleW;
313using ::mock::RegisterClassExW;
314using ::mock::UnregisterClassW;
315using ::mock::GetWindowLongPtrW;
316using ::mock::DefWindowProcW;
317using ::mock::PeekMessageW;
318using ::mock::GetMessageW;
320using ::mock::TranslateMessage;
321using ::mock::DispatchMessage;
322using ::mock::LoadCursorW;
323using ::mock::LoadIconW;
324using ::mock::GetCommandLineA;
325using ::mock::PostQuitMessage;
332using ::mock::GetModuleHandleW;
333using ::mock::CreateWindowEx;
334using ::mock::ShowWindow;
335using ::mock::DestroyWindow;
336using ::mock::GetUserDefaultLocaleName;
337using ::mock::AdjustWindowRectEx;
338using ::mock::GetSystemMetrics;
339using ::mock::PostQuitMessage;
340using ::mock::SetWindowLongPtrW;
341using ::mock::GetClientRect;
349using ::mock::ReleaseDC;
350using ::mock::ChoosePixelFormat;
351using ::mock::SetPixelFormat;
352using ::mock::wglCreateContext;
353using ::mock::wglMakeCurrent;
354using ::mock::wglDeleteContext;
355using ::mock::GetClientRect;
356using ::mock::SwapBuffers;