JCHub

  • Home
  • Category
    • A/V
    • WebRTC
    • Beauty of Programming
    • Linux
    • Windows
    • Moments of Life
    • Campus Life
  • Reference
    • API Reference
    • Utilities
    • AV Test
    • Doc
  • Message Board
  • About
JCHub
Code as My Sword, Lost in Obsession
  1. Main page
  2. Windows
  3. Main content

如何让MFC或其他VS编译的程序支持高DPI

2016年1月8日 5858hotness 16likes 0comments

如今显示器的分辨率是越来越大,2K,4K分辨率的都很常见了。在高分屏下,我们必须对DPI进行缩放,要不显示字体会很小。一般系统默认DPI缩放级别为100%。如果改成150%,200%或者其他,我们会发现部分程序界面显示错乱,这是因为这些程序没有对高DPI进行处理。在VS中编写程序时可以很容易的做到支持DPI。

第一种方法是修改程序的Mainfest,如下图,我用的是VS2015,在属性页的Mainfest Tool中进行修改。

第二种方法是使用SetProcessDpiAwareness函数:

1
2
3
HRESULT WINAPI SetProcessDpiAwareness(
  _In_ PROCESS_DPI_AWARENESS value
);

传入的参数有三个取值选择:

1
2
3
4
5
typedef enum _PROCESS_DPI_AWARENESS {
  PROCESS_DPI_UNAWARE            = 0,
  PROCESS_SYSTEM_DPI_AWARE       = 1,
  PROCESS_PER_MONITOR_DPI_AWARE  = 2
} PROCESS_DPI_AWARENESS;

对应前面VS设置中的三个选项,具体使用可以参考SetProcessDpiAwareness function

This article is licensed with Creative Commons Attribution-NonCommercial-No Derivatives 4.0 International License
Tag: VC++
Last updated:2018年12月23日

Jeff

管理员——代码为剑,如痴如醉

Tip the author Like
< Last article
Next article >

Comments

razz evil exclaim smile redface biggrin eek confused idea lol mad twisted rolleyes wink cool arrow neutral cry mrgreen drooling persevering
Cancel

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Related Posts
  • Visual Studio检查内存泄露方法
  • VC实现程序单实例运行
  • 使用libVLC实现的播放器:支持双击全屏
  • FireBreath插件IE浏览器中文字符乱码问题
  • 基于FireBreath的npapi插件在Firefox下的调试
Categories

COPYRIGHT © 2026 jianchihu.net. ALL RIGHTS RESERVED.

Theme Kratos Made By Seaton Jiang