小编Alp*_*gas的帖子

SetProcessDPIAware似乎无法在Windows 10下运行

我试图在Windows C++应用程序中获得真正的屏幕分辨率(以像素为单位).当Windows dpi设置改变时,我得到虚拟(调整)分辨率而不是真实分辨率.我尝试使用SetProcessDPIAware,SetProcessDpiAwareness(所有三个枚举值作为参数)和清单中的真实设置.在所有三种情况下,代码在我的Windows 7 PC中工作正常(即显示真实分辨率)但在Win 10中没有(这里它忽略了DPI Aware设置并返回调整后的分辨率).

#define WIN32_LEAN_AND_MEAN  // Exclude rarely-used stuff from Windows headers

// Windows Header Files:
#include <windows.h>
#include <winuser.h>
#include <VersionHelpers.h>
#include <ShellScalingAPI.h>
#include <stdlib.h>
#include <stdio.h>

int APIENTRY WinMain(HINSTANCE hInstance,
                     HINSTANCE hPrevInstance,
                     LPSTR     lpCmdLine,
                     int       nCmdShow)
{
char *cBuffer2 ;

  cBuffer2 = (char *)malloc(3000) ;
  if (IsWindowsVistaOrGreater())
  {
//    SetProcessDpiAwareness(PROCESS_SYSTEM_DPI_AWARE);
      int result = SetProcessDPIAware();

      sprintf(cBuffer2,"SetProcessDPIAware() result: [%i]\n",result) ;

      int height = GetSystemMetrics(SM_CYSCREEN);
      int width = GetSystemMetrics(SM_CXSCREEN);
      sprintf(cBuffer2,"%s#1:\nHeight: [%i]\nwidth: [%i]\n",cBuffer2,height,width) ;


      HWND hwnd = (HWND)atoi(lpCmdLine) …
Run Code Online (Sandbox Code Playgroud)

c++ winapi dpi screen-resolution

7
推荐指数
1
解决办法
6323
查看次数

标签 统计

c++ ×1

dpi ×1

screen-resolution ×1

winapi ×1