Please help with ChangeDisplaySettings
I want to do simple thing - change refresh rate.
I wrote simple code:
LPDEVMODE newres;
newres->dmSize=sizeof(newres);
EnumDisplaySettings(NULL,ENUM_CURRENT_SETTINGS,newres);
newres->dmDisplayFrequency=70;
ChangeDisplaySettings(newres,CDS_UPDATEREGISTRY);
BUT it does'nt work.
I know exactly, that this frequency is supported at this resolution, 'case I can setup it manually in properties dialog. But this code does't work. Why?
Re: Please help with ChangeDisplaySettings
Firstly, you're not allocating any memory for your DEVMODE pointer, and not initializing it (I would expect your code to crash!).
Secondly, it's worth looking at the return values for the API calls - they will help you find problems as and when they occur and are good programming practice.
The following code works fine for me:DEVMODE newres; // note, allocate a whole DEVMODE structure, not just a pointer to one
newres.dmSize=sizeof(newres);
newres.dmDriverExtra = 0;
if (EnumDisplaySettings(NULL,ENUM_CURRENT_SETTINGS,&newres))
{
newres.dmDisplayFrequency=70;
long nResult = ChangeDisplaySettings(&newres,CDS_UPDATEREGISTRY);
}
Re: Please help with ChangeDisplaySettings
Hi Darren,
Why do you expect the code crash if dmDriverExtra is not initialized?
I have a project which uses ChangeVGADisplaySettings() in a way similar to this guy's code. It doesn't crash if I use a not very high frequency,lower than 100mhz, while setting VGA timing. But it does crash if I use a higher frquency for higher resolution,such as 14x10 or 16x12.
Do you think it is caused by dmDriverExtra that is not initialized? Or by anything else? I did not change refresh rate in my code because the frequency and resolution will force it to that rate. Have I made any mistake here?
Thanks in advance.