You can add an accelerator table to a frame window either by using the WinSetAccelTable function or by defining an accelerator-table resource (as shown in the previous section) and creating a frame window with the FCF_ACCELTABLE frame style. The second method is shown in the following code fragment:

    HWND  hwndFrame,hwndClient;
    CHAR  szClassName[]="MyClass";
    CHAR  szTitle[]="MyWindow";

    ULONG flControlStyle=
            FCF_MINMAX        |      /* Min and max buttons      */
            FCF_SHELLPOSITION |      /* System size and position */
            FCF_SIZEBORDER    |      /* Size border              */
            FCF_TITLEBAR      |      /* Title bar                */
            FCF_TASKLIST      |      /* Task list                */
            FCF_ACCELTABLE    |      /* Accelerator table        */
            FCF_SYSMENU       |      /* System menu              */
            FCF_MENU;                /* Menu                     */

    hwndFrame=WinCreateStdWindow(HWND_DESKTOP,
      WS_VISIBLE,
      &flControlStyle,
      szClassName,
      szTitle,
      0,
      (HMODULE)NULL,
      ID_MENU_RESOURCE,
      &hwndClient);

Notice that if you set the flControlStyle parameter to the FCF_STANDARD flag, you must define an accelerator-table resource, because FCF_STANDARD includes the FCF_ACCELTABLE flag.

If the window being created also has a menu, the menu resource and accelerator resource must have the same resource identifier; this is because the WinCreateStdWindow function has only one input parameter to specify the resource identifiers for menus, accelerator tables, and icons. If an application creates an accelerator table resource-definition file; then, opens a standard frame window (as shown in the preceding example), the accelerator table is installed automatically in the window's message queue, and keyboard events are translated during the normal processing of events. The application simply responds to WM_COMMAND, WM_SYSCOMMAND, and WM_HELP messages; it does not matter whether these messages come from a menu or an accelerator.

An application also can add an accelerator table to a window by calling the WinSetAccelTable function with an accelerator-table handle and a frame-window handle. The application can call either the WinLoadAccelTable function to retrieve an accelerator table from a resource file or the WinCreateAccelTable function to create an accelerator table from an accelerator-table data structure in memory.


[Back] [Next]