MFC文檔/視圖體系結構,sdi(更確切地說是多個頂級窗口)。在我的視圖類中,我使用SetScrollSizes()設置了我的「操場」(即邏輯空間)。然後我想限制最大幀窗口大小到視圖的最大大小。如何根據視圖的大小限制框架大小? MFC文檔/視圖體系結構
下面是我在做什麼,但我覺得可能是更好的解決方案,請諮詢:
我在我的CMainFrame實施OnGetMinMaxInfo()。在那裏,我嘗試獲得活動視圖的滾動大小,並適當地設置lpMMI-> ptMaxTrackSize。下面是代碼:
void CMainFrame::OnGetMinMaxInfo(MINMAXINFO* lpMMI)
{
// Call base version:
CFrameWndEx::OnGetMinMaxInfo(lpMMI);
// Get active view:
CScrollView *pScrollView = (CScrollView *)GetActiveView();
if (pScrollView && pScrollView->IsKindOf(RUNTIME_CLASS(CMyFckinView)))
{
// Get total size of playground:
CSize sizePlayground = pScrollView->GetTotalSize();
// Test if the size is non-zero, i.e. there is at least one node displayed:
if (sizePlayground.cx && sizePlayground.cy/* && !IsPrintPreview()*/)
{
// Set maximum window size to match our playground size:
CRect rectClient, rectWindow;
pScrollView->GetClientRect(&rectClient);
this->GetWindowRect(&rectWindow);
if (rectWindow.top > -5000 && rectWindow.left > -5000) // Avoid when minimized...
{
lpMMI->ptMaxTrackSize.x = sizePlayground.cx + (rectWindow.Width() - rectClient.Width());
lpMMI->ptMaxTrackSize.y = sizePlayground.cy + (rectWindow.Height() - rectClient.Height());
return;
}
}
}
}
這工作,但有一個問題:當顯示打印預覽(標準MFC打印預覽),我當然希望能夠自由調整窗口大小,所以我使用運行時信息GetActiveView() - > IsKindOf(...)確定活動視圖實際上是我的視圖,而不是打印預覽的視圖(即CPreviewViewEx)。但是當我關閉打印預覽時,OnGetMinMaxInfo沒有被調用,所以我無法再根據我的視圖調整幀大小。一旦我移動窗口OnGetMinMaxInfo被再次調用,並正確調整幀大小,但不需要手動移動窗口舊大小(打印預覽的大小)保留,並具有醜陋的工件。
我該怎麼辦?基本上,如果我可以捕獲的那一刻時,打印預覽關閉時,我可以使用下面的技巧:
// Trigger the WM_MINMAXINFO message:
CFrameWnd *pFrame = GetParentFrame();
RECT rectWindow;
pFrame->GetWindowRect(&rectWindow);
pFrame->MoveWindow(&rectWindow);
但我不知道如何捕獲打印預覽關閉。
我想要完成的事情似乎很標準:誰會希望將窗口窗口調整大於視圖的邏輯大小(由SetScrollSizes()設置)?所以應該有更自然的解決方案呢?
從我的視圖的OnSize處理程序觸發WM_MINMAXINFO框與MoveWindow做了竅門。 –