欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

Qt 使用windows api支持高清屏显示界面(2K,界面字体正常)

程序员文章站 2024-03-22 22:04:34
...
/*****************************支持高清屏幕**********************************/
#ifdef Q_OS_WIN
#include "Windows.h"

typedef enum PROCESS_DPI_AWARENESS
{
    PROCESS_DPI_UNAWARE = 0,
    PROCESS_SYSTEM_DPI_AWARE = 1,
    PROCESS_PER_MONITOR_DPI_AWARE = 2
} PROCESS_DPI_AWARENESS;

#endif

typedef BOOL (WINAPI * SETPROCESSDPIAWARE_T)(void);
typedef HRESULT (WINAPI * SETPROCESSDPIAWARENESS_T)(PROCESS_DPI_AWARENESS);

static bool win32_SetProcessDpiAware(void)
{
    bool ret = false;

    HMODULE shcore = LoadLibraryA("Shcore.dll");
    SETPROCESSDPIAWARENESS_T SetProcessDpiAwareness = NULL;

    if(shcore)
    {
        SetProcessDpiAwareness = (SETPROCESSDPIAWARENESS_T)GetProcAddress(shcore, "SetProcessDpiAwareness");
    }

    if(SetProcessDpiAwareness)
    {
        ret = SetProcessDpiAwareness(PROCESS_DPI_UNAWARE) == S_OK;
    }
    return ret;
}
/*****************************支持高清屏幕**********************************/
————————————————————————————————————————————


int main(int argc, char *argv[])
{
#ifdef Q_OS_WIN

    //高清屏
    win32_SetProcessDpiAware();

#endif

}

如果编译不过加gdi32.lib文件

pro文件中添加:

LIBS += -lgdi32
相关标签: Qt开发 qt