Coder Profile - Show off your skills, get a coder profile.
 
 
 
code pin board Changing the screen resolution in C or C++ Download Source Code
Author Details Code Information
Uranium-239 ( Andrew Carter )

Pinned 2 Codes
Posted 2 Coding Articles

Send A Message
View Coders Profile
Language C
Expires Never
Length 757 Characters (27 Lines)
Password no password
Description

Using WINAPI to change the screen resolution. Calling RestoreScreenResolution() restores the mode saved before the last SetScreenResolution() call.
  1. DEVMODE devPrevMode;
  2. BOOL bPrevSet = FALSE;
  3.  
  4. BOOL SetScreenResolution(INT nWidth, INT nHeight)
  5. {
  6.     DEVMODE devMode;
  7.  
  8.     ZeroMemory(&devMode, sizeof(DEVMODE));
  9.     devMode.dmSize = sizeof(DEVMODE);
  10.  
  11.     if(!EnumDisplaySettings(NULL, ENUM_CURRENT_SETTINGS, &devMode))
  12.         return FALSE;
  13.  
  14.     CopyMemory(&devPrevMode, &devMode, sizeof(DEVMODE));
  15.     bPrevSet = TRUE;
  16.     devMode.dmPelsWidth = nWidth;
  17.     devMode.dmPelsHeight = nHeight;
  18.  
  19.     return (ChangeDisplaySettingsEx(NULL, &devMode, NULL, 0, NULL) == DISP_CHANGE_SUCCESSFUL);
  20. }
  21.  
  22. BOOL RestoreScreenResolution(VOID)
  23. {
  24.     if(bPrevSet)
  25.         return (ChangeDisplaySettingsEx(NULL, &devPrevMode, NULL, 0, NULL) == DISP_CHANGE_SUCCESSFUL);
  26.     return FALSE;
  27. }
code pin board Back To Code Pin Board Post New Code
Please login to post comments.
Page 1 of 1
 
 
Latest News About Coder Profile
Coder Profile Poll
If you made money from keeping your profile up to date, say $30 and up, per month. What extra time would you spend on your profile?

No extra time
A few hours at weekends
A whole day each week
Every minute i can get free


please login to cast your vote
and see the results of this poll
Latest Coder Profile Changes
Coder Profile was last updated
3.20 Years Ago
Official Blog :: Make A Donation :: Credits :: Contact Me
Terms & Conditions :: Privacy Policy :: Documents :: Wallpapers
Version 1.46.00
Copyright © 2007 - 2012, Scott Thompson, All Rights Reserved