我正在开发一个从主窗口调用另一个窗口的应用程序。我的问题是如何确定主应用程序窗口位于哪个监视器(如果有 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++ 写这个 谢谢!
最佳答案
我找到了解决方案:
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 返回当前事件窗口的句柄,剩下的就很简单了。
关于c++ - 如何确定应用程序正在使用哪个监视器以及如何获取它的句柄?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38875313/