StringFormat::GetHotkeyPrefix 方法 (gdiplusstringformat.h)

StringFormat::GetHotkeyPrefix 方法會取得 HotkeyPrefix 列舉的元素,指出遇到熱鍵前置詞和 (&) 時,在字串上執行的處理類型。

Syntax

HotkeyPrefix GetHotkeyPrefix();

傳回值

類型: HotkeyPrefix

這個方法會傳回 HotkeyPrefix 列舉的專案,指出在字元串上執行的熱鍵前置詞處理類型。

備註

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

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

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

範例

下列範例會建立 StringFormat 對象、設定要對字串執行的熱鍵前置詞處理類型,然後取得處理類型,並將它儲存在變數中。 程式代碼接著會建立第二個 StringFormat 物件,並使用預存值來設定第二個 StringFormat 物件的熱鍵前置詞處理類型。 程序代碼會使用第二個 StringFormat 對象來繪製包含熱鍵前置詞字元的字串。 程序代碼也會繪製字串的配置矩形。

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

   SolidBrush  solidBrush(Color(255, 255, 0, 0)); 
   FontFamily  fontFamily(L"Times New Roman");
   Font        font(&fontFamily, 24, FontStyleRegular, UnitPixel);
   
   // Create a StringFormat object, and set its hot key prefix.
   StringFormat stringFormat;
   stringFormat.SetHotkeyPrefix(HotkeyPrefixShow);

   // Get the hot key prefix from the StringFormat object.
   HotkeyPrefix hotkeyPrefix = stringFormat.GetHotkeyPrefix();

   // Create a second StringFormat object with the same hot key prefix.
   StringFormat stringFormat2;
   stringFormat2.SetHotkeyPrefix(hotkeyPrefix);

   // Use the second StringFormat object in a call to DrawString.
  graphics.DrawString(
      L"This &text has some &underlined characters.", 
      43,  // string length
      &font, 
      RectF(30, 30, 160, 200), 
      &stringFormat2, 
      &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