使用动态布局使CMFCPropertySheet可调整大小 [英] Making a CMFCPropertySheet resizable with dynamic layouts
问题描述
我看到了这个问题,但是答案中的链接是不再有效.
I saw this question but the link in the answer is no longer valid.
我还找到了此.
I also found this which I tried and doesn't work and this.
我的任务应该很简单.我在CMFCPropertySheet
上有几页,我想利用IDE中新的动态调整大小功能.因此,我设置了控件和控件的大小,但是当它们显示在工作表中时,就无法调整工作表/页面的大小.
My task should be simple. I have several pages on a CMFCPropertySheet
and I want to take advantage of the new dynamic resizing features in the IDE. So I set the resizing of the controls and alas, when shown in a sheet there is no ability to resize the sheet/pages.
尝试上述资源失败.
CMyPropertySheet
的标题:
CMyPropertySheet
的来源:
为了进行测试,我刚刚创建了一个对话框应用程序,并添加了一个页面并将其分配给此工作表.
To test I just created a dialog application and added a page and assigned it to this sheet.
我只想支持使用属性表/页面进行动态调整大小.我缺少什么,实际上是否还需要任何这些代码?
I just want to support dynamic resizing with property sheets / pages. What am I missing and is any of this code actually needed any more?
推荐答案
对于无模式属性表:
看到这个SO链接
调整无模式属性表的大小
对于模态特性表:
如何实现可调整大小的属性表
https://www.codeproject. com/Tips/214744/如何实现可调整大小的属性表类
For modeless property sheet:
See this SO link
Resizing a modeless property sheet
For modal property sheet:
How to implement a resizable property sheet
https://www.codeproject.com/Tips/214744/How-to-implement-a-resizable-property-sheet-class
在属性表窗口中添加WS_THICKFRAME
样式.
Add WS_THICKFRAME
style to the property sheet window.
int CALLBACK XmnPropSheetCallback(HWND hWnd, UINT message, LPARAM lParam)
{
extern int CALLBACK AfxPropSheetCallback(HWND, UINT message, LPARAM lParam);
// XMN: Call MFC's callback
int nRes = AfxPropSheetCallback(hWnd, message, lParam);
switch(message)
{
case PSCB_PRECREATE:
// Set our own window styles
((LPDLGTEMPLATE)lParam)->style |= (DS_3DLOOK | DS_SETFONT
| WS_THICKFRAME | WS_SYSMENU | WS_POPUP | WS_VISIBLE | WS_CAPTION);
break;
}
return nRes;
}
INT_PTR CMyPropertySheet::DoModal()
{
// Hook into property sheet creation code
m_psh.dwFlags |= PSH_USECALLBACK;
m_psh.pfnCallback = XmnPropSheetCallback;
return CMFCPropertySheet::DoModal();
}
ps,原始文章有点旧.这将使用m_psh
访问属性表的参数.
ps, the original article is a little old. This uses m_psh
to access property sheet's parameters.
调整大小:
void CMyPropertySheet::OnSize(UINT nType, int cx, int cy)
{
CPropertySheet::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;
//override***
//If you add child controls manually, you want to move not resize
//if(child == &static_control)
//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);
}
BOOL CMyPropertySheet::OnInitDialog()
{
CPropertySheet::OnInitDialog();
GetClientRect(&save_rc);
GetClientRect(&minimum_rc);
return TRUE;
}
这篇关于使用动态布局使CMFCPropertySheet可调整大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!