獲取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;
}


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM