如何确定应用程序正在使用哪个监视器以及如何处理它? [英] How to determine which monitor an application is using and how to get a handle to it?

查看:25
本文介绍了如何确定应用程序正在使用哪个监视器以及如何处理它?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在做一个从主窗口调用另一个窗口的应用程序.我的问题是如何确定主应用程序窗口位于哪个监视器(如果有 2 个或更多)以及如何获得该监视器的句柄?到目前为止,我的代码如下所示:

I'm doing an application that is invoking another window from the main one. My question is how to determine on which monitor (in case there are 2 or more) the main application window is and how to get a handle to that monitor? So far my code looks like this:

RECT desktop;
const HWND hDesktop = GetDesktopWindow();
GetWindowRect( hDesktop, &desktop );

int width = SInt32( desktop.right / 2 );
int height = SInt32( desktop.bottom / 2 );

OpenNewWindow( width, height );

但这只是获取桌面(主显示器)的句柄,右侧和底部是主显示器的分辨率大小.我在 C++ 上写这个谢谢!

But this is only getting the handle to the desktop (the main monitor) and right and bottom are the resolution sizes of the main monitor. I'm writing this on C++ Thank you!

推荐答案

我找到了解决方案:

        HMONITOR currentMonitor = MonitorFromWindow( GetActiveWindow(), MONITOR_DEFAULTTONEAREST );
        MONITORINFO activeMonitorInfo;
        activeMonitorInfo.cbSize = sizeof( MONITORINFO );
        GetMonitorInfo( currentMonitor, (LPMONITORINFO) &activeMonitorInfo );

        int width = SInt32( ( activeMonitorInfo.rcMonitor.right - activeMonitorInfo.rcMonitor.left ) * 0.75 );
        int height = SInt32( ( activeMonitorInfo.rcMonitor.bottom - activeMonitorInfo.rcMonitor.top ) * 0.75 );

        OpenNewWIndow( width, height );

碰巧 GetActiveWindow 返回当前活动窗口的句柄,其余的很容易.

It happens that GetActiveWindow returns a handle to the current active window and the rest is easy.

这篇关于如何确定应用程序正在使用哪个监视器以及如何处理它?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆