【问题标题】:How to determine which monitor an application is using and how to get a handle to it?如何确定应用程序正在使用哪个监视器以及如何获取它的句柄?
【发布时间】:2016-08-10 13:48:18
【问题描述】:

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

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++ 上写这个 谢谢!

【问题讨论】:

标签: c++ windows


【解决方案1】:

我找到了解决方案:

        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 会返回当前活动窗口的句柄,剩下的就很简单了。

【讨论】:

  • 为什么 * 0.75 表示宽度和高度?
  • 我想打开那个大小的新窗口。您可以根据需要更改值。
猜你喜欢
  • 2014-05-25
  • 1970-01-01
  • 2012-08-30
  • 2014-11-27
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多