然后,我将它添加到源文件:
cwnd*cresizingmfcPropertySheet::initNavigationControl())
{
m_pnavigationControl=cmfcPropertySheet::InitNavigationControl();
返回m_pnavigationcontrol;
}
最后,我调整了
void cresizingmfcropertySheet::onSize(uint类型,int cx,int cy)
{
cmfcpropertysheet::onSize(类型,cx,cy);
如果(!getActivePage())返回;
如果(!gettabControl())返回;
if(类型==SIZE_minimized)
返回;
int dx=cx-save_rc.width();
int dy=cy-save_rc.height();
int计数=0;
对于(cwnd*child=getwindow(gw_child);child;child=child->getwindow(gw_hwndnext))
计数++;
hdwp hdwp=::BeginDeferWindowPos(计数);
对于(cwnd*child=getwindow(gw_child);child;child=child->getwindow(gw_hwndnext))
{
布尔移动=假;
//如果手动添加子控件,则要移动而不是调整大小
如果(child=&m&u lblResize&m&u lblResize.getSafeHwnd()!=空指针)
移动=真;
正确的R;
子级->GetWindowRect(&r);
屏幕客户端(&r);
if(move child->sendmessage(wm_getdlgcode)&dlgc_按钮)
{
//移动主按钮和子控件
R.左+=dx;
r.top+=dy;
::延迟窗口位置(hdwp,child->m_hwnd,0,r.left,r.top,0,0,
swp_nosize_swp_nozorder_swp_noactivate);
}
其他的
{
if(child->getSafeHwnd()==m_pnAvigationControl->getSafeHwnd())
{
r.底部+=dy;
::延迟窗口位置(hdwp,child->m_hwnd,nullptr,
R.Left,R.Top,R.Width(),R.Height(),
swp_nomove_swp_u nozorder_swp_noactivate);
}
其他的
{
//这必须是子窗口,请调整其大小
R.RIGHT+=dx;
r.底部+=dy;
::延迟窗口位置(hdwp,child->m_hwnd,0,0,0,r.width(),r.height(),
swp_nomove_swp_u nozorder_swp_noactivate);
}
}
}
::结束延迟窗口位置(hdwp);
getclientrect(&save_rc);
无效(真);
}
如您所见,我们能够针对导航控件的处理程序进行测试。结果是:
然后,我将它添加到源文件中:
CWnd* CResizingMFCPropertySheet::InitNavigationControl()
{
m_pNavigationControl = CMFCPropertySheet::InitNavigationControl();
return m_pNavigationControl;
}
最后,我调整了OnSize
方法:
void CResizingMFCPropertySheet::OnSize(UINT nType, int cx, int cy)
{
CMFCPropertySheet::OnSize(nType, cx, cy);
if (!GetActivePage()) return;
if (!GetTabControl()) return;
if (nType == SIZE_MINIMIZED)
return;
int dx = cx - save_rc.Width();
int dy = cy - save_rc.Height();
int count = 0;
for (CWnd *child = GetWindow(GW_CHILD); child; child = child->GetWindow(GW_HWNDNEXT))
count++;
HDWP hDWP = ::BeginDeferWindowPos(count);
for (CWnd *child = GetWindow(GW_CHILD); child; child = child->GetWindow(GW_HWNDNEXT))
{
bool move = false;
//If you add child controls manually, you want to move not resize
if(child == &m_lblResize && m_lblResize.GetSafeHwnd() != nullptr)
move = true;
CRect r;
child->GetWindowRect(&r);
ScreenToClient(&r);
if (move || child->SendMessage(WM_GETDLGCODE) & DLGC_BUTTON)
{
//move the main buttons and the child controls
r.left += dx;
r.top += dy;
::DeferWindowPos(hDWP, child->m_hWnd, 0, r.left, r.top, 0, 0,
SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE);
}
else
{
if (child->GetSafeHwnd() == m_pNavigationControl->GetSafeHwnd())
{
r.bottom += dy;
::DeferWindowPos(hDWP, child->m_hWnd, nullptr,
r.left, r.top, r.Width(), r.Height(),
SWP_NOMOVE | SWP_NOZORDER | SWP_NOACTIVATE);
}
else
{
//this must be a child window, resize it
r.right += dx;
r.bottom += dy;
::DeferWindowPos(hDWP, child->m_hWnd, 0, 0, 0, r.Width(), r.Height(),
SWP_NOMOVE | SWP_NOZORDER | SWP_NOACTIVATE);
}
}
}
::EndDeferWindowPos(hDWP);
GetClientRect(&save_rc);
Invalidate(TRUE);
}
如您所见,我们能够针对导航控件的处理程序进行测试。结果是: