本文內容
CMFCRibbonButton
類別實作可以放置在功能區列項目 (例如面板、快速存取工具列和快顯功能表) 上的按鈕。
如需更多詳細資料,請參閱 Visual Studio 安裝位置下之 VC\atlmfc\src\mfc 資料夾中的原始程式碼。
class CMFCRibbonButton : public CMFCRibbonBaseElement
名稱 | 描述 |
---|---|
CMFCRibbonButton::CMFCRibbonButton | 建構功能區按鈕物件。 |
名稱 | 描述 |
---|---|
CMFCRibbonButton::OnClick | 使用者按一下按鈕時由架構呼叫。 |
下列範例示範如何在 CMFCRibbonButton
類別中使用各種方法。 此範例示範如何建構 CMFCRibbonButton
類別的物件、將快顯功能表指派給功能區按鈕、設定按鈕的描述、從快顯功能表中移除功能表項目,以及將快顯功能表靠右對齊按鈕的邊緣。
strTemp.LoadString(IDS_RIBBON_STYLE);
// The first parameter is the command ID of the button.
// The third parameter is a zero-based index of the button's small image in the
// image list of the parent category.
// The fourth parameter is a zero-based index of the button's large image in the
// image list of the parent category.
CMFCRibbonButton *pVisualStyleButton = new CMFCRibbonButton(1, strTemp, -1, -1);
pVisualStyleButton->SetMenu(IDR_THEME_MENU, TRUE, TRUE);
strTemp.LoadString(IDS_RIBBON_STYLE_TIP);
pVisualStyleButton->SetToolTipText(strTemp);
strTemp.LoadString(IDS_RIBBON_STYLE_DESC);
pVisualStyleButton->SetDescription(strTemp);
pVisualStyleButton->RemoveSubItem(0);
pVisualStyleButton->SetRightAlignMenu(TRUE);
若要在應用程式中使用功能區按鈕,請建構按鈕物件,並將其新增至適當的功能區 面板。
CMFCRibbonPanel* pPanel = pCategory->AddPanel (
_T("Clipboard"), // Panel name
m_PanelIcons.ExtractIcon (0)); // Panel icon
// Create the first button ("Paste"):
CMFCRibbonButton* pPasteButton =
new CMFCRibbonButton (ID_EDIT_PASTE, _T("Paste"), -1, 0);
// The third parameter (-1) disables small images for button.
// This button is always displayed with a large image
// Associate a pop-up menu with the "Paste" button:
pPasteButton->SetMenu (IDR_CONTEXT_MENU);
// Add buttons to the panel. These buttons have only small images.
pPanel->Add (new CMFCRibbonButton (ID_EDIT_CUT, _T("Cut"), 1));
pPanel->Add (new CMFCRibbonButton (ID_EDIT_COPY, _T("Copy"), 2));
pPanel->Add (new CMFCRibbonButton (ID_EDIT_PAINT, _T("Paint"), 9));
標頭: afxribbonbutton.h
將功能表項目加入至與按鈕相關聯的快顯功能表。
void AddSubItem(
CMFCRibbonBaseElement* pSubItem,
int nIndex=-1);
pSubItem
[in]指定要加入之新專案的指標。
nIndex
[in]指定要將專案加入按鈕功能表項數位的索引;-1,在功能表項陣列結尾加入 專案。
virtual BOOL CanBeStretched();
virtual void CleanUpSizes();
virtual void ClosePopupMenu();
建構功能區按鈕物件。
CMFCRibbonButton(
UINT nID,
LPCTSTR lpszText,
int nSmallImageIndex=-1,
int nLargeImageIndex=-1,
BOOL bAlwaysShowDescription=FALSE);
CMFCRibbonButton(
UINT nID,
LPCTSTR lpszText,
HICON hIcon,
BOOL bAlwaysShowDescription=FALSE,
HICON hIconSmall=NULL,
BOOL bAutoDestroyIcon=FALSE,
BOOL bAlphaBlendIcon=FALSE);
nID
[in]指定按鈕的命令識別碼。
lpszText
[in]指定按鈕的文字標籤。
nSmallImageIndex
[in]在父類別的影像清單中,指定按鈕小型影像的以零起始的索引。
nLargeImageIndex
[in]在父類別的影像清單中,指定按鈕大型影像的以零起始的索引。
hIcon
[in]指定應用程式用來做為按鈕影像之圖示的句柄。
下列範例示範如何建構 CMFCRibbonButton
物件。
strTemp.LoadString(IDS_RIBBON_CUT);
CMFCRibbonButton *butn = new CMFCRibbonButton(ID_EDIT_CUT, strTemp, 1);
butn->SetKeys(_T("k"));
CSize DrawBottomText(
CDC* pDC,
BOOL bCalcOnly);
[in] pDC
[in] bCalcOnly
virtual void DrawImage(
CDC* pDC,
RibbonImageType type,
CRect rectImage);
[in] pDC
[in] 類型
[in] rectImage
virtual int DrawRibbonText(
CDC* pDC,
const CString& strText,
CRect rectText,
UINT uiDTFlags,
COLORREF clrText = (COLORREF)-1);
[in] pDC
[in] strText
[in] rectText
[in] uiDTFlags
[in] clrText
傳回與指定之命令識別碼相關聯的快顯功能表項目索引。
int FindSubItemIndexByID(UINT uiID) const;
uiID
[in]指定快顯功能表項的命令標識碼。
與 uiID 相關聯之子專案的以零起始的索引。 如果沒有這類子專案,則為 -1。
CRect GetCommandRect() const;
virtual CSize GetCompactSize(CDC* pDC);
[in] pDC
HICON GetIcon(BOOL bLargeIcon = TRUE) const;
[in] bLargeIcon
傳回與按鈕相關聯的映像索引。
int GetImageIndex(BOOL bLargeImage) const;
bLargeImage
[in]如果為TRUE,則會傳回影像清單中包含大型影像的影像索引;否則會傳回影像清單中的影像索引,其中包含小型影像。
相關聯影像清單中的按鈕影像索引。
virtual CSize GetImageSize(RibbonImageType type) const;
[in] 類型
virtual CSize GetIntermediateSize(CDC* pDC);
[in] pDC
傳回已指派給功能區按鈕之 Windows 功能表的控制代碼。
HMENU GetMenu() const;
指派給按鈕之 Windows 功能表的句柄;如果沒有指派功能表,則為NULL。
CRect GetMenuRect() const;
virtual CSize GetRegularSize(CDC* pDC);
[in] pDC
const CArray<CMFCRibbonBaseElement*, CMFCRibbonBaseElement*>& GetSubItems() const;
int GetTextRowHeight() const;
virtual CString GetToolTipText() const;
virtual BOOL HasCompactMode() const;
virtual BOOL HasIntermediateMode() const;
virtual BOOL HasLargeMode() const;
virtual BOOL HasMenu() const;
virtual BOOL IsAlwaysDrawBorder() const;
virtual BOOL IsAlwaysLargeImage() const;
virtual BOOL IsApplicationButton() const;
virtual BOOL IsCommandAreaHighlighted() const;
指定是否啟用功能區按鈕的預設命令。
BOOL IsDefaultCommand() const;
如果您已啟用功能區按鈕的預設命令,則為TRUE;否則為 FALSE。
virtual BOOL IsDefaultPanelButton() const;
virtual BOOL IsDrawTooltipImage() const;
BOOL IsLargeImage() const;
virtual BOOL IsMenuAreaHighlighted() const;
BOOL IsMenuOnBottom() const;
virtual BOOL IsPopupDefaultMenuLook() const;
指定功能表是否靠右對齊。
BOOL IsRightAlignMenu() const;
如果功能表靠右對齊,則為TRUE;否則為 FALSE。
BOOL IsSingleLineText() const;
virtual void OnCalcTextSize(CDC* pDC);
[in] pDC
使用者按一下按鈕時由架構呼叫。
virtual void OnClick(CPoint point);
point
[in]指定滑鼠按下的位置。
如果您想要處理這個事件,請覆寫衍生類別中的這個方法。
virtual void OnDraw(CDC* pDC);
[in] pDC
virtual void OnDrawBorder(CDC* pDC);
[in] pDC
virtual COLORREF OnFillBackground(CDC* pDC);
[in] pDC
從快顯功能表中移除所有功能表項目。
void RemoveAllSubItems();
從快顯功能表中移除功能表項目。
BOOL RemoveSubItem(int nIndex);
nIndex
[in]指定您要移除之功能表項之以零起始的索引。
如果已成功移除指定的專案,則為TRUE;否則為 FALSE,如果 nIndex 為負數,或超過彈出視窗功能表中的功能表項數目。
設定功能區按鈕的協助工具資料。
virtual BOOL SetACCData(
CWnd* pParent,
CAccessibilityData& data);
pParent
功能區項目的父視窗。
data
功能區項目的協助工具資料。
如果成功,則傳回 TRUE;否則為 FALSE。
指定使用者摺疊按鈕時,按鈕是顯示大型影像還是小型影像。
void SetAlwaysLargeImage(BOOL bSet=TRUE);
bSet
[in]如果為TRUE,按鈕會顯示大型影像。 否則,按鈕會顯示小型影像。
啟用功能區按鈕的預設命令。
void SetDefaultCommand(BOOL bSet=TRUE);
bSet
[in]如果為TRUE,按鈕可以執行其默認命令。 如果為 FALSE,按鈕就無法執行其預設命令。
bSet 只有在按鈕具有功能表時才相關。 如果 bSet 為 TRUE,則按鈕可以執行其預設命令,而且只有在使用者按鍵右邊緣的箭號時,才會顯示指派的快捷功能表。 否則,按鈕無法執行其預設命令,而且不論使用者按兩下的按鈕區域為何,彈出視窗都會顯示。
virtual void SetDescription(LPCTSTR lpszText);
[in] lpszText
將索引指派給按鈕的影像。
void SetImageIndex(
int nIndex,
BOOL bLargeImage);
nIndex
[in]指定影像索引。
bLargeImage
[in]如果為 TRUE,則指定的索引會參考大型影像的清單。 否則,索引會參考小型影像的清單。
將快顯功能表上指派給功能區按鈕。
void SetMenu(
HMENU hMenu,
BOOL bIsDefaultCommand=FALSE,
BOOL bRightAlign=FALSE);
void SetMenu(
UINT uiMenuResID,
BOOL bIsDefaultCommand=FALSE,
BOOL bRightAlign=FALSE);
hMenu
Windows 功能表的句柄。
bIsDefaultCommand
如果為 TRUE,按鈕可以執行其預設命令;否則,按鈕會顯示快捷功能表。
bRightAlign
如果為TRUE,功能表會靠右對齊。 否則,功能表會靠左對齊。
uiMenuResID
功能表資源標識碼。
當應用程式將功能表指派給按鈕時,按鈕會在右側顯示箭號。 如果 bIsDefaultCommand 為 TRUE,則只有在使用者單擊箭號時,才會顯示功能表。 如果使用者按鍵,則會執行其預設命令。 如果 bIsDefaultCommand 為 FALSE,功能表會顯示方式是按鍵上的任意位置。
virtual void SetParentCategory(CMFCRibbonCategory* pParent);
[in] pParent
將快捷功能表對齊按鈕的邊緣。
void SetRightAlignMenu(BOOL bSet=TRUE);
bSet
[in]如果為TRUE,功能表會靠右對齊。 否則,功能表會靠左對齊
virtual void SetText(LPCTSTR lpszText);
[in] lpszText