• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 612
  • Last Modified:

center window in current monitor

We are attempting to add minimal multi monitor support to our application. We have some windows that either are centered in our application, centered in the monitor, or take up the whole monitor.  I can get the position of our window in the secondary(or more) monitor, but I am not sure how to determine what offset to use for centering our window in the monitor.  I can fudge it by using GetWindowRect(GetDesktopWindow(),&rectDesktop); but that doesnt take into account different resolutions on different monitors.  Ideally there should be a way to get the the x,y of top left and bottom right of the monitor a window is in.  Our application needs to run on Win95,NT, and above although the multi monitor support does not need to function in 95/NT so I cannot imlicitly link with User32.lib and use GetMonitorInfor(), etc.
0
PhilC
Asked:
PhilC
1 Solution
 
softplusCommented:
Why not just check the operating system and use GetMonitorInfo if it's available otherwise ignore it? I do this for lots of things (Printing, GDI, etc.). That way you have the best of both worlds - compatible + modern :)
John
0
 
PhilCAuthor Commented:
man was I wayyy over thinking this....example on MSDN "Positioning Objects on a Multiple Display Setup"...lol
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/gdi/monitor_9t0w.asp
thank you
0
 
KurtVonCommented:
Actually, you can link implicitly.  The link to the DLL is not created until the first call that needs it, so if you just make sure never to call the multi-monitor functions on Win95 then you will have no problems.  And yes, I do have a program that does just this.  Here's the function to tell if multimon is supported:

        OSVERSIONINFO version;
        version.dwOSVersionInfoSize = sizeof(version);
        GetVersionEx (&version);
        if ( // Check for NT
            ((version.dwPlatformId == VER_PLATFORM_WIN32_NT) &&
             (version.dwMajorVersion <= 4)) ||
            // Check for Win95
            ((version.dwPlatformId == VER_PLATFORM_WIN32_WINDOWS) &&
             (version.dwMajorVersion == 4) &&
             (version.dwMinorVersion == 0))
           )
            m_bMultimon = false;
        else
            m_bMultimon = true;

Hope this helps.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now