CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 6 of 6
  1. #1
    Join Date
    Jul 2005
    Posts
    3

    Detecting Screen Resolution

    Hello, I'm new here, but I've been programming for a couple of years now. Frequently I do a Google search for pieces of code that I need for programs that I write, and frequently CodeGuruForums have been helpful! So I figure I could start asking directly, since apparently the question hadn't been recently answered.

    I need a way to detect the resolution of the screen that my program is running on (800x600,1024x768, etc.).

    It would be all I need to complete this need little program that I'm writing: I'll post it (or email or something), if you can help me finish it.

  2. #2
    Join Date
    May 2005
    Location
    United States
    Posts
    526

    Re: Detecting Screen Resolution

    Call GetSystemMetrics() with SM_CXSCREEN and SM_CYSCREEN to obtain the width and height of the screen in pixels, respectively.

  3. #3
    Join Date
    Jul 2005
    Posts
    3

    Re: Detecting Screen Resolution

    Thanks!
    I had seen that before, but I don't think I was doing it correctly. The MSDN website made it clear, and for whatever reason it works now.
    I'll attach a compiled copy of my program when I finish it.

  4. #4
    Join Date
    Mar 2004
    Location
    (Upper-) Austria
    Posts
    2,899

    Re: Detecting Screen Resolution

    Quote Originally Posted by Greenfish
    Thanks!
    I had seen that before, but I don't think I was doing it correctly. The MSDN website made it clear, and for whatever reason it works now.
    I'll attach a compiled copy of my program when I finish it.
    You don't need/have to attach a compiled copy of your program. Posting the solution is more helpful, because anyone else who expierience the same problem in future can get help from this thread.
    I am not offering technical guidiance via email or IM
    Come on share your photo with us! CG members photo album!
    Use the Code Tags!

  5. #5
    Join Date
    Jul 2005
    Posts
    3

    Re: Detecting Screen Resolution

    Well, the simple solution was just that:

    int cx = GetSystemMetrics(SM_CXSCREEN)/2;
    int cy = GetSystemMetrics(SM_CXSCREEN)/2;

    The rest of my code, is a little sloppy (I'm used to a different type of C++ compiler) and doesn't have much to do with my question - other than using those variables for the center of the screen. Posting the compiled copy was a sort of reward (for whoever wanted it), to see what they helped create. But if they have the source code, then they can view it or compile it, so I'll just post the source code.
    Attached Files Attached Files

  6. #6
    Join Date
    Nov 2003
    Location
    Belgium
    Posts
    8,150

    Re: Detecting Screen Resolution

    Quote Originally Posted by Greenfish
    Well, the simple solution was just that:

    int cx = GetSystemMetrics(SM_CXSCREEN)/2;
    int cy = GetSystemMetrics(SM_CXSCREEN)/2;
    I think you mean:
    Code:
    int cx = GetSystemMetrics(SM_CXSCREEN)/2;
    int cy = GetSystemMetrics(SM_CYSCREEN)/2;
    NOTE: The above calls will return the size of the primary display on your system. If you need the dimensions of the virtual screen (combining all your monitors), you can use SM_CXVIRTUALSCREEN and SM_CYVIRTUALSCREEN.
    Marc Gregoire - NuonSoft (http://www.nuonsoft.com)
    My Blog
    Wallpaper Cycler 3.5.0.97

    Author of Professional C++, 4th Edition by Wiley/Wrox (includes C++17 features)
    ISBN: 978-1-119-42130-6
    [ http://www.facebook.com/professionalcpp ]

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured