📄 controlsprop.cpp
字号:
// ControlsProp.cpp : implementation file
//
#include "stdafx.h"
#include "Controls.h"
#include "ControlsProp.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
bool GetCommonControlsVersion(DWORD &dwMajor, DWORD &dwMinor);
/////////////////////////////////////////////////////////////////////////////
// CControlsProp
IMPLEMENT_DYNAMIC(CControlsProp, CPropertySheet)
CControlsProp::CControlsProp(UINT nIDCaption, CWnd* pParentWnd, UINT iSelectPage)
:CPropertySheet(nIDCaption, pParentWnd, iSelectPage)
{
AddPages ();
m_psh.dwFlags |= PSH_NOAPPLYNOW;
m_psh.dwFlags &= ~PSH_HASHELP;
}
CControlsProp::CControlsProp(LPCTSTR pszCaption, CWnd* pParentWnd, UINT iSelectPage)
:CPropertySheet(pszCaption, pParentWnd, iSelectPage)
{
AddPages ();
m_psh.dwFlags |= PSH_NOAPPLYNOW;
m_psh.dwFlags &= ~PSH_HASHELP;
}
void CControlsProp::AddPages()
{
AddPage (&m_StaticPage);
m_StaticPage.m_psp.pszTitle = _T("Static Text");
AddPage (&m_EditPage);
m_EditPage.m_psp.pszTitle = _T("Edit");
AddPage (&m_RichEditPage);
m_RichEditPage.m_psp.pszTitle = _T("Rich Edit");
AddPage (&m_ButtonPage);
m_ButtonPage.m_psp.pszTitle = _T("Buttons");
AddPage (&m_ListBoxPage);
m_ListBoxPage.m_psp.pszTitle = _T("List Box");
AddPage (&m_ComboBoxPage);
m_ComboBoxPage.m_psp.pszTitle = _T("Combo Box");
AddPage (&m_ScrollBarPage);
m_ScrollBarPage.m_psp.pszTitle = _T("Scroll Bar");
AddPage (&m_ImageListPage);
m_ImageListPage.m_psp.pszTitle = _T("Image List");
AddPage (&m_ProgressBarPage);
m_ProgressBarPage.m_psp.pszTitle = _T("Progress Bar");
AddPage (&m_SliderPage);
m_SliderPage.m_psp.pszTitle = _T("Slider");
AddPage (&m_SpinnerPage);
m_SpinnerPage.m_psp.pszTitle = _T("Spinner");
AddPage (&m_HeaderPage);
m_HeaderPage.m_psp.pszTitle = _T("Header");
AddPage (&m_ListCtrlPage);
m_ListCtrlPage.m_psp.pszTitle = _T("List Control");
AddPage (&m_TreeCtrlPage);
m_TreeCtrlPage.m_psp.pszTitle = _T("Tree Control");
AddPage (&m_AnimationPage);
m_AnimationPage.m_psp.pszTitle = _T("Animation");
AddPage (&m_TabCtrlPage);
m_TabCtrlPage.m_psp.pszTitle = _T("Tab Control");
AddPage (&m_StatusBarPage);
m_StatusBarPage.m_psp.pszTitle = _T("Status Bar");
AddPage (&m_ToolBarPage);
m_ToolBarPage.m_psp.pszTitle = _T("Tool Bar");
AddPage (&m_ToolTipPage);
m_ToolTipPage.m_psp.pszTitle = _T("Tool Tips");
AddPage (&m_HotKeyPage);
m_HotKeyPage.m_psp.pszTitle = _T("Hot Key");
AddPage (&m_DateTimePickerPage);
m_DateTimePickerPage.m_psp.pszTitle = _T("Date Time Picker");
AddPage (&m_CalendarPage);
m_CalendarPage.m_psp.pszTitle = _T("Calendar");
AddPage (&m_OtherPage);
m_OtherPage.m_psp.pszTitle = _T("Other Controls");
}
CControlsProp::~CControlsProp()
{
}
BEGIN_MESSAGE_MAP(CControlsProp, CPropertySheet)
//{{AFX_MSG_MAP(CControlsProp)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CControlsProp message handlers
BOOL CControlsProp::OnInitDialog()
{
BOOL bResult = CPropertySheet::OnInitDialog();
CWnd *button = GetDlgItem (IDOK);
button->ShowWindow (SW_HIDE);
button = GetDlgItem (IDHELP);
button->ShowWindow (SW_HIDE);
button = GetDlgItem (IDCANCEL);
button->SetWindowText (_T("Close"));
CRect rc;
button->GetWindowRect (rc);
ScreenToClient (rc);
rc.right = rc.left - 15;
rc.left = 5;
m_wndStatusBar.Create (WS_CHILD
| WS_VISIBLE
| CCS_NOPARENTALIGN,
rc, this, 0);
int nParts [] = {rc.right - 120, -1};
m_wndStatusBar.SetParts (2, nParts);
m_wndStatusBar.GetRect (1, rc);
rc.bottom += 4 * (rc.bottom - rc.top);
m_wndCombo.Create (CBS_DROPDOWNLIST
| WS_VISIBLE
| WS_CHILD | WS_BORDER
| CBS_SORT
| WS_VSCROLL,
rc, &m_wndStatusBar,
IDC_PROPSHEET_COMBO);
CFont *font = GetFont ();
m_wndCombo.SetFont (font);
int nPageCount = GetPageCount ();
for (int i = 0; i < nPageCount; ++i)
{
CPropertyPage *page = GetPage (i);
int nIndex = m_wndCombo.AddString (page->m_psp.pszTitle);
m_wndCombo.SetItemDataPtr (nIndex, page);
}
m_wndCombo.SelectString (-1, GetPage(0)->m_psp.pszTitle);
DWORD dwMajor, dwMinor;
GetCommonControlsVersion(dwMajor, dwMinor);
CString strText;
strText.Format ("Windows Common Controls Library Version %d.%02d",
dwMajor, dwMinor);
m_wndStatusBar.SetText ((LPCSTR) strText, 0, 0);
CRect rcButton;
m_wndStatusBar.GetWindowRect (rc);
button->GetWindowRect (rcButton);
rcButton.top = rc.top;
ScreenToClient (rcButton);
button->MoveWindow (rcButton, TRUE);
return bResult;
}
BOOL CControlsProp::OnNotify(WPARAM wParam, LPARAM lParam, LRESULT* pResult)
{
NMHDR *pNMHDR = (NMHDR *) lParam;
switch (pNMHDR->code)
{
case TCN_SELCHANGE:
{
int nIndex = GetActiveIndex ();
CPropertyPage *active = GetPage (nIndex);
int nCount = GetPageCount ();
for (int i = 0; i < nCount; ++i)
{
if (m_wndCombo.GetItemDataPtr (i) == active)
{
m_wndCombo.SetCurSel (i);
break;
}
}
}
break;
case CBN_SELCHANGE:
{
int nSel = m_wndCombo.GetCurSel ();
CPropertyPage *page = (CPropertyPage *) m_wndCombo.GetItemDataPtr (nSel);
SetActivePage (page);
return (TRUE);
}
}
return (CPropertySheet::OnNotify(wParam, lParam, pResult));
}
BOOL CControlsProp::OnChildNotify(UINT message, WPARAM wParam, LPARAM lParam, LRESULT* pLResult)
{
if (message == WM_CHILDACTIVATE)
{
CPropertyPage *page = GetActivePage ();
int nCount = GetPageCount ();
for (int i = 0; i < nCount; ++i)
{
if (m_wndCombo.GetItemDataPtr (i) == page)
{
m_wndCombo.SetCurSel (i);
break;
}
}
}
return CPropertySheet::OnChildNotify(message, wParam, lParam, pLResult);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -