📄 headerbar.h
字号:
/******************************************************************************
* @file HeaderBar.h
* @author reg_todd@hotmail.com
*
* Header file for the Header Bar control.
* Header file holding the definition of the MFC implementation
* of the header bar control.
*
* References none
* Documentation none
* This file is provided 'as is' with no expressed or implied warranty.
* The author accepts no liability if it causes any damage to your computer.
*
* Copyright Paul Todd 2003
******************************************************************************/
#ifndef HEADERBAR_CTRL_H
#define HEADERBAR_CTRL_H
/**
* Macro definition for the expected default style for a header bar control.
*/
#define HEADERBAR_DEFSTYLE (WS_CHILD | WS_VISIBLE | TBSTYLE_FLAT | TBSTYLE_LIST /*| TBSTYLE_CUSTOMERASE | CCS_NODIVIDER */)
/**
* Class holding the MFC class definition for the header bar control.
* This class is based on CWnd and not CToolbarCtrl to provide
* a simpler and more concrete solution to developers.
* This class is actually just a low level wrapper around a toolbar
* with the most important features retained and irrelevant toolbar
* features removed.
*/
class CHeaderBarCtrl : public CWnd
{
// Construction
public:
/**
* RTTI macro for the header bar control class.
*/
DECLARE_DYNAMIC(CHeaderBarCtrl)
public:
/**
* Constructor for the header bar control class.
*/
CHeaderBarCtrl();
/**
* Function to create a new instance of the header bar control class.
* This creates an instance of the toolbar class and links it to the
* MFC object
* @param dwStyle
* @param rect
* @param pParentWnd
* @param nID
* @return BOOL
*/
BOOL Create(DWORD dwStyle, const RECT& rect, CWnd* pParentWnd, UINT nID);
// Attributes
public:
/**
* Function to add a button to the left hand side of the header bar control.
* @param button the button structure to be added to the left in the headerbar.
* @return TRUE if the button was successfully added.
*/
BOOL AddLeftButton(const TBBUTTON& button);
/**
* Function to add a button to the right hand side of the header bar control.
* @param button the button structure to be added to the right in the headerbar.
* @return TRUE if the button was successfully added.
*/
BOOL AddRightButton(const TBBUTTON& button);
/**
* Function to add a button to the left hand side of the header bar control.
* @param button the button structure to be added to the left of the toolbar.
* @return TRUE if the button was successfully added.
*/
BOOL AddLeftButton (const int iBmpIndex, const int iStrIndex, const int iIdCmd,
const int iStyle = TBSTYLE_AUTOSIZE | TBSTYLE_DROPDOWN, const DWORD dwData = NULL);
/**
* Function to add a button to the right hand side of the header bar control.
* @param button the button structure to be added to the right in the headerbar.
* @return TRUE if the button was successfully added.
*/
BOOL AddRightButton(const int iBmpIndex, const int iStrIndex, const int iIdCmd,
const int iStyle = TBSTYLE_AUTOSIZE | TBSTYLE_DROPDOWN, const DWORD dwData = NULL);
/**
* Function to check if the button specified by an id is enabled
* @param nID the id of the button to check
* @return TRUE if the button is enabled, FALSE is not or error.
*/
BOOL IsButtonEnabled(int nID) const;
/**
* Function to check if the button specified by the id is pressed.
* @param nID of the button to check.
* @return TRUE if the button is pressed, FALSE if not pressed or error.
*/
BOOL IsButtonPressed(int nID) const;
/**
* Function to check if the button specified by the id is hidden.
* @param nID of the button to check.
* @return TRUE if the button is hidden, FALSE if it is visible or there is an error.
*/
BOOL IsButtonHidden(int nID) const;
/**
* IsButtonHighlighted
* @param nID
* @return BOOL
*/
BOOL IsButtonHighlighted(int nID) const;
/**
* Sets the state of the button specified by the command id.
* @param nID of the button whose state is to be set.
* @param nState the new state.
* @return TRUE if the state was successfully set, FALSE otherwise.
*/
BOOL SetState(int nID, UINT nState);
/**
* Gets the state if the button specified by the command id.
* @param nID of the button whose state is to be set.
* @return the button state
*/
int GetState(int nID) const;
/**
* Gets the rectangle occupied by the button specified by the command id.
* @param nID of the button whose rectangle is to be obtained.
* @param lpRect pointer to the rectangle to be filled in.
* @return TRUE if the rectangle was successfully obtained, FALSE if error.
*/
BOOL GetRect(int nID, LPRECT lpRect) const;
/**
* Gets the size of a button.
* @return DWORD the HIWORD contains the height of a button and
* the LOWORD contains the width of a button.
*/
DWORD GetButtonSize() const;
/**
* Sets the size of a button.
* @param size the width and height of a button.
* @return TRUE if the new default button size was successfully set.
*/
BOOL SetButtonSize(CSize size);
/**
* Sets the minimum and maximum widths of a button on the toolbar.
* @param cxMin the minimum width in pixels.
* @param cxMax the maximum width in pixels.
* @return TRUE if the button width was set, FALSE if error.
*/
BOOL SetButtonWidth(int cxMin, int cxMax);
/**
* Sets the size of the a bitmap for the toolbar buttons.
* @param size the width and the height of an image in the toolbar.
* @return TRUE if the image size was successfully set or not.
*/
BOOL SetBitmapSize(CSize size);
/**
* Sets the owner window where messages from the toolbar are being sent to.
* @param pWnd the window to recieve the messages.
* @return none.
*/
void SetOwner(CWnd* pWnd);
/**
* Gets the bitmap flags for the headerbar control.
* @return TBBF_LARGE if the toolbar control supports large images.
*/
UINT GetBitmapFlags() const;
/**
* Gets the disabled image list.
* @return a CImagelist object holding the disabled images.
*/
CImageList* GetDisabledImageList() const;
/**
* Gets the image list associated with the headerbar control
* @return the imagelist associated with the header bar control.
*/
CImageList* GetImageList() const;
/**
* Sets the disabled image list for the headerbar control.
* @param pImageList pointer to the new image list to associate with the headerbar control.
* @return CImageList* the previous image list or NULL if there was an error or no previous image list.
*/
CImageList* SetDisabledImageList(CImageList* pImageList);
/**
* Sets the image list for the headerbar control.
* @param pImageList pointer to the new image list to associate with the headerbar control.
* @return CImageList* pointer to the previous imagelist or NULL if there was an error or no previous image list.
*/
CImageList* SetImageList(CImageList* pImageList);
/**
* Gets the current style associated with the headerbar control.
* @return DWORD the style associated with the control.
*/
DWORD GetStyle() const;
/**
* Sets the indent of the left button in the headerbar control.
* @param iIndent the size in pixels of the indent.
* @return TRUE if the indent was successfully set, FALSE otherwise.
*/
BOOL SetIndent(int iIndent);
/**
* Sets the style of the headerbar control.
* @param dwStyle the new headerbar style.
* @return none
*/
void SetStyle(DWORD dwStyle);
/**
* Gets the headerbar button information from the button specified by its id.
* @param nID the id of the button whose information is to be retrieved.
* @param ptbbi pointer to the button information.
* @return TRUE if the button information was successfully retrieved, FALSE otherwise.
*/
BOOL GetButtonInfo(int nID, TBBUTTONINFO* ptbbi) const;
/**
* Sets the headerbar button information for the specified command id.
* @param nID the id whose toolbar button infomation is to be set.
* @param ptbbi pointer to the toolbar button information.
* @return TRUE if the button information was successfully set, FALSE otherwise.
*/
BOOL SetButtonInfo(int nID, TBBUTTONINFO* ptbbi);
/**
* Sets the flags for drawing text in the headerbar control.
* @param dwMask the flag bits to be set.
* @param dwDTFlags the new flags.
* @return DWORD the previous text flags.
*/
DWORD SetDrawTextFlags(DWORD dwMask, DWORD dwDTFlags);
// Operations
public:
/**
* Enables or disables the specified button.
* @param nID the id of the button to enable or disable.
* @param bEnable TRUE if the button is to be enabled, FALSE if its to be disabled.
* @return TRUE if the button was successfully enabled or disabled, FALSE otherwise.
*/
BOOL EnableButton(int nID, BOOL bEnable = TRUE);
/**
* Presses or releases the specified button.
* @param nID the id of the button to press or unpress.
* @param bPress if the button is to be pressed, FALSE if the button is to be unpressed.
* @return TRUE if the button was successfully pressed or unpressed, FALSE if error.
*/
BOOL PressButton(int nID, BOOL bPress = TRUE);
/**
* Function to hide the button specified by the command id.
* @param nID the id of the button to show or hide.
* @param bHide TRUE to hide the button, FALSE to show the button.
* @return TRUE if the button was successfully hidden or shown.
*/
BOOL HideButton(int nID, BOOL bHide = TRUE);
/**
* Adds a bitmap to headerbar control.
* @param nNumButtons the number of button in the bitmap
* @param nBitmapID the resource id of the bitmap.
* @return -1 if error, else index of first image.
*/
int AddBitmap(int nNumButtons, UINT nBitmapID);
/**
* Adds a bitmap to the headerbar control.
* @param nNumButtons the number of bitmaps in the bitmap.
* @param pBitmap a pointer to the bitmap object.
* @return -1 if error else index of the first image.
*/
int AddBitmap(int nNumButtons, CBitmap* pBitmap);
/**
* Loads the bitmap into the headerbar control.
* @param iBitmapID the id of the bitmap holding the images.
* @param hinst the instance holding the bitmap.
* @return none.
*/
void LoadImages(int iBitmapID, HINSTANCE hinst);
/**
* Adds the specified resource string to the headerbar control.
* @param nStringID the id of the string to be added to the toolbar control.
* @return the new index of the string in the headerbar control.
*/
int AddString(UINT nStringID);
/**
* Adds the specified list of strings to the headerbar control.
* @param lpszStrings point to a list of string pointer. the last string is delimited
* with a double zero.
* @return the index of the first added string or -1 if there is an error.
*/
int AddStrings(LPCTSTR lpszStrings);
// Implementation
public:
/**
* Destructor for the headerbar control.
*/
virtual ~CHeaderBarCtrl();
protected:
/**
* Helper function which calculates the correct placement of the toolbar buttons.
* @return none
*/
void AdjustSeperatorButtonSize();
//{{AFX_MSG(CHeaderBarCtrl)
afx_msg int OnCreate(LPCREATESTRUCT lpCreateStruct);
afx_msg LRESULT OnSizeParent(WPARAM wParam, LPARAM lParam);
afx_msg void OnDropDown( NMHDR * pNotifyStruct, LRESULT* result );
afx_msg void OnCustomDraw( NMHDR * pNotifyStruct, LRESULT* result );
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
};
/////////////////////////////////////////////////////////////////////////////
//{{AFX_INSERT_LOCATION}}
// Microsoft Visual C++ will insert additional declarations immediately before the previous line.
#endif // !defined(HEADERBAR_CTRL_H)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -