Menu

Getting screen dimensions in windows

Eric Davis
2009-01-09
2012-09-26
  • Eric Davis

    Eric Davis - 2009-01-09

    Simply put, I'm trying to get the X and Y dimensions of my screen. I tried the below source, but the GetViewportExtEx() function only loads a 1 into both cx and cy. It looks as though it should work, but doesn't.

    ////////////////////////////////////////////////////////////

    HDC hToScreenDC;
    SIZE screensize;
    long x, y;

    hToWindowDC = GetDC(NULL);
    GetViewportExtEx(hToScreenDC, &screensize)

    x = screensize.cx;
    y = screensize.cy;

    ReleaseDC(NULL, hToScreenDC);

    /////////////////////////////////////////////////////////////

    All I want to do is center my application window on the screen. I'm very curious as to why this isn't working. Any help would be appreciated. Thanx

     
    • Eric Davis

      Eric Davis - 2009-01-09

      I made an error while typing this. The problem still persists. Ignore the above typo

      ////////////////////////////////////////////////////////////

      HDC hToScreenDC;
      SIZE screensize;
      long x, y;

      //////////////////////////////////////
      hToScreenDC = GetDC(NULL);
      //////////////////////////////////////

      GetViewportExtEx(hToScreenDC, &screensize)

      x = screensize.cx;
      y = screensize.cy;

      ReleaseDC(NULL, hToScreenDC);

      /////////////////////////////////////////////////////////////

       
    • Eric Davis

      Eric Davis - 2009-01-09

      Got it!

      // width
      int cx = GetSystemMetrics(SM_CXSCREEN);
      // height
      int cy = GetSystemMetrics(SM_CYSCREEN);

      I'm still curious why GetViewportExtEx() was returning only 1 has the X and Y dimension.

       

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.