Removes windows enumeration on Windows to retrieve HWND taking it from SDL and wxWidgets.
Tested By: Stan Differential Revision: https://code.wildfiregames.com/D4064 This was SVN commit r25709.
This commit is contained in:
parent
40cbde1925
commit
63c1347ef7
@ -20,10 +20,6 @@
|
||||
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
/*
|
||||
* various Windows-specific utilities
|
||||
*/
|
||||
|
||||
#include "precompiled.h"
|
||||
#include "lib/sysdep/os/win/wutil.h"
|
||||
|
||||
@ -40,6 +36,7 @@
|
||||
#include <shlobj.h> // SHGetFolderPath
|
||||
|
||||
#include <SDL_loadso.h>
|
||||
#include <SDL_syswm.h>
|
||||
|
||||
|
||||
WINIT_REGISTER_EARLY_INIT(wutil_Init);
|
||||
@ -409,31 +406,21 @@ HMODULE wutil_LibModuleHandle()
|
||||
|
||||
static HWND hAppWindow;
|
||||
|
||||
static BOOL CALLBACK FindAppWindowByPid(HWND hWnd, LPARAM UNUSED(lParam))
|
||||
void wutil_SetAppWindow(SDL_Window* window)
|
||||
{
|
||||
DWORD pid;
|
||||
DWORD tid = GetWindowThreadProcessId(hWnd, &pid);
|
||||
UNUSED2(tid);
|
||||
SDL_SysWMinfo wmInfo;
|
||||
SDL_VERSION(&wmInfo.version);
|
||||
if (SDL_GetWindowWMInfo(window, &wmInfo) && wmInfo.subsystem == SDL_SYSWM_WINDOWS)
|
||||
hAppWindow = wmInfo.info.win.window;
|
||||
}
|
||||
|
||||
if(pid == GetCurrentProcessId())
|
||||
{
|
||||
char windowName[100];
|
||||
GetWindowTextA(hWnd, windowName, 99);
|
||||
if (strcmp(windowName, main_window_name) == 0)
|
||||
hAppWindow = hWnd;
|
||||
}
|
||||
|
||||
return TRUE; // keep calling
|
||||
void wutil_SetAppWindow(void* hwnd)
|
||||
{
|
||||
hAppWindow = reinterpret_cast<HWND>(hwnd);
|
||||
}
|
||||
|
||||
HWND wutil_AppWindow()
|
||||
{
|
||||
if(!hAppWindow)
|
||||
{
|
||||
WARN_IF_FALSE(EnumWindows(FindAppWindowByPid, 0));
|
||||
// (hAppWindow may still be 0 if we haven't created a window yet)
|
||||
}
|
||||
|
||||
return hAppWindow;
|
||||
}
|
||||
|
||||
|
@ -201,6 +201,8 @@ extern HMODULE wutil_LibModuleHandle();
|
||||
**/
|
||||
extern HWND wutil_AppWindow();
|
||||
|
||||
extern void wutil_SetAppWindow(void* hwnd);
|
||||
|
||||
extern void wutil_EnableHiDPIOnWindows();
|
||||
|
||||
#endif // #ifndef INCLUDED_WUTIL
|
||||
|
@ -48,6 +48,10 @@ int DEFAULT_FULLSCREEN_H = 768;
|
||||
} // anonymous namespace
|
||||
|
||||
#if OS_WIN
|
||||
// We can't include wutil directly because GL headers conflict with Windows
|
||||
// until we use a proper GL loader.
|
||||
extern void wutil_SetAppWindow(SDL_Window* window);
|
||||
|
||||
// After a proper HiDPI integration we should switch to manifest until
|
||||
// SDL has an implemented HiDPI on Windows.
|
||||
extern void wutil_EnableHiDPIOnWindows();
|
||||
@ -164,6 +168,11 @@ bool CVideoMode::SetVideoMode(int w, int h, int bpp, bool fullscreen)
|
||||
else
|
||||
SDL_SetWindowGrab(m_Window, SDL_FALSE);
|
||||
|
||||
#if OS_WIN
|
||||
// We need to set the window for an error dialog.
|
||||
wutil_SetAppWindow(m_Window);
|
||||
#endif
|
||||
|
||||
m_IsFullscreen = fullscreen;
|
||||
|
||||
g_xres = m_CurrentW;
|
||||
|
@ -589,6 +589,10 @@ ScenarioEditor::ScenarioEditor(wxWindow* parent)
|
||||
|
||||
// Send setup messages to game engine:
|
||||
|
||||
// We need to set the window HWND for the error dialog instead of iteraing
|
||||
// through all open windows on Windows.
|
||||
POST_MESSAGE(InitAppWindow, (GetHandle()));
|
||||
|
||||
POST_MESSAGE(InitSDL, ());
|
||||
|
||||
POST_MESSAGE(SetCanvas, (static_cast<wxGLCanvas*>(canvas),
|
||||
|
@ -41,13 +41,19 @@
|
||||
#include "ps/GameSetup/GameSetup.h"
|
||||
#include "renderer/Renderer.h"
|
||||
|
||||
static InputProcessor g_Input;
|
||||
#if OS_WIN
|
||||
// We don't include wutil header directly to prevent including Windows headers.
|
||||
extern void wutil_SetAppWindow(void* hwnd);
|
||||
#endif
|
||||
|
||||
namespace AtlasMessage
|
||||
{
|
||||
|
||||
InputProcessor g_Input;
|
||||
|
||||
// This keeps track of the last in-game user input.
|
||||
// It is used to throttle FPS to save CPU & GPU.
|
||||
static double last_user_activity;
|
||||
|
||||
namespace AtlasMessage {
|
||||
double last_user_activity;
|
||||
|
||||
// see comment in GameLoop.cpp about ah_display_error before using INIT_HAVE_DISPLAY_ERROR
|
||||
const int g_InitFlags = INIT_HAVE_VMODE|INIT_NO_GUI;
|
||||
@ -73,6 +79,15 @@ MESSAGEHANDLER(Init)
|
||||
g_VideoMode.InitNonSDL();
|
||||
}
|
||||
|
||||
MESSAGEHANDLER(InitAppWindow)
|
||||
{
|
||||
#if OS_WIN
|
||||
wutil_SetAppWindow(msg->handle);
|
||||
#else
|
||||
UNUSED2(msg);
|
||||
#endif
|
||||
}
|
||||
|
||||
MESSAGEHANDLER(InitSDL)
|
||||
{
|
||||
UNUSED2(msg);
|
||||
@ -254,4 +269,4 @@ MESSAGEHANDLER(RenderStyle)
|
||||
g_Renderer.SetOverlayRenderMode(msg->wireframe ? EDGED_FACES : SOLID);
|
||||
}
|
||||
|
||||
}
|
||||
} // namespace AtlasMessage
|
||||
|
@ -37,6 +37,10 @@
|
||||
// Initialise some engine code. Must be called before anything else.
|
||||
MESSAGE(Init, );
|
||||
|
||||
MESSAGE(InitAppWindow,
|
||||
((void*, handle)) // Atlas Window handle.
|
||||
);
|
||||
|
||||
// Initialise SDL-related code. Must be called before SetCanvas and InitGraphics.
|
||||
MESSAGE(InitSDL, );
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user