C++ Full screen

This is a discussion on C++ Full screen within the Windows Programming forums, part of the Platform Specific Boards category; Which is why I can't pass what you suggested of "800, 600, 32" - as that's 3 parameters? What should ...

  1. #16
    Registered User
    Join Date
    Mar 2010
    Posts
    20
    Which is why I can't pass what you suggested of "800, 600, 32" - as that's 3 parameters? What should I pass as my value for the first parameter?

  2. #17
    Registered User Codeplug's Avatar
    Join Date
    Mar 2003
    Posts
    4,647
    You need to be able to read and comprehend source code in order to write your own.
    Code:
    #include <windows.h>
    #include <iostream>
    using namespace std;
    
    bool FindBestDisplayMode(DEVMODE &best, DWORD width, DWORD height, DWORD bpp)
    {
        DEVMODE dm = {0};
        dm.dmSize = sizeof(DEVMODE);
    
        DWORD n, maxFreq = 0;
        bool found = false;
    
        for (n = 0; EnumDisplaySettings(NULL, n, &dm); n++)
        {
            if ((dm.dmPelsWidth == width) && 
                (dm.dmPelsHeight == height) &&
                (dm.dmBitsPerPel == bpp))
            {
                if ((dm.dmFields & DM_ORIENTATION) && 
                    (dm.dmOrientation != DMDO_DEFAULT))
                {
                    // only select default orientation
                    continue;
                }//if
    
                if (dm.dmDisplayFrequency > maxFreq)
                {
                    maxFreq = dm.dmDisplayFrequency;
                    best = dm;
                    found = true;
                }//if
            }//if
        }//for
    
        return found;
    }//FindBestDisplayMode
    
    ostream& operator<<(ostream &out, const DEVMODE &dm)
    {
        return out << dm.dmPelsWidth << 'x' << dm.dmPelsHeight  << 'x' 
                   << dm.dmBitsPerPel  << '-' << dm.dmDisplayFrequency;
    }//ostream << DEVMODE
    
    int main()
    {
        const DWORD W = 800, H = 600;
        DEVMODE dm;
        bool bFound = FindBestDisplayMode(dm, W, H, 32) ||
                      FindBestDisplayMode(dm, W, H, 16);
        if (!bFound)
        {
            cerr << H << 'x' << W << " resolution not found." << endl;
            return 1;
        }//if
    
        LONG cds = ChangeDisplaySettings(&dm, CDS_FULLSCREEN);
        if (cds != DISP_CHANGE_SUCCESSFUL)
        {
            cerr << "Failed to change display settings to " 
                 << dm << ", ec=" << GetLastError() << endl;
            return 2;
        }//if
        
        cout << "Display now in " << dm << endl;
        cout << "Enjoy for the next 20 seconds..." << endl;
    
        Sleep(20 * 1000);
    
        cds = ChangeDisplaySettings(0, 0);
        if (cds != DISP_CHANGE_SUCCESSFUL)
        {
            cerr << "Uh-Oh, didn't change back, ec=" << GetLastError() << endl;
            return 3;
        }//if
    
        return 0;
    }//main
    gg

  3. #18
    Registered User
    Join Date
    Mar 2010
    Posts
    20
    Still black-screens.
    I even fiddled with it a bit and made it just go Sleep and then ChangeDisplay(0, 0);
    It sleeps for 20 seconds... And then black-screens.
    Last edited by MinatureCookie; 03-13-2010 at 03:07 PM.

  4. #19
    Registered User Codeplug's Avatar
    Join Date
    Mar 2003
    Posts
    4,647
    If you ran the above program, unmodified, and your screen went black and stayed that way - then you have a buggy video driver or an invalid monitor INF file.

    Make sure your video drivers are up-to-date and that you're system recognizes your monitor correctly

    From the start menu, run "desk.cpl". Is "Display" correct? What is your monitor's make/model?

    Code:
    int main()
    {
        const DWORD W = 800, H = 600;
        DEVMODE dm;
        bool bFound = FindBestDisplayMode(dm, W, H, 32) ||
                      FindBestDisplayMode(dm, W, H, 16);
        if (!bFound)
        {
            cerr << H << 'x' << W << " resolution not found." << endl;
            return 1;
        }//if
    
        cout << "Found settings: " << dm << endl;
        return 0;
    }//main
    If you run that main(), what is the output?

    gg

  5. #20
    Registered User
    Join Date
    Mar 2010
    Posts
    20
    There's nothing wrong with my drivers, I can play video games that are programmed in C++ full-screen all the time.
    Display comes up fine in "desk.cpl" - my monitor's just my TV, but the same thing happens when I run it through my "NEC AccuSync LCD 72VM" monitor.
    And when I run that code it comes out as "800x600x32-75"

  6. #21
    Registered User Codeplug's Avatar
    Join Date
    Mar 2003
    Posts
    4,647
    Run desk.cpl and change your settings to 800x600x32 via GUI. What happens?

    gg

  7. #22
    Registered User
    Join Date
    Mar 2010
    Posts
    20
    It changes to make itself 800x600.

  8. #23
    Registered User Codeplug's Avatar
    Join Date
    Mar 2003
    Posts
    4,647
    What frequency does it use?

    gg

  9. #24
    Registered User
    Join Date
    Mar 2010
    Posts
    20
    60Hz I think. Although I can change it to 70 or 75Hz at 800x600 and it still runs fine.

  10. #25
    Registered User Codeplug's Avatar
    Join Date
    Mar 2003
    Posts
    4,647
    In desk.cpl, is the display you are using labeled #1?

    gg

  11. #26
    Registered User
    Join Date
    Mar 2010
    Posts
    20
    Yes.

  12. #27
    Registered User Codeplug's Avatar
    Join Date
    Mar 2003
    Posts
    4,647
    All I can say is get the latest drivers and try the code in post #17 again.

    gg

  13. #28
    Registered User
    Join Date
    Jan 2010
    Posts
    412
    If you run the program in post 17, what is the value of dm.dmFields after FindBestDisplayMode()?

  14. #29
    Registered User
    Join Date
    Mar 2010
    Posts
    20
    It has a value of...
    8126592

  15. #30
    Registered User
    Join Date
    Jan 2010
    Posts
    412
    Seems like the DM_DISPLAYFLAGS flag is set. Maybe windows tries to change to an interlaced mode and your monitor can't handle that.
    Try inserting
    Code:
    dm.dmFields ^= DM_DISPLAYFLAGS;
    dm.dmDisplayFlags = 0;
    just before the first call to ChangeDisplaySettings()

    Btw, have you tried setting dm.dmDisplayFrequency to 0 to let windows auto select the refresh rate?

Page 2 of 3 FirstFirst 123 LastLast
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. C++ Full Screen
    By Unregistered in forum C++ Programming
    Replies: 25
    Last Post: 06-12-2009, 01:33 PM
  2. Opening in full screen
    By MaGaIn in forum C++ Programming
    Replies: 14
    Last Post: 08-21-2007, 11:12 AM
  3. Full Screen
    By Rainer in forum C++ Programming
    Replies: 4
    Last Post: 08-08-2003, 05:56 AM
  4. !!!!!!Full screen!!!!!
    By Lukas in forum C++ Programming
    Replies: 2
    Last Post: 03-19-2003, 03:43 AM
  5. Full Screen
    By JamMan in forum C++ Programming
    Replies: 3
    Last Post: 11-21-2001, 02:10 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21