StringFormat::SetHotkeyPrefix 方法 (gdiplusstringformat.h)

StringFormat::SetHotkeyPrefix 方法會設定遇到熱鍵前置詞和 (&) 時,在字串上執行的處理類型。 連字元稱為熱鍵前置詞,可用來將特定索引鍵指定為熱鍵。

語法

Status SetHotkeyPrefix(
  [in] HotkeyPrefix hotkeyPrefix
);

參數

[in] hotkeyPrefix

類型: HotkeyPrefix

HotkeyPrefix 列舉的 元素,指定如何處理熱鍵前置詞。

傳回值

類型: 狀態

如果方法成功,它會傳回Ok,這是 Status 列舉的元素。

如果方法失敗,它會傳回 Status 列舉的其他其中一個專案。

備註

快捷鍵也稱為訪問鍵,是程式設計來為使用者提供功能鍵盤快捷方式的按鍵,並按下 ALT 鍵來啟用。 索引鍵與應用程式相關,並以底線字母識別,通常是在功能表名稱或功能表項中;例如,當您按下 ALT 時, [檔案 ] 選單的字母 F 會加上底線。 F 鍵是顯示 [ 檔案 ] 選單的快捷方式。

用戶端程式設計人員會使用熱鍵前置詞、連字元和 (&) ,在一般會顯示為功能表名稱的字串中,以及使用 StringFormat::SetHotkeyPrefix 方法來設定適當的處理類型,以指定應用程式中的熱鍵。 當字串中的字元前面加上連字元時,對應至字元的索引鍵會在顯示裝置上繪製字串時,變成熱鍵。 連字元稱為熱鍵前置詞,因為它在要啟動的字元之前。 如果 HotkeyPrefixNone 傳遞至 StringFormat::SetHotkeyPrefix,則不會處理熱鍵前置詞。

注意 常用 索引鍵 一詞在此與 存取密鑰一詞同義。 在其他 Windows API 中 ,熱鍵 一詞可能有不同的意義。
 

範例

下列範例會建立 StringFormat 物件,並設定字串上要執行的熱鍵前置詞處理類型。 程式代碼接著會使用 StringFormat 物件來繪製包含熱鍵前置詞字元的字串。 程序代碼也會繪製字串的配置矩形。

VOID Example_SetHotkeyPrefix(HDC hdc)
{
   Graphics graphics(hdc);

   SolidBrush  solidBrush(Color(255, 255, 0, 0)); 
   FontFamily  fontFamily(L"Times New Roman");
   Font        font(&fontFamily, 24, FontStyleRegular, UnitPixel);
   
   StringFormat stringFormat;
   stringFormat.SetHotkeyPrefix(HotkeyPrefixShow);

   graphics.DrawString(
      L"This &text has some &underlined characters.", 
      43,  // string length
      &font, 
      RectF(30, 30, 160, 200), 
      &stringFormat, 
      &solidBrush);

   // Draw the rectangle that encloses the text.
   Pen pen(Color(255, 255, 0, 0));
   graphics.DrawRectangle(&pen, 30, 30, 160, 200);
}

規格需求

需求
最低支援的用戶端 Windows XP、Windows 2000 Professional [僅限桌面應用程式]
最低支援的伺服器 Windows 2000 Server [僅限桌面應用程式]
目標平台 Windows
標頭 gdiplusstringformat.h (包含 Gdiplus.h)
程式庫 Gdiplus.lib
Dll Gdiplus.dll

另請參閱

HotkeyPrefix

StringFormat

StringFormat::GetHotkeyPrefix