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

/*****************************支持高清屏幕**********************************/
#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

猜你喜欢

转载自blog.csdn.net/qq_40650582/article/details/108305530