📄 treeoptionsctrl.h
字号:
/*
Module : TreeOptionsCtrl.h
Purpose: Defines the interface for an MFC class to implement a tree options control
similiar to the advanced tab as seen on the "Internet options" dialog in
Internet Explorer 4 and later
Created: PJN / 31-03-1999
Copyright (c) 1999 - 2003 by PJ Naughter. (Web: www.naughter.com, Email: pjna@naughter.com)
All rights reserved.
Copyright / Usage Details:
You are allowed to include the source code in any product (commercial, shareware, freeware or otherwise)
when your product is released in binary form. You are allowed to modify the source code in any way you want
except you cannot modify the copyright details at the top of each module. If you want to distribute source
code with your application, then you are only allowed to distribute versions released by the author. This is
to maintain a single distribution point for the source code.
*/
/////////////////////////////// Defines ///////////////////////////////////////
#ifndef __TREEOPTIONSCTRL_H__
#define __TREEOPTIONSCTRL_H__
/////////////////////////////// Includes //////////////////////////////////////
#ifndef __AFXDTCTL_H__
#pragma message("To avoid this message please put afxdtctl.h in your PCH (normally stdafx.h)")
#include <afxdtctl.h>
#endif
/////////////////////////////// Classes ///////////////////////////////////////
//forward declaration
class CTreeOptionsCtrl;
class CTreeOptionsBrowseButton;
//Class which represents a combo box used by the tree options class
class CTreeOptionsCombo : public CComboBox
{
public:
//Constructors / Destructors
CTreeOptionsCombo();
virtual ~CTreeOptionsCombo();
protected:
//Misc methods
void SetButtonBuddy(CTreeOptionsBrowseButton* pButton) { m_pButtonCtrl = pButton; };
void SetTreeBuddy(CTreeOptionsCtrl* pTreeCtrl) { m_pTreeCtrl = pTreeCtrl; };
void SetTreeItem(HTREEITEM hItem) { m_hTreeCtrlItem = hItem; };
virtual DWORD GetWindowStyle();
virtual int GetDropDownHeight();
BOOL IsRelatedWnd(CWnd* pChild);
//{{AFX_VIRTUAL(CTreeOptionsCombo)
//}}AFX_VIRTUAL
//{{AFX_MSG(CTreeOptionsCombo)
afx_msg void OnChar(UINT nChar, UINT nRepCnt, UINT nFlags);
afx_msg UINT OnGetDlgCode ();
afx_msg void OnKillFocus(CWnd* pNewWnd);
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
DECLARE_DYNCREATE(CTreeOptionsCombo)
//Member variables
CTreeOptionsCtrl* m_pTreeCtrl;
CTreeOptionsBrowseButton* m_pButtonCtrl;
HTREEITEM m_hTreeCtrlItem;
friend class CTreeOptionsCtrl;
};
//Class which represents a combo box which allows a Font Name to be specified
class CTreeOptionsFontNameCombo : public CTreeOptionsCombo
{
public:
//Constructors / Destructors
CTreeOptionsFontNameCombo();
virtual ~CTreeOptionsFontNameCombo();
protected:
//{{AFX_VIRTUAL(CTreeOptionsFontNameCombo)
//}}AFX_VIRTUAL
//{{AFX_MSG(CTreeOptionsFontNameCombo)
afx_msg int OnCreate(LPCREATESTRUCT lpCreateStruct);
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
DECLARE_DYNCREATE(CTreeOptionsFontNameCombo)
//Misc Methods
virtual DWORD GetWindowStyle();
int EnumFontProc(CONST LOGFONT* lplf, CONST TEXTMETRIC* lptm, DWORD dwType);
static int CALLBACK _EnumFontProc(CONST LOGFONT* lplf, CONST TEXTMETRIC* lptm, DWORD dwType, LPARAM lpData);
};
//Class which represents a combo box which allows a True / False value to be specified
class CTreeOptionsBooleanCombo : public CTreeOptionsCombo
{
public:
//Constructors / Destructors
CTreeOptionsBooleanCombo();
virtual ~CTreeOptionsBooleanCombo();
protected:
//{{AFX_VIRTUAL(CTreeOptionsBooleanCombo)
//}}AFX_VIRTUAL
//{{AFX_MSG(CTreeOptionsBooleanCombo)
afx_msg int OnCreate(LPCREATESTRUCT lpCreateStruct);
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
DECLARE_DYNCREATE(CTreeOptionsBooleanCombo)
};
//forward declaration
class CTreeOptionsBrowseButton;
//Class which represents an edit box used by the tree options class
class CTreeOptionsEdit : public CEdit
{
public:
//Constructors / Destructors
CTreeOptionsEdit();
virtual ~CTreeOptionsEdit();
protected:
//Misc methods
void SetTreeBuddy(CTreeOptionsCtrl* pTreeCtrl) { m_pTreeCtrl = pTreeCtrl; };
void SetButtonBuddy(CTreeOptionsBrowseButton* pButtonCtrl) { m_pButtonCtrl = pButtonCtrl; };
void SetTreeItem(HTREEITEM hItem) { m_hTreeCtrlItem = hItem; };
virtual DWORD GetWindowStyle();
virtual int GetHeight(int nItemHeight);
virtual void BrowseForFolder(const CString& sInitialFolder);
virtual void BrowseForFile(const CString& sInitialFile);
virtual CString GetBrowseForFolderCaption();
virtual CString GetBrowseForFileCaption();
virtual CString GetFileExtensionFilter();
//{{AFX_VIRTUAL(CTreeOptionsEdit)
//}}AFX_VIRTUAL
//{{AFX_MSG(CTreeOptionsEdit)
afx_msg void OnChar(UINT nChar, UINT nRepCnt, UINT nFlags);
afx_msg UINT OnGetDlgCode ();
afx_msg void OnKillFocus(CWnd* pNewWnd);
//}}AFX_MSG
static int CALLBACK SHBrowseSetSelProc(HWND hWnd, UINT uMsg, LPARAM /*lParam*/, LPARAM lpData);
DECLARE_MESSAGE_MAP()
DECLARE_DYNCREATE(CTreeOptionsEdit)
//Member variables
CTreeOptionsCtrl* m_pTreeCtrl;
CTreeOptionsBrowseButton* m_pButtonCtrl;
HTREEITEM m_hTreeCtrlItem;
BOOL m_bDoNotDestroyUponLoseFocus;
friend class CTreeOptionsCtrl;
friend class CTreeOptionsBrowseButton;
};
//Class which represents the spin control which can be used in association with an edit box by the tree options class
class CTreeOptionsSpinCtrl : public CSpinButtonCtrl
{
public:
//Constructors / Destructors
CTreeOptionsSpinCtrl();
virtual ~CTreeOptionsSpinCtrl();
protected:
//Misc methods
void SetTreeBuddy(CTreeOptionsCtrl* pTreeCtrl);
void SetEditBuddy(CTreeOptionsEdit* pEdit);
void SetTreeItem(HTREEITEM hItem) { m_hTreeCtrlItem = hItem; };
virtual DWORD GetWindowStyle();
virtual void GetDefaultRange(int &lower, int& upper);
//{{AFX_VIRTUAL(CTreeOptionsSpinCtrl)
//}}AFX_VIRTUAL
//{{AFX_MSG(CTreeOptionsSpinCtrl)
afx_msg void OnKillFocus(CWnd* pNewWnd);
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
DECLARE_DYNCREATE(CTreeOptionsSpinCtrl)
//Member variables
CTreeOptionsCtrl* m_pTreeCtrl;
HTREEITEM m_hTreeCtrlItem;
CTreeOptionsEdit* m_pEdit;
friend class CTreeOptionsCtrl;
};
//Class which represents the browse button which can be used in association with an edit box by the tree options class
class CTreeOptionsBrowseButton : public CButton
{
public:
//Constructors / Destructors
CTreeOptionsBrowseButton();
virtual ~CTreeOptionsBrowseButton();
protected:
//Misc methods
void SetTreeBuddy(CTreeOptionsCtrl* pTreeCtrl);
void SetTreeItem(HTREEITEM hItem) { m_hTreeCtrlItem = hItem; };
void SetEditBuddy(CTreeOptionsEdit* pEdit);
void SetComboBuddy(CTreeOptionsCombo* pCombo);
virtual DWORD GetWindowStyle();
virtual int GetWidth();
virtual CString GetCaption();
COLORREF GetColor() const { return m_Color; };
void SetColor(COLORREF color);
void GetFontItem(LOGFONT* pLogFont);
void SetFontItem(const LOGFONT* pLogFont);
virtual void BrowseForColor();
virtual void BrowseForFont();
virtual void BrowseForOpaque();
//{{AFX_VIRTUAL(CTreeOptionsBrowseButton)
//}}AFX_VIRTUAL
//{{AFX_MSG(CTreeOptionsBrowseButton)
afx_msg void OnKillFocus(CWnd* pNewWnd);
afx_msg void OnClicked();
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
DECLARE_DYNCREATE(CTreeOptionsBrowseButton)
//Member variables
COLORREF m_Color;
LOGFONT m_Font;
CTreeOptionsCtrl* m_pTreeCtrl;
CTreeOptionsEdit* m_pEdit;
CTreeOptionsCombo* m_pCombo;
HTREEITEM m_hTreeCtrlItem;
friend class CTreeOptionsCtrl;
};
//Class which is used for browsing for filenames
class CTreeOptionsFileDialog : public CFileDialog
{
public:
//Constructors / Destructors
CTreeOptionsFileDialog(BOOL bOpenFileDialog, LPCTSTR lpszDefExt = NULL, LPCTSTR lpszFileName = NULL,
DWORD dwFlags = OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT, LPCTSTR lpszFilter = NULL, CWnd* pParentWnd = NULL);
protected:
DECLARE_DYNAMIC(CTreeOptionsFileDialog)
virtual void OnInitDone();
//{{AFX_MSG(CTreeOptionsFileDialog)
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
};
//Class which represents a date / time control used by the list options class
class CTreeOptionsDateCtrl : public CDateTimeCtrl
{
public:
//Constructors / Destructors
CTreeOptionsDateCtrl();
virtual ~CTreeOptionsDateCtrl();
//Methods
virtual CString GetDisplayText(const SYSTEMTIME& st);
protected:
//Misc methods
void SetTreeBuddy(CTreeOptionsCtrl* pTreeCtrl) { m_pTreeCtrl = pTreeCtrl; };
void SetTreeItem(HTREEITEM hItem) { m_hTreeCtrlItem = hItem; };
virtual DWORD GetWindowStyle();
virtual BOOL IsRelatedWnd(CWnd* pChild);
void GetDateTime(SYSTEMTIME& st) const { CopyMemory(&st, &m_SystemTime, sizeof(SYSTEMTIME)); };
void SetDateTime(const SYSTEMTIME& st) { CopyMemory(&m_SystemTime, &st, sizeof(SYSTEMTIME)); };
//{{AFX_VIRTUAL(CTreeOptionsDateCtrl)
//}}AFX_VIRTUAL
//{{AFX_MSG(CTreeOptionsDateCtrl)
afx_msg void OnChar(UINT nChar, UINT nRepCnt, UINT nFlags);
afx_msg UINT OnGetDlgCode ();
afx_msg void OnKillFocus(CWnd* pNewWnd);
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
DECLARE_DYNCREATE(CTreeOptionsDateCtrl)
//Member variables
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -