zoukankan      html  css  js  c++  java
  • 获取windows操作系统分辨率(DPI)

    // ScreenDPI.cpp : Defines the entry point for the console application.
    //

    #include "stdafx.h"
    #include <iostream>
    #include <windows.h>
    #include <math.h>
    using namespace std;

    // 1毫米=0.039370078740157英寸 
    #define INCH 0.03937

    float GetDPI()
    {
        HDC hdcScreen;
        hdcScreen = CreateDC(L"DISPLAY", NULL, NULL, NULL);

        int iX = GetDeviceCaps(hdcScreen, HORZRES);    // pixel
        int iY = GetDeviceCaps(hdcScreen, VERTRES);    // pixel
        int iPhsX = GetDeviceCaps(hdcScreen, HORZSIZE);    // mm
        int iPhsY = GetDeviceCaps(hdcScreen, VERTSIZE);    // mm

        if (NULL != hdcScreen)
        {
            DeleteDC(hdcScreen);
        }
        float iTemp = iPhsX * iPhsX + iPhsY * iPhsY;
        float fInch = sqrt(iTemp) * INCH ;
        iTemp = iX * iX + iY * iY;
        float fPixel = sqrt(iTemp);

        float iDPI = fPixel / fInch;    // dpi pixel/inch
        cout<<"DPI:"<<iDPI<<endl;
        return iDPI;
    }

    int _tmain(int argc, _TCHAR* argv[])
    {
        GetDPI();
        system("pause");
        return 0;
    }
  • 相关阅读:
    阿里Java开发规约【摘录】
    JavaWeb【八、JSP指令与动作元素】
    JavaWeb【七、JSP状态管理】
    JavaWeb【六、JavaBean】
    JavaWeb【五、内置对象】
    JavaWeb【四、JSP基础语法】
    JavaWeb【三、Web程序编写】
    JavaWeb【二、Tomcat安装】
    Django 模板层
    Django auth模块
  • 原文地址:https://www.cnblogs.com/freemindblog/p/5704607.html
Copyright © 2011-2022 走看看