Exemple #1
0
void Sys_SetHighDPIMode(void)
{
  /* For Vista, Win7 and Win8 */
  BOOL(WINAPI * SetProcessDPIAware)(void) = NULL;

  /* Win8.1 and later */
  HRESULT(WINAPI * SetProcessDpiAwareness)
  (YQ2_PROCESS_DPI_AWARENESS dpiAwareness) = NULL;

  HINSTANCE userDLL = LoadLibrary("USER32.DLL");

  if (userDLL) {
    SetProcessDPIAware = (BOOL(WINAPI *)(void)) GetProcAddress(userDLL, "SetProcessDPIAware");
  }

  HINSTANCE shcoreDLL = LoadLibrary("SHCORE.DLL");

  if (shcoreDLL) {
    SetProcessDpiAwareness =
        (HRESULT(WINAPI *)(YQ2_PROCESS_DPI_AWARENESS)) GetProcAddress(shcoreDLL, "SetProcessDpiAwareness");
  }

  if (SetProcessDpiAwareness) {
    SetProcessDpiAwareness(YQ2_PROCESS_PER_MONITOR_DPI_AWARE);
  } else if (SetProcessDPIAware) {
    SetProcessDPIAware();
  }
}
Exemple #2
0
// Based on the example provided by Eric Wasylishen
// https://discourse.libsdl.org/t/sdl-getdesktopdisplaymode-resolution-reported-in-windows-10-when-using-app-scaling/22389
void WIN_InitDPI()
{
	void* userDLL;
	void* shcoreDLL;

	shcoreDLL = SDL_LoadObject("SHCORE.DLL");
	if (shcoreDLL)
	{
		SetProcessDpiAwareness = (HRESULT(WINAPI *)(PROCESS_DPI_AWARENESS)) SDL_LoadFunction(shcoreDLL, "SetProcessDpiAwareness");
	}

	if (SetProcessDpiAwareness)
	{
		/* Try Windows 8.1+ version */
		HRESULT result = SetProcessDpiAwareness(PROCESS_PER_MONITOR_DPI_AWARE);
		return;
	}

	userDLL = SDL_LoadObject("USER32.DLL");
	if (userDLL)
	{
		SetProcessDPIAware = (BOOL(WINAPI *)(void)) SDL_LoadFunction(userDLL, "SetProcessDPIAware");
	}

	if (SetProcessDPIAware)
	{
		/* Try Vista - Windows 8 version.
		This has a constant scale factor for all monitors.
		*/
		BOOL success = SetProcessDPIAware();
	}
}
Exemple #3
0
int _glfwPlatformInit(void)
{
    // To make SetForegroundWindow work as we want, we need to fiddle
    // with the FOREGROUNDLOCKTIMEOUT system setting (we do this as early
    // as possible in the hope of still being the foreground process)
    SystemParametersInfoW(SPI_GETFOREGROUNDLOCKTIMEOUT, 0,
                          &_glfw.win32.foregroundLockTimeout, 0);
    SystemParametersInfoW(SPI_SETFOREGROUNDLOCKTIMEOUT, 0, UIntToPtr(0),
                          SPIF_SENDCHANGE);

    if (!loadLibraries())
        return GLFW_FALSE;

    createKeyTables();
    _glfwUpdateKeyNamesWin32();

    if (_glfwIsWindows10CreatorsUpdateOrGreaterWin32())
        SetProcessDpiAwarenessContext(DPI_AWARENESS_CONTEXT_PER_MONITOR_AWARE_V2);
    else if (IsWindows8Point1OrGreater())
        SetProcessDpiAwareness(PROCESS_PER_MONITOR_DPI_AWARE);
    else if (IsWindowsVistaOrGreater())
        SetProcessDPIAware();

    if (!_glfwRegisterWindowClassWin32())
        return GLFW_FALSE;

    if (!createHelperWindow())
        return GLFW_FALSE;

    _glfwInitTimerWin32();
    _glfwInitJoysticksWin32();

    _glfwPollMonitorsWin32();
    return GLFW_TRUE;
}
Exemple #4
0
 void SetAwareness(PROCESS_DPI_AWARENESS awareness)
 {
     HRESULT hr = E_FAIL;
     hr = SetProcessDpiAwareness(awareness);
     auto l = E_INVALIDARG;
     if (hr == S_OK) {
         m_Awareness = awareness;
     } else {
         MessageBox(NULL, (LPCWSTR)L"SetProcessDpiAwareness Error", (LPCWSTR)L"Error", MB_OK);
     }
     return;
 }
Exemple #5
0
UINT SetupDPI()
{
    // Just do system DPI awareness for now for simplicity... scale the 3D content
    SetProcessDpiAwareness(PROCESS_SYSTEM_DPI_AWARE);

    UINT dpiX = 0, dpiY;
    POINT pt = { 1, 1 };
    auto hMonitor = MonitorFromPoint(pt, MONITOR_DEFAULTTONEAREST);
    if (SUCCEEDED(GetDpiForMonitor(hMonitor, MDT_EFFECTIVE_DPI, &dpiX, &dpiY))) {
        return dpiX;
    }
    else {
        return 96; // default
    }
}
Exemple #6
0
static void AppInit(int width, int height, const char* title)
{
    CHECKHR(SetProcessDpiAwareness(PROCESS_PER_MONITOR_DPI_AWARE));

    WNDCLASSEXW wc = {};
    wc.cbSize = sizeof(wc);
    wc.lpfnWndProc = WndProc;
    wc.hInstance = GetModuleHandleW(NULL);
    wc.hCursor = LoadCursorW(NULL, IDC_ARROW);
    wc.lpszClassName = L"WindowClass";
    CHECKWIN32(RegisterClassExW(&wc));

    DWORD dwStyle = WS_OVERLAPPEDWINDOW;
    DWORD dwExStyle = 0;
    RECT wr = { 0, 0, width, height };
    CHECKWIN32(AdjustWindowRectEx(&wr, dwStyle, FALSE, dwExStyle));

    std::wstring wtitle = WideFromMultiByte(title);

    HWND hWnd = CreateWindowExW(
        dwExStyle, L"WindowClass", wtitle.c_str(), dwStyle,
        CW_USEDEFAULT, CW_USEDEFAULT,
        wr.right - wr.left, wr.bottom - wr.top,
        NULL, NULL, GetModuleHandleW(NULL), NULL);
    CHECKWIN32(hWnd != NULL);

    RendererInit(hWnd);

    RECT cr;
    CHECKWIN32(GetClientRect(hWnd, &cr));
    RendererResize(
        cr.right - cr.left, cr.bottom - cr.top,
        cr.right - cr.left, cr.bottom - cr.top);

    ShowWindow(hWnd, SW_SHOWDEFAULT);

    g_App.hWnd = hWnd;
    g_App.bShouldClose = false;
}