Attention: PROnetworks has upgraded our forum from phpbb2 to phpbb3!!

Please head over to our new converted forum at: http://www.pronetworks.org/forums/

This old forum will remain 'read-only' until approximately February 2009. We look forward to seeing you at the new forum!
Author Message
mudd69
PostPosted: Sun Feb 18, 2007 1:22 am Reply with quote

PRO New Member
 
 


Joined: 18 Feb 2007
Posts: 1
Hey I want to change the screen resolution on Windows, usingg Borland C++. How can I do it? Thanks!
 
Back to top
kd1966
Kevin Durbin
PostPosted: Sun Feb 18, 2007 11:36 pm Reply with quote

PROfessional Member
 
 


Joined: 08 Aug 2005
Posts: 9207
Location: USA - GSO - NC
Hi and welcome to PROnetworks!! Apologize for missing your post; the weekends are the toughest for getting support anywhere, and we are all volunteers here. Please be patient as our members check in periodically and look at your issue; enjoy the site!!
 
Back to top
shougan
Sid Upadhyay
PostPosted: Sun Feb 18, 2007 11:54 pm Reply with quote

PRO GOLD
 
 


Joined: 26 Apr 2004
Posts: 5290
Location: Western Hemisphere
Well I'm more of a java programmer, but this made sense;

Code:

Option Explicit

Const DM_BITSPERPEL As Long = &H40000
Const DM_PELSWIDTH As Long = &H80000
Const DM_PELSHEIGHT As Long = &H100000
Const CDS_FORCE As Long = &H80000000

Const CCDEVICENAME As Long = 32
Const CCFORMNAME As Long = 32

Private Type DEVMODE
    dmDeviceName As String * CCDEVICENAME
    dmSpecVersion As Integer
    dmDriverVersion As Integer
    dmSize As Integer
    dmDriverExtra As Integer
    dmFields As Long
    dmOrientation As Integer
    dmPaperSize As Integer
    dmPaperLength As Integer
    dmPaperWidth As Integer
    dmScale As Integer
    dmCopies As Integer
    dmDefaultSource As Integer
    dmPrintQuality As Integer
    dmColor As Integer
    dmDuplex As Integer
    dmYResolution As Integer
    dmTTOption As Integer
    dmCollate As Integer
    dmFormName As String * CCFORMNAME
    dmUnusedPadding As Integer
    dmBitsPerPel As Long
    dmPelsWidth As Long
    dmPelsHeight As Long
    dmDisplayFlags As Long
    dmDisplayFrequency As Long
End Type
Private Declare Function EnumDisplaySettings Lib "user32" Alias _
    "EnumDisplaySettingsA" (ByVal lpszDeviceName As Long, _
    ByVal modeIndex As Long, lpDevMode As Any) As Boolean
Private Declare Function ChangeDisplaySettings Lib "user32" Alias _
    "ChangeDisplaySettingsA" (lpDevMode As Any, ByVal dwflags As Long) As Long

' change the screen resolution mode
'
' returns True if the requested resolution mode is among those
' supported by the display adapter (otherwise it doesn't even
' try to change the screen resolution)

Function ChangeScreenResolution(ByVal Width As Long, ByVal Height As Long, _
    ByVal NumColors As Long, Optional Frequency As Long) As Boolean
    Dim lpDevMode As DEVMODE
    Dim index As Long
   
    ' set the DEVMODE flags and structure size
    lpDevMode.dmSize = Len(lpDevMode)
    lpDevMode.dmFields = DM_PELSWIDTH Or DM_PELSHEIGHT Or DM_BITSPERPEL
   
    ' retrieve info on the Nth display mode, exit if no more
    Do While EnumDisplaySettings(0, index, lpDevMode) > 0
        ' check whether this is the mode we're looking for
        If lpDevMode.dmPelsWidth = Width And lpDevMode.dmPelsHeight = Height _
            And 2 ^ lpDevMode.dmBitsPerPel = NumColors Then
            ' check that the frequency is also the one we're looking for
            If Frequency = 0 Or Frequency = lpDevMode.dmDisplayFrequency Then
                ' try changing the resolution
                If ChangeDisplaySettings(lpDevMode, CDS_FORCE) = 0 Then
                    ' zero means success
                    ChangeScreenResolution = True
                    Exit Do
                End If
            End If
        End If
        ' skip to next screen mode
        index = index + 1
    Loop

End Function
 
Back to top
toxic chicken
PostPosted: Wed Feb 21, 2007 12:45 am Reply with quote

PRO Level 8
 
 


Joined: 20 Apr 2006
Posts: 314
Location: nowhere, washington.
this was in one of the example archive things i found. a little smaller than sid's.
Code:

#include <windows>
#include <iostream>
int main()
{
int w=1024;
int h=768;
int d=32;
DEVMODE sDevMode;
ZeroMemory(&sDevMode, sizeof(DEVMODE));
sDevMode.dmSize = sizeof(DEVMODE);
sDevMode.dmPelsWidth = w;
sDevMode.dmFields |= DM_PELSWIDTH;
sDevMode.dmPelsHeight = h;
sDevMode.dmFields |= DM_PELSHEIGHT;
sDevMode.dmBitsPerPel = d;
sDevMode.dmFields |= DM_BITSPERPEL;
LONG rVal = ChangeDisplaySettings(&sDevMode, CDS_UPDATEREGISTRY);
switch (rVal)
{
case DISP_CHANGE_SUCCESSFUL:  //The settings change was successful.
break;
default:
cout << "Error.";
break;
}
return 0;
}
 
Back to top
swayzesloan
PostPosted: Sat Feb 02, 2008 3:20 pm Reply with quote

PRO New Member
 
 


Joined: 02 Feb 2008
Posts: 1
this code worked great for me toxic chicken, all i had to do was change "#include <windows>" to "#include <windows>".
 
Back to top
Back to top
Index >> Webmaster Domain & Code Room >> Screen Resolution in C/C++

Page 1 of 1

 


Tired of the Ads? Registered users have 80% less adverts.