CGpStringFormat.GetHotkeyPrefixmethod
Gets an element of the **HotkeyPrefix** enumeration that indicates the type of processing that is performed on a string when a hot key prefix, an ampersand (&), is encountered.
Syntax
FUNCTION GetHotkeyPrefix () AS HotkeyPrefix
Description
Gets an element of the HotkeyPrefix enumeration that indicates the type of processing that is performed on a string when a hot key prefix, an ampersand (&), is encountered.
Remarks
Hot keys, also called access keys, are keys that are programmed to provide an end user with keyboard shortcuts to functionality and are activated by pressing the ALT key. The keys are application dependent and are identified by an underscored letter, typically in a menu name or menu item; for example, when you press ALT, the letter F of the File menu is underscored. The F key is a shortcut to display the File menu.
A client programmer designates a hot key in an application by using the hot key prefix, an ampersand (&), in a string that typically is displayed as the name of a menu or an item in a menu and by using the SetHotkeyPrefix method to set the appropriate type of processing. When a character in a string is preceded with an ampersand, the key that corresponds to the character becomes a hot key during the processing that occurs when the string is drawn on the display device. The ampersand is called a hot key prefix because it precedes the character to be activated. If HotkeyPrefixNone is passed to SetHotkeyPrefix, no processing of hot key prefixes occurs.
Note: The term hot key is used synonymously here with the term access key. The term hot key may have a different meaning in other Windows APIs.
Example
' ======================================================================================== ' The following example creates a StringFormat object, sets the type of hot key prefix ' processing to be performed on the string, and then gets the type of processing and stores ' it in a variable. The code then creates a second StringFormat object and uses the stored ' value to set the type of hot key prefix processing for the second StringFormat object. ' The code uses the second StringFormat object to draw a string that contains the hot key ' prefix character. The code also draws the string's layout rectangle. ' ======================================================================================== SUB Example_GetHotKeyPrefix (BYVAL hdc AS HDC)
' // Create a graphics object from the window device context DIM graphics AS CGpGraphics = hdc ' // Set the scale transform graphics.ScaleTransformForDpi
' // Create a red solid brush DIM solidBrush AS CGpSolidBrush = ARGB_RED ' // Create a font family from name DIM fontFamily AS CGpFontFamily = "Times New Roman" ' // Create a font from the font family DIM pFont AS CGpFont = CGpFont(@fontFamily, AfxGdipPointsToPixels(16, TRUE), FontStyleRegular, UnitPixel)
' // Create a string format object and set its hot key prefix DIM stringFormat AS CGpStringFormat stringFormat.SetHotkeyPrefix(HotkeyPrefixShow)
' // Get the hot key prefix from the StringFormat object. DIM nHotkeyPrefix AS HotkeyPrefix = stringFormat.GetHotkeyPrefix
' // Create a second StringFormat object with the same hot key prefix. DIM stringFormat2 AS CGpStringFormat stringFormat2.SetHotkeyPrefix(nHotkeyPrefix)
' // Use the seconds StringFormat object in a call to DrawString DIM wszText AS WSTRING * 260 = "This &text has some &underlined characters." graphics.DrawString(@wszText, LEN(wszText), @pFont, 30, 30, 160, 200, @stringFormat2, @solidBrush)
' // Draw the rectangle that encloses the text DIM pen AS CGpPen = ARGB_RED graphics.DrawRectangle(@pen, 30, 30, 160, 200)
END SUB ' ========================================================================================
Reference
- Include file
CGpStringFormat.inc - Defined in AfxNova/CGpStringFormat.inc:149
- Documented in Graphics/GdiPlus Classes/CGpStringFormat Class.md
- Topic: CGpStringFormat Class