调整大小 属性 sheet 正在影响外观栏尺寸
Resizing property sheet is affecting the outlook bar dimensions
这是我的 OnSize
调整大小的方法 属性 sheet:
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
{
//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);
}
但是,如果我像这样更改 属性 sheet 的外观:
SetIconsList(IDB_MAINT_DB_LARGE, 32);
SetLook(CMFCPropertySheet::PropSheetLook_OutlookBar);
然后我调整 属性 sheet:
我们如何调整 OnSize
以保留 outlook 栏宽度?我们只需要调整高度即可。
有这个 question 和相关的答案,但是 Microsoft 知识库文章的答案中的 link 不起作用。无论哪种方式,都需要自定义 OnSize
才能正确呈现 PropSheetLook_OutlookBar
。不知何故...
更新
根据 Spy 的说法,它是一个工具栏:
我做的第一件事就是将它添加到我的调整大小中 class header:
protected:
CWnd* InitNavigationControl() override;
private:
CWnd * m_pNavigationControl;
然后,我将这个添加到源文件中:
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);
}
如您所见,我们能够针对导航控件的处理程序进行测试。所以结果:
这是我的 OnSize
调整大小的方法 属性 sheet:
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
{
//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);
}
但是,如果我像这样更改 属性 sheet 的外观:
SetIconsList(IDB_MAINT_DB_LARGE, 32);
SetLook(CMFCPropertySheet::PropSheetLook_OutlookBar);
然后我调整 属性 sheet:
我们如何调整 OnSize
以保留 outlook 栏宽度?我们只需要调整高度即可。
有这个 question 和相关的答案,但是 Microsoft 知识库文章的答案中的 link 不起作用。无论哪种方式,都需要自定义 OnSize
才能正确呈现 PropSheetLook_OutlookBar
。不知何故...
更新
根据 Spy 的说法,它是一个工具栏:
我做的第一件事就是将它添加到我的调整大小中 class header:
protected:
CWnd* InitNavigationControl() override;
private:
CWnd * m_pNavigationControl;
然后,我将这个添加到源文件中:
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);
}
如您所见,我们能够针对导航控件的处理程序进行测试。所以结果: