获取显示器的设备上限可以为您提供像素和mm的尺寸:
HDC screen = GetDC(NULL);
int hSize=GetDeviceCaps(screen,HORZSIZE);
int hRes=GetDeviceCaps(screen,HORZRES);
float PixelsPerMM=(float)hRes/hSize; // pixels per millimeter
float PixelsPerInch=PixelsPerMM*25.4; //dpi
Run Code Online (Sandbox Code Playgroud)
使用该GetDC函数获取显示器的句柄,然后调用该GetDeviceCaps函数以获取显示器的尺寸(以毫米为单位)。例如:
HDC monitor = GetDC( NULL );
int horizSize = GetDeviceCaps( monitor, HORZSIZE );
int vertSize = GetDeviceCaps( monitor, VERTSIZE );
Run Code Online (Sandbox Code Playgroud)