📄 saprefsdialog.cpp
字号:
m_nMaxSize.cx = max.cx;
if(max.cy>m_nMaxSize.cy)
m_nMaxSize.cy = max.cy;
}
*/
pageStruct *pPS = new pageStruct;
pPS->pDlg = &dlg;
pPS->id = dlg.GetID();
pPS->csCaption = pCaption;
pPS->pDlgParent = pDlgParent;
m_pages.Add(pPS);
return true;
}
/////////////////////////////////////////////////////////////////////////////
BOOL CSAPrefsDialog::PreCreateWindow(CREATESTRUCT& cs)
{
if (!CWnd::PreCreateWindow(cs))
return FALSE;
cs.lpszClass = AfxRegisterWndClass(CS_DBLCLKS, NULL, NULL, NULL);
cs.style |= WS_CLIPCHILDREN;
return TRUE;
}
/////////////////////////////////////////////////////////////////////////////
bool CSAPrefsDialog::ShowPage(CSAPrefsSubDlg * pPage)
{
// find that page
for (int i=0;i<m_pages.GetSize();i++)
{
pageStruct *pPS = (pageStruct *)m_pages.GetAt(i);
ASSERT(pPS);
if (pPS)
{
ASSERT(pPS->pDlg);
if (pPS->pDlg == pPage)
{
ShowPage(i);
m_iCurPage = i;
return true;
}
}
}
return false;
}
/////////////////////////////////////////////////////////////////////////////
bool CSAPrefsDialog::ShowPage(int iPage)
{
m_captionBar.SetWindowText("");
// turn off the current page
if ((m_iCurPage >= 0) && (m_iCurPage < m_pages.GetSize()))
{
pageStruct *pPS = (pageStruct *)m_pages.GetAt(m_iCurPage);
ASSERT(pPS);
if (pPS)
{
ASSERT(pPS->pDlg);
if (pPS->pDlg)
{
if (::IsWindow(pPS->pDlg->m_hWnd))
{
pPS->pDlg->ShowWindow(SW_HIDE);
}
}
}
else
{
return false;
}
}
// show the new one
if ((iPage >= 0) && (iPage < m_pages.GetSize()))
{
pageStruct *pPS = (pageStruct *)m_pages.GetAt(iPage);
ASSERT(pPS);
if (pPS)
{
ASSERT(pPS->pDlg);
if (pPS->pDlg)
{
// update caption bar
m_captionBar.SetWindowText(pPS->csCaption);
// if we haven't already, Create the dialog
if (!::IsWindow(pPS->pDlg->m_hWnd))
{
pPS->pDlg->Create(pPS->pDlg->GetID(), this);
}
// move, show, focus
if (::IsWindow(pPS->pDlg->m_hWnd))
{
CRect rcRest(m_frameRect);
rcRest.DeflateRect(1,1,1,1);
pPS->pDlg->MoveWindow(rcRest);
pPS->pDlg->ShowWindow(SW_SHOW);
pPS->pDlg->SetFocus();
}
// change the tree
// find this in our map
HTREEITEM hItem = FindHTREEItemForDlg(pPS->pDlg);
if (hItem)
{
// select it
m_pageTree.SelectItem(hItem);
}
return true;
}
}
}
return false;
}
/////////////////////////////////////////////////////////////////////////////
void CSAPrefsDialog::OnOK()
{
// if EndOK returns true, all of the UpdateData(TRUE)'s succeeded
if (EndOK())
{
CDialog::OnOK();
}
}
/////////////////////////////////////////////////////////////////////////////
bool CSAPrefsDialog::EndOK()
{
bool bOK = true;
CSAPrefsSubDlg * pPage = NULL;
// first, UpdateData...
for (int i=0;i<m_pages.GetSize();i++)
{
pageStruct *pPS = (pageStruct *)m_pages.GetAt(i);
ASSERT(pPS);
if (pPS)
{
ASSERT(pPS->pDlg);
if (pPS->pDlg)
{
if (::IsWindow(pPS->pDlg->m_hWnd))
{
if (!pPS->pDlg->UpdateData(TRUE))
{
bOK = false;
pPage = pPS->pDlg;
break;
}
}
}
}
}
// were there any UpdateData errors?
if ((!bOK) && (pPage!=NULL))
{
ShowPage(pPage);
return false;
}
// tell all of the sub-dialogs "OK"
for (i=0;i<m_pages.GetSize();i++)
{
pageStruct *pPS = (pageStruct *)m_pages.GetAt(i);
ASSERT(pPS);
if (pPS)
{
ASSERT(pPS->pDlg);
if (pPS->pDlg)
{
if (::IsWindow(pPS->pDlg->m_hWnd))
{
pPS->pDlg->OnOK();
}
}
}
}
return true;
}
/////////////////////////////////////////////////////////////////////////////
void CSAPrefsDialog::OnCancel()
{
// tell all of the sub-dialogs "Cancel"
for (int i=0;i<m_pages.GetSize();i++)
{
pageStruct *pPS = (pageStruct *)m_pages.GetAt(i);
ASSERT(pPS);
if (pPS)
{
ASSERT(pPS->pDlg);
if (pPS->pDlg)
{
if (::IsWindow(pPS->pDlg->m_hWnd))
{
pPS->pDlg->OnCancel();
}
}
}
}
CDialog::OnCancel();
}
/////////////////////////////////////////////////////////////////////////////
void CSAPrefsDialog::EndSpecial(UINT res, bool bOk)
{
if (bOk)
{
EndOK();
}
EndDialog(res);
}
/////////////////////////////////////////////////////////////////////////////
void CSAPrefsDialog::OnSelchangingPageTree(NMHDR* pNMHDR, LRESULT* pResult)
{
NM_TREEVIEW* pNMTreeView = (NM_TREEVIEW*)pNMHDR;
// do we need to validate this page?
if (m_bValidateBeforeChangingPage)
{
// is the current page a real page?
if ((m_iCurPage >= 0) && (m_iCurPage < m_pages.GetSize()))
{
pageStruct *pPS = (pageStruct *)m_pages.GetAt(m_iCurPage);
if (pPS)
{
ASSERT(pPS->pDlg);
if (pPS->pDlg)
{
if (::IsWindow(pPS->pDlg->m_hWnd))
{
// now we know we have a valid window. let's see if the data on it is OK
if (!pPS->pDlg->UpdateData())
{
// bad data!
// when we leave here, the tree wil grab focus again.
// this is bad, because we want the control that cause the UpdateData
// to fail to have focus (so the user knows what to fix). so, we'll
// do some trickery...
// find out who has focus
CWnd *pLost = pPS->pDlg->GetFocus();
if (pLost)
{
// post a message back to this window with the HWND of the
// window that had focus (the one that broke the UpdateData).
// the handler for WM_SET_FOCUS_WND will set the focus back to
// that control
PostMessage(WM_SET_FOCUS_WND, (UINT)pLost->m_hWnd);
}
// don't switch pages
*pResult = 1;
return;
}
// if we're here, the dialog validated OK. we can switch pages.
}
}
}
}
}
// ok to switch pages
*pResult = 0;
}
/////////////////////////////////////////////////////////////////////////////
void CSAPrefsDialog::OnSelchangedPageTree(NMHDR* pNMHDR, LRESULT* pResult)
{
NM_TREEVIEW* pNMTreeView = (NM_TREEVIEW*)pNMHDR;
if (pNMTreeView->itemNew.lParam)
{
// find out which page was selected
int iIdx = -1;
for (int i=0;i<m_pages.GetSize();i++)
{
if (m_pages.GetAt(i)==(pageStruct *)pNMTreeView->itemNew.lParam)
{
iIdx = i;
break;
}
}
// show that page
if ((iIdx >= 0) && (iIdx < m_pages.GetSize()))
{
pageStruct *pPS = (pageStruct *)m_pages.GetAt(iIdx);
if (m_iCurPage!=iIdx)
{
PostMessage(WM_CHANGE_PAGE, iIdx);
}
}
}
*pResult = 0;
}
/////////////////////////////////////////////////////////////////////////////
void CSAPrefsDialog::OnGetdispinfoPageTree(NMHDR* pNMHDR, LRESULT* pResult)
{
TV_DISPINFO* pTVDispInfo = (TV_DISPINFO*)pNMHDR;
// return the caption of the appropriate dialog
if (pTVDispInfo->item.lParam)
{
if (pTVDispInfo->item.mask & TVIF_TEXT)
{
pageStruct *pPS = (pageStruct *)pTVDispInfo->item.lParam;
strcpy(pTVDispInfo->item.pszText, pPS->csCaption);
}
}
*pResult = 0;
}
/////////////////////////////////////////////////////////////////////////////
void CSAPrefsDialog::OnPhelp()
{
// simulate the property sheet method of sending Help (with WM_NOTIFY)
if ((m_iCurPage >= 0) && (m_iCurPage < m_pages.GetSize()))
{
pageStruct *pPS = (pageStruct *)m_pages.GetAt(m_iCurPage);
ASSERT(pPS);
ASSERT(pPS->pDlg);
if (pPS)
{
if (pPS->pDlg)
{
if (::IsWindow(pPS->pDlg->m_hWnd))
{
// help!
NMHDR nm;
nm.code=PSN_HELP;
nm.hwndFrom=m_hWnd;
nm.idFrom=CSAPrefsDialog::IDD;
pPS->pDlg->SendMessage(WM_NOTIFY, 0, (long)&nm);
}
}
}
}
}
/////////////////////////////////////////////////////////////////////////////
LONG CSAPrefsDialog::OnChangePage(UINT u, LONG l)
{
if (ShowPage(u))
{
m_iCurPage = u;
}
return 0L;
}
/////////////////////////////////////////////////////////////////////////////
LONG CSAPrefsDialog::OnSetFocusWnd(UINT u, LONG l)
{
if (::IsWindow((HWND)u))
{
::SetFocus((HWND)u);
}
return 0L;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -