Link to home
Start Free TrialLog in
Avatar of PhilC
PhilC

asked on

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.
ASKER CERTIFIED SOLUTION
Avatar of softplus
softplus

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of PhilC
PhilC

ASKER

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
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.