Click here to Skip to main content
Click here to Skip to main content

ResSwitch & ResList v1.2 - Easily change screen resolution

By , 3 Mar 2000
 
  • Download source files - 19 Kb
  • Introduction

    Tired of using the Windows Control panel or QuickRes to change your graphics cards screen depth & resolution? This program uses the command line sent to it to change the screen depth & resolution. For example to change into 1024 * 768 in 24 bit color, just use the command line ResSwitch.exe 1024 768 24 0. With this structure you can create a number of shortcuts to ResSwitch on your desktop using different command lines which will allow you to change mode with a simple double click on your desktop. By setting up shortcut keys in the shortcut file to ResSwitch you can quickly change modes by just using the keyboard only. The size of the binary file itself is only 6K.

    Also included is ResList which is a simple console app which lists the available video modes which ResSwitch can use.

    The source zip file contains the ResSwitch and ResList source code, a very handy MFC class to wrap access to the two underlying APIs. ResSwitch and ResList use and a prebuilt binary version of both programs. The enclosed binary requires that you have the MFC 4.2b DLLs already installed. If you haven't already got them on your machine (MFC42.DLL in your Windows system directory), then grab them from Microsoft's web site at http://activex.microsoft.com/controls/vc/mfc42.cab.


    Usage
    History
    API Reference
    Contacting the Author


    Usage

    • To use the class in your code simply include videomod.cpp in your project and #include videomod.h in which ever of your modules needs to make calls to the class.
    • Your code will need to include MFC either statically or dynamically.
    • You will also need to have afxtempl.h in your precompiled header.
    • To see the class in action, have a look at the code in the main function in the module ResList.cpp or the Winmain function in the module ResSwitch.cpp.


    History

    v1.1 (25 September 1997)
    • Changed name QuickerRes to QRes to avoid conflict with a similarly named third party product.
    • Now supports setting the monitor frequency (NT only according to the documentation).
    • Inclusion of a new console mode program called QList (binary & source code) with enumerates all the video modes available. Comes in helpful if QRes is reporting that some options you select are unavailable.

    v1.2 (4 January 1999)

    • Changed name (yet again) from QRes to ResSwitch to avoid conflict with another similarly named third party product.
    • Source code now ships with Visual C++ 5 workspace files now as standard.
    • All source code is now fully UNICODE enabled and UNICODE build configurations are now provided.
    • General tidy up of the codebase.


    API Reference

    The API consists of the public member functions of the classes CVideoMode & CVideoModes.

    CVideoMode
    CVideoModes::GetCurrentVideoMode
    CVideoModes::GetAvailableVideoModes
    CVideoModes::ChangeVideoModePermanently
    CVideoModes::ChangeVideoModeTemporarily
    CVideoModes::CanChangeVideoMode
    CVideoModes::RevertVideoModeToDefault


    CVideoMode

    Remarks:
    This class is an encapsulation of a video mode. It contains 4 public member variables, namely:
    • m_dwBitsPerPixel -- Specifies in bits per pixel the colour resolution of the display device. For example: 4 bits for 16 colours, 8 bits for 256 colours, or 16 bits for 65,536 colours.
    • m_dwWidth -- Specifies the width, in pixels, of the display device.
    • m_dwHeight -- Specifies the height, in pixels, of the display device.
    • m_dwFrequency -- Specifies the frequency, in hertz of the display device in a particular mode. On some early builds of Windows 95, changing the frequency of the display adapter is not supported and this value should be set to 0 which means the default hardware value.


    CVideoModes::GetCurrentVideoMode

    static BOOL CVideoModes::GetCurrentVideoMode(CVideoMode& mode);

    Return Value:
    TRUE if the current video mode was retrieved successfully otherwise FALSE.

    Parameters:

    • mode -- Upon successful return this will contain the current video mode of the main display adapter.

    Remarks:
    Internally this retrieves the current settings GetDeviceCaps() function on a device context for the display.


    CVideoModes::GetAvailableVideoModes

    static BOOL CVideoModes::GetAvailableVideoModes(CAvailableVideoModes& modes);

    Return Value:
    TRUE if the available video modes were retrieved successfully otherwise FALSE.

    Parameters:

    • modes -- Upon successful return this will contain an array containing the available video modes of the main display adapter.

    Remarks:
    Returns all the video modes which the display adapter supports.

    CAvailableVideoModes is defined as follows:
    typedef CArray<CVideoMode, CVideoMode&> CAvailableVideoModes;


    CVideoModes::ChangeVideoModePermanently

    static LONG CVideoModes::ChangeVideoModePermanently(const CVideoMode& mode);

    Return Value:
    Returns one of the following values:

    Value Meaning
    DISP_CHANGE_SUCCESSFUL The settings change was successful.
    DISP_CHANGE_RESTART The computer must be restarted in order for the graphics mode to work.
    DISP_CHANGE_BADFLAGS An invalid set of flags was passed in.
    DISP_CHANGE_FAILED The display driver failed the specified graphics mode.
    DISP_CHANGE_BADMODE The graphics mode is not supported.
    DISP_CHANGE_NOTUPDATED Unable to write settings to the registry.

    Parameters:

    • mode -- The video mode to change into.

    Remarks:
    If this function succeeds then the changes are permanent, meaning that upon next boot of Windows the video mode will be the preserved to that which you just changed into.


    CVideoModes::ChangeVideoModeTemporarily

    static LONG CVideoModes::ChangeVideoModeTemporarily(const CVideoMode& mode);

    Return Value:
    The return value is the same as ChangeVideoModePermanently.

    Parameters:

    • mode -- The video mode to change into.

    Remarks:
    If this function succeeds then the changes are not permanent, meaning that upon next boot of Windows the video mode will be the the same as before you called this function.


    CVideoModes::CanChangeVideoMode

    static LONG CVideoModes::CanChangeVideoMode(const CVideoMode& mode);

    Return Value:
    The return value is the same as ChangeVideoModePermanently.

    Parameters:

    • mode -- he video mode to test whether or not the change can be made.

    Remarks:
    Using this function allows an application to determine if a specified graphics modes is actually valid, without causing the system to change to that graphics mode.


    CVideoModes::RevertVideoModeToDefault

    static LONG CVideoModes::RevertVideoModeToDefault();

    Return Value:
    The return value is the same as ChangeVideoModePermanently.

    Remarks:
    Using this function allows an application to determine if a specified graphics modes is actually valid, without causing the system to change to that graphics mode.



    Contacting the Author

    PJ Naughter
    Email: pjn@indigo.ie
    Web: http://www.naughter.com
    4th January 1999


    License

    This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

    A list of licenses authors might use can be found here

    About the Author

    PJ Naughter
    United States United States
    Member
    No Biography provided

    Sign Up to vote   Poor Excellent
    Add a reason or comment to your vote: x
    Votes of 3 or less require a comment

    Comments and Discussions

     
    You must Sign In to use this message board.
    Search this forum  
        Spacing  Noise  Layout  Per page   
    GeneralMy vote of 5memberJeroen Walter28 Dec '11 - 22:34 
    Just what I needed and well documented, thanks!
    GeneralNot supportedmemberJason Lieber3 Jun '08 - 13:31 
    In reading the threads I see that the command line build may reference the adapter to determine whether or not the graphics mode is supported. If the error is received that the graphics mode is not supported and it is supported when using display settings control panel what would you recommend?
     
    Reslist - 800 x 480 isn't on there, it only has 800 x 600
     
    Thanks in advance
    GeneralThanks Buddymemberprda15 Apr '08 - 20:34 
    Nice Article
    GeneralSome hintsmemberDmitry_Bond10 Apr '08 - 22:09 
    Hi.
     
    Yes. Good tool but...
     
    1) if you are using command line interface - there should not be any MessageBoxes at all!!!
    Example - when start "ResSwitch.exe /?" it displays MessageBox. It should print error message to console.
    Any GUI elements in command line interface is nonsense.
     
    2) It is good to provide some basic help on usage by "/?" or "/help" command line switch.
     
    Regards,
    Dmitry.
    GeneralVisual Basicmemberjames.howell9 Aug '07 - 8:49 
    Is there any chance these could be made into code / class / dll files that could be used in a visual basic .net 2005 program?
     
    I have been using this software from .cmd files for years and think the program is awesome, but I have now started poking around with vb and would like to make use of the code on offer.
     
    Well done on a great program I have relied on and made use of for a long time!
    Generalchange color depth without reboot on win95sussRudy Scott8 Aug '03 - 15:25 
    Changing color depth requires a reboot on older versions of Windows (some versions of Windows 95 in particular exhibit this problem). If the user has some form of DirectX installed there is a nifty trick that will allow you to bypass this reboot.
     
    1) Change the display settings with the appropriate API calls (as shown in this article).
    2) Open a full-screen, exclusive mode directX window.
    3) Close the window.
     
    That's it! Opening and closing DirectX in full screen mode causes GDI to reintialize with your new color depth settings.
     

     
    --Rudy
    GeneralRe: change color depth without reboot on win95membersabrown1002 Jan '08 - 5:58 
    What's the point when .NET won't run on Windows 95?
    GeneralProblem in Compiling error MFC42.lib not foundmemberAzhar Javaid5 Aug '03 - 20:55 
    Hello Thanx for the code
    but there ias a problem when i compile the code it gives me an error that mfc42.lib not found i have downloaded the specified mfc42.exe
    but it did not solve the problem
    GeneralRe: Problem in Compiling error MFC42.lib not foundmemberpjnaughter5 Aug '03 - 23:15 
    If it really is MFC42.lib causing problems then either your install of VC is screwed up or you need to update your lib settings. I'd bet that it is not this and it is "MFC42U.LIB" or "MFC42UD.LIB". If this is the case, then I'd suggest you build the Win32 Ascii or Win32 Debug configuration (if you are not interested in a Unicode build) or else do a custom reinstall of VC specifying that you want the MFC Unicode libraries installed.
    GeneralWoW - great work!memberYovav7 Apr '03 - 5:16 
    What great piece of work !
     
    +
     
    Does it allow keeping the changed screen mode after restarting the computer ?
    (how ?)
     

     
    Best Regards - Yovav Gad
    EMail: Dev@SuperMain.com
    Web-Site: www.SuperMain.com
    GeneralRe: WoW - great work!memberpjnaughter7 Apr '03 - 6:25 
    I'm pretty sure the changes it make are persistant.
    GeneralRe: WoW - great work!memberYovav7 Apr '03 - 7:14 
    10X 4 the fast reply.
     
    I changed on XP (using ResSwitch.exe),
    from 1024x768 to 800x600
     
    after Restart it become 1024x768 again
     
    should I use specific function to remember the last switch ?
     
    Best Regards - Yovav Gad
    EMail: Dev@SuperMain.com
    Web-Site: www.SuperMain.com
    GeneralRe: WoW - great work!memberpjnaughter7 Apr '03 - 8:33 
    To have the change affect any logged in user as opposed to the current user, you need to use the CDS_GLOBAL flag in the call to ChangeDisplaySettings. Currently my class and app does not support this, which I will add for the next user.
    Generalcontrolling rescopy output ?memberflashkid1 May '03 - 11:45 
    Hi,
    Great work pjnaufter .
    I'm not a C++ programmer but I want to use your resList/resCopy
    with a batch script that only outputs user's current display settings in one line .txt file.
    eg.
     
    .txt file :
     
    1024 768 32 60
    ----------------------
    This is because I want to firstly detect and save the current display settings then change it to 640 480 ,run a program , when exit return to previous user display settings is this possible ?
    Thanx
     
    La Elaha Ella Allah
    -------------------------
    http://flashkid.8m.com
    GeneralRe: controlling rescopy output ?memberpjnaughter1 May '03 - 12:18 
    The simplest solution to this would be to just use the C++ class which resList uses and drop it into a new console app which can write to a file or whatever you desire. If you want, contact me directly (pjna@naughter.com) if you want to contract me to do this. Alternatively you could do it yourself if you have access to a C++ compiler
    GeneralRe: WoW - great work!sussSteve Goodman19 Nov '03 - 10:57 
    A workaround that doesn't involve any C++ coding:
    In the batch script that changes the resolution, include a line that creates a file in the user's Windows startup folder with the same resolution that you are changing to.
     
    I.E. If your batch file looks like this:
     
    @echo off
    ResSwitch.exe 1024 768 32 85
     
    include a line that creates a file called "resSwitch.cmd" in C:\Documents and Settings\JohnDoe\Start Menu\Programs\Startup\ that also includes the above.
     
    Make sure that if you have different batch files for different resolutions, the file you generate always has the same name (e.g. resSwitch.cmd), so that it overwrites whatever's in the startup directory. Otherwise, I would think that Windows will run all the scripts in a row, which I wouldn't think would be too healthy for your screen card or screen.
     
    CAVEAT EMPTOR: I haven't tried the above solution yet, but I intend to.
    GeneralProblem: Taskbar doesn't movememberMaciek Niedzielski3 Dec '02 - 11:48 
    In Win2k, when I switch from 800x600 24 to 1024x768, taskbar stays on it's position. This means, it's 800px wide, and is 600px from the top of the screen. Why does it happen and how to fix this??
     
    BTW: In Win2k, is it possible to let every user have different screen resolution?
     
    Maciek Niedzielski
    GeneralRe: Problem: Taskbar doesn't movememberpjnaughter3 Dec '02 - 12:41 
    The API's which the code uses is very dependent on the quality of the graphic card drivers. A couple of ideas:
     
    1. Try it on other machines with the same OS, but different graphics cards to confirm it is a driver issue.
    2. Check you graphics card vendor for updates.
    3. Consult the MSDN for any possible KB articles.
    GeneralGood job, but...memberFranFLY25 Nov '02 - 23:45 
    Good job, but you can do the same thing using
    control Desk.cpl,,3
    Francesc
    GeneralRe: Good job, but...memberpjnaughter26 Nov '02 - 22:53 
    Maybe so, but I thought Code Project was about sharing code on how to do things in Windows. Pointing out that Windows has a built in way of achieving the same is not much good to the programmer who wants to find out the API calls which MS use and provide.
    GeneralRe: Good job, but...memberYovav7 Apr '03 - 5:14 
    Hi,
     
    How it is possible to execute this ?
     
    executing "control Desk.cpl,,3" just brings me the screen resolution change screen,
     
    + does it allow U to know what are the available modes ?
     

    Thanks in advanced.

     
    Best Regards - Yovav Gad
    EMail: Dev@SuperMain.com
    Web-Site: www.SuperMain.com
    GeneralRe: Good job, but...memberpjnaughter7 Apr '03 - 6:27 
    Using this command line is just a shortcut to bringing up control panel applets. It will do nothing more than that. If you want to get the list of modes, then just use the Windows API just like the ResList app does i.e. just look at the code in it!.
    QuestionCan you help me?sussRaducu21 Aug '02 - 13:47 
    How can I modify Gamma, Brightness, Contrast or temperature for my video dispaly from my program ?
    Thank you!Eek! | :eek: Eek! | :eek:

    AnswerRe: Can you help me?memberpjnaughter21 Aug '02 - 23:29 
    This is adapter specific and AFAIK there is no documented Win32 API's to allow you to do this. You will need to contact the developers of your monitor to see if they allow this functionality to be programatically change. For example my Mitsubshi DiamondPro monitor provides an App which changes these settings via a USB connection.
    GeneralKudos!memberGlenn8 Feb '02 - 4:53 
    Cool | :cool: Very, very cool. Thanks for sharing this.

    General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

    Permalink | Advertise | Privacy | Mobile
    Web04 | 2.6.130523.1 | Last Updated 4 Mar 2000
    Article Copyright 2000 by PJ Naughter
    Everything else Copyright © CodeProject, 1999-2013
    Terms of Use
    Layout: fixed | fluid