-3

I was wondering if someone could help me change the screen resolution of the secondary monitor using C++ on Windows 7. I understand this is not much information so if you need more just comment and I'll provide it.

Thanks in advance,

YahooMania
  • 115
  • 4
  • 15

1 Answers1

1

You can do this by setting the correct resolution in a DEVMODE structure, then calling ChangeDisplaySettingsEx to actually make the change.

You may want to use EnumDisplaySettingsEx to find a resolution supported by the display and graphics card in question.

Jerry Coffin
  • 476,176
  • 80
  • 629
  • 1,111
  • for the DEVMODE struct, what do I specify for dmPosition? – YahooMania Apr 15 '13 at 19:57
  • 1
    @YahooMania: If you just want to change resolution, only set DM_PELSWIDTH and DM_PELSHEIGHT in `dmFields`, and `dmPosition` will be ignored. – Jerry Coffin Apr 15 '13 at 20:07
  • I tried that, only setting width and height, but that changes the resolution of the primary monitor only – YahooMania Apr 16 '13 at 02:30
  • 1
    @YahooMania: You typically start with EnumDisplayDevices to find the right display. Then you use EnumDisplaySettings to find valid settings for that display. Finally, you use ChangeDisplaySettingsEx to set the chosen display to one of the available modes. This does work (i.e., I've written code that successfully changes the resolution on my secondary monitor this way). – Jerry Coffin Apr 16 '13 at 04:03
  • At the risk of sounding incredibly stupid, I can't find EnumDisplayDevices in my libraries. I have included Winuser.h and Windows.h and I can see EnumDisplaySettings but not EnumDisplayDevices :S. Do you know what I'm doing wrong? – YahooMania Apr 16 '13 at 16:54
  • 1
    @YahooMania: I'm not sure. [The docs](http://msdn.microsoft.com/en-us/library/windows/desktop/dd162609.aspx) say it's been present since Win2K, so any *reasonably* recent compiler should have it in the headers/libraries. – Jerry Coffin Apr 16 '13 at 19:16