2016-08-10 3 views
1

私は、メインウィンドウから別のウィンドウを呼び出すアプリケーションを実行しています。私の質問は、メインアプリケーションウィンドウがどのモニター(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++でこれを書いています ありがとう!

+1

[ウィンドウがどのモニターに表示されているかを知るにはどうすればいいですか?]を参照してください(http://stackoverflow.com/questions/2465646/how-do-i-know-what-monitor-a-wwff-window-is-in )。答えは 'MonitorFromWindow'です。 –

答えて

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

なぜ幅と高さが* 0.75ですか? – dk123

関連する問題