Strange Results with ChangeDisplaySettings and Intel graphics card
I've been getting weird results with ChangeDisplaySettings and my Intel Graphics card. I find that when I try to go fullscreen, it won't do it in the same way as other programs.
My Intel control panel lets me handle different resolutions in 3 ways: Stretching the image, using the original resolution but centering the image, or Maintaining the aspect ratio with letterboxing. I set the default to maintain the aspect ratio, and some old games on my computer end up doing that. However, my program won't do the same. Instead, it gets centered.
Here's the code I'm using:
#include "windows.h"
DEVMODE DevMode;
DEVMODE UsedDevMode;
struct stOptions
{
char szFiles[260];
int xres;
int yres;
int bpp;
bool bMultiMon;
};
stOptions options;
void ApplyOptions(HWND hWnd)
{
int iModeNum=0;
bool bRes, bBpp, bFreq;
bRes=bBpp=bFreq=false;
bool bResult=true;
bool bChanged=false;
int iFreq;
EnumDisplaySettings(NULL, ENUM_CURRENT_SETTINGS, &DevMode); //Get the current frequency
iFreq=DevMode.dmDisplayFrequency;
//With this, I try to find a DevMode that will work for the display. If it can't match all of the user's
//preferences, it will at least try to match as much as it can.
while (bResult)
{
bResult=EnumDisplaySettings(NULL, iModeNum, &DevMode);
if ((DevMode.dmPelsWidth==options.xres)&&(DevMode.dmPelsHeight==options.yres))
{
if (!bRes) EnumDisplaySettings(NULL, iModeNum, &UsedDevMode);
bRes=true; bChanged=true;
if (DevMode.dmBitsPerPel==options.bpp)
{
if (!bBpp) EnumDisplaySettings(NULL, iModeNum, &UsedDevMode);
bBpp=true;
if (DevMode.dmDisplayFrequency==iFreq)
{
EnumDisplaySettings(NULL, iModeNum, &UsedDevMode);
bFreq=true;
break;
}
}
}
iModeNum++;
}
开发者_如何学运维 if (!bChanged)
{
//TODO: add error handling
}
ChangeDisplaySettings(&UsedDevMode, CDS_FULLSCREEN);
MoveWindow(hWnd, 0, 0, options.xres, options.yres, true);
}
I'd like to know if anyone else with an intel card has this problem.
Thanks in advance!
I tried a simpler function and it more like I expected this time:
void ApplyOptions(HWND hWnd)
{
DEVMODE dmScreenSettings; // Device Mode
ZeroMemory (&dmScreenSettings, sizeof (DEVMODE)); // Make Sure Memory Is Cleared
dmScreenSettings.dmSize = sizeof (DEVMODE); // Size Of The Devmode Structure
dmScreenSettings.dmPelsWidth = options.xres; // Select Screen Width
dmScreenSettings.dmPelsHeight = options.yres; // Select Screen Height
dmScreenSettings.dmBitsPerPel = options.bpp; // Select Bits Per Pixel
dmScreenSettings.dmFields = DM_BITSPERPEL | DM_PELSWIDTH | DM_PELSHEIGHT;
if (ChangeDisplaySettings (&dmScreenSettings, CDS_FULLSCREEN) != DISP_CHANGE_SUCCESSFUL)
{
MessageBox(NULL, "Fail", "Error", MB_ICONHAND);
}
//ChangeDisplaySettings(&UsedDevMode, CDS_FULLSCREEN);
MoveWindow(hWnd, 0, 0, options.xres, options.yres, true);
}
I still don't know why this would be any different, but I guess it has something to do with dmScreenSettings.dmFields
.
精彩评论