$ACCELERATOR directive

Note: The $ACCELERATOR directive is valid only in BCX programs which use the GUI statement. The $ACCELERATOR directive should be placed immediately preceding the GUI statement.

Purpose: The $ACCELERATOR directive implements keyboard accelerator access to the command set of a program.


Syntax:

 $ACCELERATOR hAccTable

Parameters:

  • Data type: HACCEL
    hAccTable The handle of the accelerator table. This handle must be declared as a GLOBAL.

Remarks:

Starting with Windows 2000, keyboard indicators such as underlined accelerators and focus rectangles (collectively known as "keyboard cues") are hidden by default, and are revealed only when you start using the keyboard. You can control this behavior from the Desktop Control Panel, under Appearance, Effects, "Hide underlined letters for keyboard navigation until I press the Alt key".

In the example below, the underlined accelerators are turned on, as the default, at the code line


 SystemParametersInfo(SPI_SETKEYBOARDCUES, 0, (LPVOID)1, 0) ' Turn on underlining of the accelerator keys.

To turn off the underlining of the accelerator keys use


 SystemParametersInfo(SPI_SETKEYBOARDCUES, 0, (LPVOID)0, 0) ' Turn off underlining of the accelerator keys.

Example:

Below, the $ACCELERATOR directive is used to facilitate the capture of a keypress for menu items.


   $ACCELERATOR hAccTable
    
   GUI "ACCELERATOR", PIXELS
    
  MACRO   ID_Edit    = 200 'Main Menu member 
  MACRO   ID_Options = 300 'Main Menu member 
  MACRO   ID_Open    = 400 'File Menu member 
  MACRO   ID_Close   = 500 'File Menu member 
  MACRO   ID_Save    = 600 'File Menu member 
  MACRO   ID_SaveAs  = 700 'File Menu member 
  MACRO   ID_Exit    = 800 'File Menu member 
   
   GLOBAL  Form1      AS HWND
   GLOBAL  MainMenu   AS HMENU
   GLOBAL  FileMenu   AS HMENU
   GLOBAL  hAccTable  AS HACCEL
    
   SUB FORMLOAD
     DIM RAW Caption$
     SET sAccel[] AS ACCEL
      FCONTROL OR FVIRTKEY, ASC("O"), ID_Open,
      FCONTROL OR FVIRTKEY, ASC("S"), ID_Save
     END SET
    
     hAccTable = CreateAcceleratorTable(sAccel, 2)
    
    '======================================================================== 
    Caption$ = "ACCELERATOR Demo"
    '======================================================================== 
   
    Form1 = BCX_FORM(Caption$, 0, 0, 300, 200)
    
    '======================================================================== 
    '                          Start Building Menus 
    '======================================================================== 
    MainMenu   = CreateMenu() ' CreateMenu returns a MENU HANDLE 
    FileMenu   = CreateMenu() ' CreateMenu returns a MENU HANDLE 
    '======================================================================== 
    '                     Build the File Menu First 
    '======================================================================== 
    AppendMenu(FileMenu, MF_STRING   , ID_Open  , "&Open" + CHR$(9) + "Ctrl + O")
    AppendMenu(FileMenu, MF_STRING   , ID_Close , "&Close")
    AppendMenu(FileMenu, MF_STRING   , ID_Save  , "&Save" + CHR$(9) + "Ctrl + S")
    AppendMenu(FileMenu, MF_STRING   , ID_SaveAs, "Save &As")
    AppendMenu(FileMenu, MF_SEPARATOR, 0       , "")
    AppendMenu(FileMenu, MF_STRING   , ID_Exit  , "E&xit")
    '======================================================================== 
    '                        Build the Main Menu Next 
    '======================================================================== 
    AppendMenu(MainMenu, MF_STRING, ID_Edit   , "Edit")
    AppendMenu(MainMenu, MF_STRING, ID_Options, "Options")
    '======================================================================== 
    '                  Attach the File menu to the main menu 
    '======================================================================== 
    InsertMenu(MainMenu, ID_Edit, MF_POPUP, FileMenu, "File")
    '======================================================================== 
    SetMenu(Form1,MainMenu)             ' Activate the menu 
 
    SystemParametersInfo(SPI_SETKEYBOARDCUES, 0, (LPVOID)1, 0) ' Underline the accelerator keys 
 
    CENTER(Form1)
    SHOW (Form1)
  
   END SUB
      
   BEGIN EVENTS
    SELECT CASE CBMSG
       '======================================================================== 
    CASE WM_COMMAND
       '======================================================================== 
     SELECT CASE CBCTL
       CASE ID_Exit : PostQuitMessage(0)
       CASE ID_Open : MSGBOX "Open"
       CASE ID_Save : MSGBOX "Save"
     END SELECT
    END SELECT
   END EVENTS