轉載請注明: http://www.cnblogs.com/Vincentblogs/p/4092104.html
QQ群:346738352 Unity技術交流群,講純粹的技術。
這里使用Win API來獲取當前屏幕分辨率 int GetSystemMetrics(int index);
下面的代碼我是轉換成了DLL庫文件
頭文件:
1 //預編譯頭文件 2 #ifndef SCREENINFO_H 3 #define SCREENINFO_H 4 //所需頭文件 5 #include <Windows.h> 6 #include <WinUser.h> 7 8 #define DLL __declspec(dllexport) 9 10 extern "C" 11 { 12 DLL int GetScreenW();//獲取屏幕寬 13 DLL int GetScreenH();//獲取屏幕高 14 }; 15 16 #endif
源文件:
1 #include "ScreenInfo.h" 2 3 int GetScreenW() 4 { 5 return GetSystemMetrics(SM_CXSCREEN); 6 } 7 int GetScreenH() 8 { 9 return GetSystemMetrics(SM_CYSCREEN); 10 }
這個可以用於Unity3D PC Windows應用,繞過Unity的一些限制。