日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 编程语言 > c/c++ >内容正文

c/c++

VC++获取屏幕大小第二篇 物理大小GetDeviceCaps 上

發(fā)布時間:2025/3/12 c/c++ 17 豆豆
生活随笔 收集整理的這篇文章主要介紹了 VC++获取屏幕大小第二篇 物理大小GetDeviceCaps 上 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
上一篇《 VC++獲取屏幕大小第一篇像素大小GetSystemMetrics 》中介紹了使用GetSystemMetrics函數(shù)來獲取屏幕的像素大小,本篇將介紹使用GetDeviceCaps函數(shù)來獲取屏幕的物理大小。下面來看看GetDeviceCaps函數(shù)的用法:

函數(shù)功能:用于得到被定義的系統(tǒng)數(shù)據(jù)或者系統(tǒng)配置信息

函數(shù)原型:獲取一些設(shè)備數(shù)據(jù)

//?By?MoreWindows(?http://blog.csdn.NET/MoreWindows?) ?

int GetDeviceCaps(

?????? HDChdc,???? // handle to DC

?????? int nIndex?? // index of capability

);

參數(shù)說明:

第一個參數(shù)表示設(shè)備環(huán)境的HDC句柄。

第二個參數(shù)與GetSystemMetrics函數(shù)的參數(shù)類似,有很多種取值,這里就不一一列舉了,常用的有二個:

HORZSIZE

?????????????? Width, in millimeters, of the physical screen.

VERTSIZE

?????????????? Height, in millimeters, of the physical screen.

http://blog.csdn.net/morewindows/article/details/8502592?

?

GetDeviceCaps函數(shù)的介紹可知獲取屏幕的物理大小非常簡單,下面給出完整的源代碼:

[cpp] view plaincopy print?
  • //?獲取屏幕大小?物理大小?<a?href="http://blog.csdn.net/morewindows/article/details/8502592">http://blog.csdn.net/morewindows/article/details/8502592</a>??
  • #include?<stdio.h>??
  • #include?<windows.h>??
  • int?main()??
  • {??
  • ????printf("????獲取屏幕大小?物理大小\n");??????????
  • ????printf("?--?By?MoreWindows(?http://blog.csdn.net/MoreWindows?)?--\n\n");?????
  • ??????
  • ????int?nScreenWidth,?nScreenHeight;??
  • ????HDC?hdcScreen?=?GetDC(NULL);???//獲取屏幕的HDC??
  • ????nScreenWidth?=?GetDeviceCaps(hdcScreen,?HORZSIZE);??
  • ????nScreenHeight?=?GetDeviceCaps(hdcScreen,?VERTSIZE);??
  • ??????
  • ????printf("屏幕大小(毫米)?寬:%d?高:%d\n",?nScreenWidth,?nScreenHeight);??
  • ????return?0;??
  • }??
  • // 獲取屏幕大小 物理大小 http://blog.csdn.net/morewindows/article/details/8502592 #include <stdio.h> #include <windows.h> int main() {printf(" 獲取屏幕大小 物理大小\n"); printf(" -- By MoreWindows( http://blog.csdn.net/MoreWindows ) --\n\n"); int nScreenWidth, nScreenHeight;HDC hdcScreen = GetDC(NULL); //獲取屏幕的HDCnScreenWidth = GetDeviceCaps(hdcScreen, HORZSIZE);nScreenHeight = GetDeviceCaps(hdcScreen, VERTSIZE);printf("屏幕大小(毫米) 寬:%d 高:%d\n", nScreenWidth, nScreenHeight);return 0; }

    程序運(yùn)行結(jié)果如下所示:

    ?

    ?

    ?

    后面一篇《VC++獲取屏幕大小第三篇物理大小GetDeviceCaps》將介紹獲取屏幕的物理大小后計算屏幕對角線長度,再換算成英寸。這樣可以方便大家查看自己電腦屏幕是多少英寸的,很多筆記本用戶會有意外喔^_^。歡迎繼續(xù)瀏覽。地址:http://blog.csdn.net/morewindows/article/details/8610891

    ?

    轉(zhuǎn)載請標(biāo)明出處,原文地址:http://blog.csdn.net/morewindows/article/details/8502592

    歡迎關(guān)注微博:http://weibo.com/MoreWindows


    ?

    Note: ?MSDN對GetDeviceCaps函數(shù)有說明:GetDeviceCaps reports info that the display driver provides. If the display driver declines to report any info, GetDeviceCaps calculates the info based on fixed calculations. If the display driver reports invalid info, GetDeviceCaps returns the invalid info. Also, if the display driver declines to report info, GetDeviceCaps might calculate incorrect info because it assumes either fixed DPI (96 DPI) or a fixed size (depending on the info that the display driver did and didn’t provide). Unfortunately, a display driver that is implemented to the Windows Display Driver Model (WDDM) (introduced in Windows?Vista) causes GDI to not get the info, so GetDeviceCaps must always calculate the info.

    ?

    總結(jié)

    以上是生活随笔為你收集整理的VC++获取屏幕大小第二篇 物理大小GetDeviceCaps 上的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

    如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。