C++ 如何在CPropertySheet中重新排序CPropertyPage
我们有一个CPropertySheet,里面有5个CPropertyPage 假设我们有这样的东西 123445 然后,根据一些业务逻辑,当用户单击refresh时,我们希望 1 5 2 3 4 我们不想删除所有CPropertyPage并以正确的顺序重新创建它们(使用C++ 如何在CPropertySheet中重新排序CPropertyPage,c++,mfc,cpropertysheet,C++,Mfc,Cpropertysheet,我们有一个CPropertySheet,里面有5个CPropertyPage 假设我们有这样的东西 123445 然后,根据一些业务逻辑,当用户单击refresh时,我们希望 1 5 2 3 4 我们不想删除所有CPropertyPage并以正确的顺序重新创建它们(使用AddPage()),我们只想更新页面在工作表中的位置 这可能吗 谢谢 Microsoft的MFC CPropertySheet没有执行此操作的功能,但是,如果选中,可以通过删除要移动的页面,然后将其插入所需位置来实现类似的操作
AddPage()
),我们只想更新页面在工作表中的位置
这可能吗
谢谢 Microsoft的MFC CPropertySheet没有执行此操作的功能,但是,如果选中,可以通过删除要移动的页面,然后将其插入所需位置来实现类似的操作
pPropertySheet->RemovePage(pPageToAdd);
pPropertySheet->InsertPageAt(pPageToAdd, nIndex);
为此,您首先需要子类CPropertySheet,并添加一个函数以按给定顺序插入页面:
//In the .h of your subclass
//Inserts the page at a given Index
void InsertPageAt(CPropertyPage* pPageToInsert, int nPos);
//In the .cpp file
void CPropertySheetControleur::InsertPageAt(CPropertyPage* pPage, int nPos)
{
ASSERT_VALID(this);
ENSURE_VALID(pPage);
ASSERT_KINDOF(CPropertyPage, pPage);
// add page to internal list
m_pages.InsertAt(nPos, pPage);
// add page externally
if (m_hWnd != NULL)
{
// determine size of PROPSHEETPAGE array
PROPSHEETPAGE* ppsp = const_cast<PROPSHEETPAGE*>(m_psh.ppsp);
int nBytes = 0;
int nNextBytes;
for (UINT i = 0; i < m_psh.nPages; i++)
{
nNextBytes = nBytes + ppsp->dwSize;
if ((nNextBytes < nBytes) || (nNextBytes < (int)ppsp->dwSize))
AfxThrowMemoryException();
nBytes = nNextBytes;
(BYTE*&)ppsp += ppsp->dwSize;
}
nNextBytes = nBytes + pPage->m_psp.dwSize;
if ((nNextBytes < nBytes) || (nNextBytes < (int)pPage->m_psp.dwSize))
AfxThrowMemoryException();
// build new prop page array
ppsp = (PROPSHEETPAGE*)realloc((void*)m_psh.ppsp, nNextBytes);
if (ppsp == NULL)
AfxThrowMemoryException();
m_psh.ppsp = ppsp;
// copy processed PROPSHEETPAGE struct to end
(BYTE*&)ppsp += nBytes;
Checked::memcpy_s(ppsp, nNextBytes - nBytes , &pPage->m_psp, pPage->m_psp.dwSize);
pPage->PreProcessPageTemplate(*ppsp, IsWizard());
if (!pPage->m_strHeaderTitle.IsEmpty())
{
ppsp->pszHeaderTitle = pPage->m_strHeaderTitle;
ppsp->dwFlags |= PSP_USEHEADERTITLE;
}
if (!pPage->m_strHeaderSubTitle.IsEmpty())
{
ppsp->pszHeaderSubTitle = pPage->m_strHeaderSubTitle;
ppsp->dwFlags |= PSP_USEHEADERSUBTITLE;
}
HPROPSHEETPAGE hPSP = AfxCreatePropertySheetPage(ppsp);
if (hPSP == NULL)
AfxThrowMemoryException();
if (!SendMessage(PSM_INSERTPAGE, nPos, (LPARAM)hPSP))
{
AfxDestroyPropertySheetPage(hPSP);
AfxThrowMemoryException();
}
++m_psh.nPages;
}
}