The following Code maximises a dialog on the second screen.
The code is available for download:
void DlgSecondScreen::ResizeDialog(const CRect newRect) { // Resize Dialog SetWindowPos(&CWnd::wndTop, newRect.left, newRect.top, newRect.right, newRect.bottom, SWP_SHOWWINDOW | // Displays the window. SWP_NOCOPYBITS // Do NOT Save content ); } void DlgSecondScreen::MaximizeOnSecondScreen(const HWND hWndParent) { HMONITOR hMonPrim = MonitorFromWindow(hWndParent,MONITOR_DEFAULTTOPRIMARY); HMONITOR hMonSecond = MonitorFromWindow(hWndParent,MONITOR_DEFAULTTONEAREST); MONITORINFO MonitorInfo; MonitorInfo.cbSize = sizeof(MonitorInfo); // Rect of Current Monitor ::GetMonitorInfo(hMonPrim,&MonitorInfo); CRect Rect = MonitorInfo.rcMonitor; // Rect of Second Monitor ::GetMonitorInfo(hMonSecond,&MonitorInfo); CRect RectSecond = MonitorInfo.rcMonitor; // New Rect with second monitor Rect.left = Rect.Width() + 1; Rect.right = Rect.left + RectSecond.Width(); Rect.bottom = RectSecond.Height(); ResizeDialog(Rect); } |
call by the parent dialog with
void CDrawOnSecondScreenDlg::OnBnClickedButtonShow() { if (theApp.m_pDlgSecondScreen != NULL) { theApp.m_pDlgSecondScreen->SetForegroundWindow(); theApp.m_pDlgSecondScreen->SetFocus(); } else { theApp.m_pDlgSecondScreen = new DlgSecondScreen; theApp.m_pDlgSecondScreen->Create(DlgSecondScreen::IDD); // Get handle of Monitor HWND hWndParent = ::GetParent(m_hWnd); theApp.m_pDlgSecondScreen->MaximizeOnSecondScreen(hWndParent); // Ausgabe initialisieren theApp.m_pDlgSecondScreen->ShowWindow(SW_SHOW); } } |