📄 tabctrldlg.cpp
字号:
case 1: // At the bottom
m_tab.ModifyStyle (TCS_VERTICAL, TCS_BOTTOM, TRUE);
dwStyle = m_tab.GetStyle();
dwStyleEx = m_tab.GetExStyle();
RecreateWindow (dwStyle, dwStyleEx);
AlignTabsAtBottom ();
m_StyleMultilineCtrl.EnableWindow(TRUE);
break;
case 2: // At the left
m_tab.ModifyStyle (TCS_BOTTOM, TCS_VERTICAL, TRUE);
dwStyle = m_tab.GetStyle();
dwStyleEx = m_tab.GetExStyle();
RecreateWindow (dwStyle, dwStyleEx);
AlignTabsAtLeft();
m_StyleMultiline = TRUE;
UpdateData (FALSE);
OnStyleMultiline ();
m_StyleMultilineCtrl.EnableWindow(FALSE);
break;
case 3: // At the right
m_tab.ModifyStyle (0, TCS_BOTTOM | TCS_VERTICAL, TRUE);
dwStyle = m_tab.GetStyle();
dwStyleEx = m_tab.GetExStyle();
RecreateWindow (dwStyle, dwStyleEx);
m_StyleMultiline = TRUE;
UpdateData (FALSE);
OnStyleMultiline ();
m_StyleMultilineCtrl.EnableWindow(FALSE);
AlignTabsAtRight();
break;
}
}
void CTabCtrlDlg::AlignTabsAtTop()
{
CRect r, rc;
int nRows = m_tab.GetRowCount ();
//
// Get the image area and resize all the controls
//
GetTabRects (r, rc);
if (nRows == 1)
rc.bottom = m_rcBase.bottom;
else
rc.bottom += (r.bottom - r.top) * (nRows - 1);
m_tab.MoveWindow (rc, TRUE);
CRect rcClient;
CRect rcTab;
rc = m_rcBase;
rc.top += (r.bottom - r.top) * nRows + 6;
rc.bottom += (r.bottom - r.top) * nRows - 30;
rc.left += 6;
rc.right -= 6;
m_list.MoveWindow (rc, TRUE);
m_edit.MoveWindow (rc, TRUE);
// m_tree.MoveWindow (rc, TRUE);
m_FirstPageControl->MoveWindow (rc, TRUE);
CPropertySheet *ps = STATIC_DOWNCAST(CPropertySheet, GetParent());
int nIndex = ps->GetPageIndex (this);
CRect rcPTab;
ps->GetTabControl()->GetItemRect (nIndex, rcPTab);
m_tab.GetWindowRect (rcClient);
ScreenToClient (rcClient);
rc.top += rcClient.top + rcPTab.bottom;
rc.left += 10;
rc.right += 10;
rc.bottom += 56;
m_tabtree.MoveWindow (rc, TRUE);
m_tabboxes.MoveWindow (rc, TRUE);
}
void CTabCtrlDlg::AlignTabsAtBottom()
{
CRect r, rc;
int nRows = m_tab.GetRowCount ();
//
// Get the image area and resize all the controls
//
GetTabRects (r, rc);
if (nRows == 1)
rc.bottom = m_rcBase.bottom;
else
rc.bottom = m_rcBase.bottom + (r.bottom - r.top) * (nRows - 1);
m_tab.MoveWindow (rc, TRUE);
rc.top += 6;
rc.bottom -= (r.bottom - r.top) * nRows + 10;
rc.left += 6;
rc.right -= 6;
m_list.MoveWindow (rc, TRUE);
m_edit.MoveWindow (rc, TRUE);
// m_tree.MoveWindow (rc, TRUE);
m_FirstPageControl->MoveWindow (rc, TRUE);
CPropertySheet *ps = STATIC_DOWNCAST(CPropertySheet, GetParent());
int nIndex = ps->GetPageIndex (this);
CRect rcPTab;
ps->GetTabControl()->GetItemRect (nIndex, rcPTab);
CRect rcClient;
m_tab.GetWindowRect (rcClient);
ScreenToClient (rcClient);
rc.top += rcClient.top + rcPTab.bottom;//42;
rc.left += 10;
rc.right += 10;
rc.bottom += rcPTab.bottom + r.Height();//56;
m_tabtree.MoveWindow (rc, TRUE);
m_tabboxes.MoveWindow (rc, TRUE);
}
void CTabCtrlDlg::AlignTabsAtLeft()
{
CRect r, rc;
int nRows = m_tab.GetRowCount ();
//
// Get the image area and resize all the controls
//
GetTabRects (r, rc);
m_tab.MoveWindow (rc, TRUE);
m_tab.MoveWindow (rc, TRUE);
rc.left += (r.right - r.left) * nRows + 6;
rc.top += 6;
rc.bottom -= 6;
rc.right -= 6;
m_list.MoveWindow (rc, TRUE);
m_edit.MoveWindow (rc, TRUE);
// m_tree.MoveWindow (rc, TRUE);
m_FirstPageControl->MoveWindow (rc, TRUE);
CPropertySheet *ps = STATIC_DOWNCAST(CPropertySheet, GetParent());
int nIndex = ps->GetPageIndex (this);
CRect rcPTab;
ps->GetTabControl()->GetItemRect (nIndex, rcPTab);
CRect rcClient;
m_tab.GetWindowRect (rcClient);
ScreenToClient (rcClient);
rc.top += rcClient.top + rcPTab.bottom;//42;
rc.left += 10;
rc.right += 10;
rc.bottom += 56;
m_tabtree.MoveWindow (rc, TRUE);
m_tabboxes.MoveWindow (rc, TRUE);
}
void CTabCtrlDlg::AlignTabsAtRight()
{
CRect r, rc;
int nRows = m_tab.GetRowCount ();
//
// Get the image area and resize all the controls
//
GetTabRects (r, rc);
m_tab.MoveWindow (rc, TRUE);
rc = m_rcBase;
m_tab.MoveWindow (rc, TRUE);
rc.right -= (r.right - r.left) * nRows + 6;
rc.top += 6;
rc.bottom -= 6;
rc.left += 6;
m_list.MoveWindow (rc, TRUE);
m_edit.MoveWindow (rc, TRUE);
// m_tree.MoveWindow (rc, TRUE);
m_FirstPageControl->MoveWindow (rc, TRUE);
CPropertySheet *ps = STATIC_DOWNCAST(CPropertySheet, GetParent());
int nIndex = ps->GetPageIndex (this);
CRect rcPTab;
ps->GetTabControl()->GetItemRect (nIndex, rcPTab);
CRect rcClient;
m_tab.GetWindowRect (rcClient);
ScreenToClient (rcClient);
rc.top += rcClient.top + rcPTab.bottom;//42;
rc.left += 10;
rc.right += 10;
rc.bottom += 56;
m_tabtree.MoveWindow (rc, TRUE);
m_tabboxes.MoveWindow (rc, TRUE);
}
void CTabCtrlDlg::OnAlignFixedwidth()
{
m_tab.ModifyStyle (TCS_RAGGEDRIGHT, TCS_FIXEDWIDTH, TRUE);
RecreateWindow (m_tab.GetStyle(), m_tab.GetExStyle ());
switch (m_TabsLocation)
{
case 0: // At the top
AlignTabsAtTop();
break;
case 1: // At the bottom
AlignTabsAtBottom ();
break;
case 2: // At the left
AlignTabsAtLeft();
break;
case 3: // At the right
AlignTabsAtRight();
break;
}
}
void CTabCtrlDlg::OnAlignRightjustify()
{
m_tab.ModifyStyle (TCS_RAGGEDRIGHT | TCS_FIXEDWIDTH, 0, TRUE);
RecreateWindow (m_tab.GetStyle(), m_tab.GetExStyle ());
switch (m_TabsLocation)
{
case 0: // At the top
AlignTabsAtTop();
break;
case 1: // At the bottom
AlignTabsAtBottom ();
break;
case 2: // At the left
AlignTabsAtLeft();
break;
case 3: // At the right
AlignTabsAtRight();
break;
}
}
void CTabCtrlDlg::OnAlignRaggedright()
{
m_tab.ModifyStyle (TCS_FIXEDWIDTH, TCS_RAGGEDRIGHT, TRUE);
RecreateWindow (m_tab.GetStyle(), m_tab.GetExStyle ());
switch (m_TabsLocation)
{
case 0: // At the top
AlignTabsAtTop();
break;
case 1: // At the bottom
AlignTabsAtBottom ();
break;
case 2: // At the left
AlignTabsAtLeft();
break;
case 3: // At the right
AlignTabsAtRight();
break;
}
}
void CTabCtrlDlg::RecreateWindow(DWORD dwStyle, DWORD dwStyleEx)
{
TC_ITEM ti;
UpdateData (TRUE);
CWnd *parent;
int nSel = m_tab.GetCurSel ();
ti.mask = TCIF_PARAM | TCIF_IMAGE;
m_tab.GetItem (nSel, &ti);
CWnd *cDlg = (CWnd *) ti.lParam;
if (cDlg != NULL)
cDlg->ShowWindow (SW_HIDE);
CRect rc;
m_tab.GetWindowRect (rc);
DeleteTabItems ();
parent = m_tab.GetParent();
m_tab.DestroyWindow ();
m_tab.Create (dwStyle, rc, parent, IDC_TABCTRL_SAMPLETAB);
m_tab.ShowWindow (SW_SHOWDEFAULT);
if (m_StyleMultiline == TRUE)
{
m_tab.ModifyStyle (TCS_SINGLELINE, TCS_MULTILINE, TRUE);
}
else
{
m_tab.ModifyStyle (TCS_MULTILINE, TCS_SINGLELINE, TRUE);
}
CFont* font = GetFont ();
m_tab.SetFont (font);
m_tab.SetImageList (&m_Images);
AddTabItems ();
m_tab.SetCurSel (nSel);
if (cDlg != NULL)
cDlg->ShowWindow (SW_SHOWNORMAL);
}
void CTabCtrlDlg::OnStyleButtons()
{
UpdateData (TRUE);
if (m_StyleButtons == TRUE)
{
m_tab.ModifyStyle (0, TCS_BUTTONS, TRUE);
m_tab.Invalidate ();
}
else
{
m_tab.ModifyStyle (TCS_BUTTONS, 0, TRUE);
m_tab.Invalidate ();
}
TC_ITEM ti;
int nSel = m_tab.GetCurSel ();
ti.mask = TCIF_PARAM | TCIF_IMAGE;
m_tab.GetItem (nSel, &ti);
CWnd *cDlg = (CWnd *) ti.lParam;
if (cDlg != NULL)
cDlg->Invalidate ();
}
void CTabCtrlDlg::OnStyleHottrack()
{
DWORD dwStyle, dwStyleEx;
UpdateData (TRUE);
if (m_StyleHotTrack == TRUE)
{
m_tab.ModifyStyle (0, TCS_HOTTRACK, TRUE);
dwStyle = m_tab.GetStyle ();
dwStyleEx = m_tab.GetExStyle ();
RecreateWindow (dwStyle, dwStyleEx);
}
else
{
m_tab.ModifyStyle (TCS_HOTTRACK, 0, TRUE);
dwStyle = m_tab.GetStyle ();
dwStyleEx = m_tab.GetExStyle ();
RecreateWindow (dwStyle, dwStyleEx);
}
switch (m_TabsLocation)
{
case 0: // At the top
AlignTabsAtTop();
break;
case 1: // At the bottom
AlignTabsAtBottom ();
break;
case 2: // At the left
AlignTabsAtLeft();
break;
case 3: // At the right
AlignTabsAtRight();
break;
}
}
void CTabCtrlDlg::GetTabRects(CRect &r, CRect &rc)
{
int nSel = m_tab.GetCurSel ();
m_tab.SetCurSel (0);
m_tab.GetItemRect (0, &r);
m_tab.GetClientRect (rc);
rc.left += m_rcBase.left;
rc.top += m_rcBase.top;
rc.right += m_rcBase.left;
rc.bottom += m_rcBase.top;
m_tab.SetCurSel (nSel);
}
void CTabCtrlDlg::OnTabctrlSwitchcontrols()
{
TC_ITEM ti;
ti.mask = TCIF_PARAM;
m_tab.GetItem (0, &ti);
CTreeCtrl *tree = (CTreeCtrl *) ti.lParam;
tree->SetParent (&m_tab);
CRect rc;
tree->GetWindowRect (rc);
m_tab.ScreenToClient (rc);
if (tree->IsKindOf (RUNTIME_CLASS(CTreeCtrl)))
{
tree->DestroyWindow ();
m_AltList.Create (LVS_REPORT | WS_BORDER, rc, &m_tab, 0);
ti.lParam = (LPARAM) &m_AltList;
InitializeList (&m_AltList);
m_FirstPageControl = &m_AltList;
::SetWindowText (GetDlgItem(IDC_TABCTRL_SWITCHCONTROLS)->m_hWnd,
"Use Tree Control");
}
else
{
tree->DestroyWindow ();
m_tree.Create (TREE_STYLES, rc, &m_tab, 0);
ti.lParam = (LPARAM) &m_tree;
m_tab.SetItem (0, &ti);
int nCur = m_tab.GetCurSel ();
if (nCur == 0)
m_tree.ShowWindow (SW_SHOWNORMAL);
InitializeTree (&m_tree);
m_FirstPageControl = &m_tree;
::SetWindowText (GetDlgItem(IDC_TABCTRL_SWITCHCONTROLS)->m_hWnd,
"Use List Control");
}
m_tab.SetItem (0, &ti);
int nCur = m_tab.GetCurSel ();
if (nCur == 0)
m_FirstPageControl->ShowWindow (SW_SHOWNORMAL);
m_FirstPageControl->SetParent (this);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -