WindowDC和GetWindowRect之间的尺寸关系是什么?

时间:2019-07-01 16:04:10

标签: visual-c++

  • 我正在编写一个屏幕捕获程序,该程序需要GetWindowDC,GetWindowRect,DwmGetWindowAttribute(DWMWA_EXTENDED_FRAME_BOUNDS),PrintWindow和其他功能。由于某些计算器之类的Windows应用程序具有ws_ex_noredirectionbitmap之类的属性,因此无法从GetWindowDC获取HDC大小
  • 因此,我将注意力重新集中在GetWindowRect上,以尝试通过GetDeviceCaps(HORZRES / VERTRES / DESKTOPHORZRES / DESKTOPVERTRES / LOGPIXELSX / LOGPIXELSY)获得HDC大小。我的计算机系统的dpi设置为150%。通过在目标进程和我自己的进程上调用GetProcessDpiAwareness,我使用以下函数来获取:GetWindowRect(target_hwnd),GetWindowDC(target_hwnd)-> GetCurrentObject(OBJ_BITMAP)-> GetObject
  • dpi可识别(target_proc:0,local_proc:0)

    GetDeviceCaps:

    HORZRES: 2560,
    DESKTOPHORZRES: 3840,
    VERTRES: 1440,
    DESKTOPVERTRES: 2160
    LOGPIXELSX: 96
    LOGPIXELSX: 96
    

    GetWindowRect:

    Width: 669
    Height: 389
    

    GetWindowDC_Dismension:

    Width: 669
    Height: 389
    
  • 可识别dpi(target_proc:0,local_proc:1)

    GetDeviceCaps:

    HORZRES: 3840,
    DESKTOPHORZRES : 3840,
    VERTRES : 2160,
    DESKTOPVERTRES : 2160
    LOGPIXELSX : 144
    LOGPIXELSX : 144
    

    GetWindowRect:

    Width : 1004
    Height : 584
    

    GetWindowDC_Dismension:

    Width : 669
    Height : 389
    
  • 可识别dpi(target_proc:1,local_proc:1)

    GetDeviceCaps:

    HORZRES : 3840,
    DESKTOPHORZRES : 3840,
    VERTRES : 2160,
    DESKTOPVERTRES : 2160
    LOGPIXELSX : 144
    LOGPIXELSX : 144
    

    GetWindowRect:

    Width : 955
    Height : 606
    

    GetWindowDC_Dismension:

    Width : 955
    Height : 606
    
  • dpi感知(target_proc:1,local_proc:0)

    GetDeviceCaps:     霍兹雷斯:2560,     台式机:3840,     垂直:1440,     台式机:2160     LOGPIXELSX:96     LOGPIXELSX:96

    GetWindowRect:

    Width : 637
    Height : 404
    

    GetWindowDC_Dismension:

    Width : 955
    Height : 606
    
  • 所以,这个定律是:

    如果(!target_proc_dpi_aware)

    {

    Windc_dimension = win_rect * 96 / LOGPIXELS;
    

    }

    其他

    {

    Windc_dimension = win_rect * HORZRES_VERTRES / DESKTOPHORZRES_DESKTOPVERTRES;
    

    }

  • 不知道是否有更简单,更有效的方法?

0 个答案:

没有答案