Use W APIs only necessary

This commit is contained in:
Cloud Wu 2019-05-09 09:31:19 +08:00
parent 65aa58aab1
commit 0c6ea27310

View File

@ -462,11 +462,11 @@ namespace entry
int32_t run(int _argc, const char* const* _argv) int32_t run(int _argc, const char* const* _argv)
{ {
SetDllDirectoryW(L"."); SetDllDirectoryA(".");
s_xinput.init(); s_xinput.init();
HINSTANCE instance = (HINSTANCE)GetModuleHandleW(NULL); HINSTANCE instance = (HINSTANCE)GetModuleHandle(NULL);
WNDCLASSEXW wnd; WNDCLASSEXW wnd;
bx::memSet(&wnd, 0, sizeof(wnd) ); bx::memSet(&wnd, 0, sizeof(wnd) );
@ -474,17 +474,17 @@ namespace entry
wnd.style = CS_HREDRAW | CS_VREDRAW; wnd.style = CS_HREDRAW | CS_VREDRAW;
wnd.lpfnWndProc = wndProc; wnd.lpfnWndProc = wndProc;
wnd.hInstance = instance; wnd.hInstance = instance;
wnd.hIcon = LoadIconW(NULL, (LPWSTR)IDI_APPLICATION); wnd.hIcon = LoadIcon(NULL, IDI_APPLICATION);
wnd.hCursor = LoadCursorW(NULL, (LPWSTR)IDC_ARROW); wnd.hCursor = LoadCursor(NULL, IDC_ARROW);
wnd.lpszClassName = L"bgfx"; wnd.lpszClassName = L"bgfx";
wnd.hIconSm = LoadIconW(NULL, (LPWSTR)IDI_APPLICATION); wnd.hIconSm = LoadIcon(NULL, IDI_APPLICATION);
RegisterClassExW(&wnd); RegisterClassExW(&wnd);
m_windowAlloc.alloc(); m_windowAlloc.alloc();
m_hwnd[0] = CreateWindowExW( m_hwnd[0] = CreateWindowExA(
WS_EX_ACCEPTFILES WS_EX_ACCEPTFILES
, L"bgfx" , "bgfx"
, L"BGFX" , "BGFX"
, WS_OVERLAPPEDWINDOW|WS_VISIBLE , WS_OVERLAPPEDWINDOW|WS_VISIBLE
, 0 , 0
, 0 , 0
@ -569,7 +569,7 @@ namespace entry
, msg->m_height , msg->m_height
, NULL , NULL
, NULL , NULL
, (HINSTANCE)GetModuleHandleW(NULL) , (HINSTANCE)GetModuleHandle(NULL)
, 0 , 0
); );
clear(hwnd); clear(hwnd);
@ -755,7 +755,7 @@ namespace entry
HWND parent = GetWindow(_hwnd, GW_OWNER); HWND parent = GetWindow(_hwnd, GW_OWNER);
if (NULL != parent) if (NULL != parent)
{ {
PostMessageW(parent, _id, _wparam, _lparam); PostMessage(parent, _id, _wparam, _lparam);
} }
} }
} }
@ -951,7 +951,7 @@ namespace entry
if (m_frame) if (m_frame)
{ {
GetWindowRect(_hwnd, &m_rect); GetWindowRect(_hwnd, &m_rect);
m_style = GetWindowLongW(_hwnd, GWL_STYLE); m_style = GetWindowLong(_hwnd, GWL_STYLE);
} }
if (_windowFrame) if (_windowFrame)
@ -964,13 +964,13 @@ namespace entry
HMONITOR monitor = MonitorFromWindow(_hwnd, MONITOR_DEFAULTTONEAREST); HMONITOR monitor = MonitorFromWindow(_hwnd, MONITOR_DEFAULTTONEAREST);
MONITORINFO mi; MONITORINFO mi;
mi.cbSize = sizeof(mi); mi.cbSize = sizeof(mi);
GetMonitorInfoW(monitor, &mi); GetMonitorInfo(monitor, &mi);
newrect = mi.rcMonitor; newrect = mi.rcMonitor;
rect = mi.rcMonitor; rect = mi.rcMonitor;
m_aspectRatio = float(newrect.right - newrect.left)/float(newrect.bottom - newrect.top); m_aspectRatio = float(newrect.right - newrect.left)/float(newrect.bottom - newrect.top);
} }
SetWindowLongW(_hwnd, GWL_STYLE, style); SetWindowLong(_hwnd, GWL_STYLE, style);
uint32_t prewidth = newrect.right - newrect.left; uint32_t prewidth = newrect.right - newrect.left;
uint32_t preheight = newrect.bottom - newrect.top; uint32_t preheight = newrect.bottom - newrect.top;
AdjustWindowRect(&newrect, style, FALSE); AdjustWindowRect(&newrect, style, FALSE);
@ -1109,7 +1109,7 @@ namespace entry
msg->m_height = _height; msg->m_height = _height;
msg->m_title = _title; msg->m_title = _title;
msg->m_flags = _flags; msg->m_flags = _flags;
PostMessageW(s_ctx.m_hwnd[0], WM_USER_WINDOW_CREATE, handle.idx, (LPARAM)msg); PostMessage(s_ctx.m_hwnd[0], WM_USER_WINDOW_CREATE, handle.idx, (LPARAM)msg);
} }
return handle; return handle;
@ -1119,7 +1119,7 @@ namespace entry
{ {
if (UINT16_MAX != _handle.idx) if (UINT16_MAX != _handle.idx)
{ {
PostMessageW(s_ctx.m_hwnd[0], WM_USER_WINDOW_DESTROY, _handle.idx, 0); PostMessage(s_ctx.m_hwnd[0], WM_USER_WINDOW_DESTROY, _handle.idx, 0);
bx::MutexScope scope(s_ctx.m_lock); bx::MutexScope scope(s_ctx.m_lock);
s_ctx.m_windowAlloc.free(_handle.idx); s_ctx.m_windowAlloc.free(_handle.idx);
@ -1131,19 +1131,19 @@ namespace entry
Msg* msg = new Msg; Msg* msg = new Msg;
msg->m_x = _x; msg->m_x = _x;
msg->m_y = _y; msg->m_y = _y;
PostMessageW(s_ctx.m_hwnd[0], WM_USER_WINDOW_SET_POS, _handle.idx, (LPARAM)msg); PostMessage(s_ctx.m_hwnd[0], WM_USER_WINDOW_SET_POS, _handle.idx, (LPARAM)msg);
} }
void setWindowSize(WindowHandle _handle, uint32_t _width, uint32_t _height) void setWindowSize(WindowHandle _handle, uint32_t _width, uint32_t _height)
{ {
PostMessageW(s_ctx.m_hwnd[0], WM_USER_WINDOW_SET_SIZE, _handle.idx, (_height<<16) | (_width&0xffff) ); PostMessage(s_ctx.m_hwnd[0], WM_USER_WINDOW_SET_SIZE, _handle.idx, (_height<<16) | (_width&0xffff) );
} }
void setWindowTitle(WindowHandle _handle, const char* _title) void setWindowTitle(WindowHandle _handle, const char* _title)
{ {
Msg* msg = new Msg; Msg* msg = new Msg;
msg->m_title = _title; msg->m_title = _title;
PostMessageW(s_ctx.m_hwnd[0], WM_USER_WINDOW_SET_TITLE, _handle.idx, (LPARAM)msg); PostMessage(s_ctx.m_hwnd[0], WM_USER_WINDOW_SET_TITLE, _handle.idx, (LPARAM)msg);
} }
void setWindowFlags(WindowHandle _handle, uint32_t _flags, bool _enabled) void setWindowFlags(WindowHandle _handle, uint32_t _flags, bool _enabled)
@ -1151,24 +1151,24 @@ namespace entry
Msg* msg = new Msg; Msg* msg = new Msg;
msg->m_flags = _flags; msg->m_flags = _flags;
msg->m_flagsEnabled = _enabled; msg->m_flagsEnabled = _enabled;
PostMessageW(s_ctx.m_hwnd[0], WM_USER_WINDOW_SET_FLAGS, _handle.idx, (LPARAM)msg); PostMessage(s_ctx.m_hwnd[0], WM_USER_WINDOW_SET_FLAGS, _handle.idx, (LPARAM)msg);
} }
void toggleFullscreen(WindowHandle _handle) void toggleFullscreen(WindowHandle _handle)
{ {
PostMessageW(s_ctx.m_hwnd[0], WM_USER_WINDOW_TOGGLE_FRAME, _handle.idx, 0); PostMessage(s_ctx.m_hwnd[0], WM_USER_WINDOW_TOGGLE_FRAME, _handle.idx, 0);
} }
void setMouseLock(WindowHandle _handle, bool _lock) void setMouseLock(WindowHandle _handle, bool _lock)
{ {
PostMessageW(s_ctx.m_hwnd[0], WM_USER_WINDOW_MOUSE_LOCK, _handle.idx, _lock); PostMessage(s_ctx.m_hwnd[0], WM_USER_WINDOW_MOUSE_LOCK, _handle.idx, _lock);
} }
int32_t MainThreadEntry::threadFunc(bx::Thread* /*_thread*/, void* _userData) int32_t MainThreadEntry::threadFunc(bx::Thread* /*_thread*/, void* _userData)
{ {
MainThreadEntry* self = (MainThreadEntry*)_userData; MainThreadEntry* self = (MainThreadEntry*)_userData;
int32_t result = main(self->m_argc, self->m_argv); int32_t result = main(self->m_argc, self->m_argv);
PostMessageW(s_ctx.m_hwnd[0], WM_QUIT, 0, 0); PostMessage(s_ctx.m_hwnd[0], WM_QUIT, 0, 0);
return result; return result;
} }