Page 126 - DCAP408_WEB_PROGRAMMING
P. 126

Windows Programming




                    Notes
                                                                     Figure  7.3

















                                   The system also sustains accelerator tables for each application. An application can define any
                                   number of accelerator tables for  utilization with its own windows. A unique 32-bit  handle
                                   (HACCEL) identifies each table. Though, only one accelerator table can be active at a time for a
                                   particular thread. The handle to the accelerator table passed to the TranslateAccelerator function
                                   identifies which accelerator table is active for a thread. The active accelerator table can be altered
                                   at any time by passing a dissimilar accelerator-table handle to TranslateAccelerator.

                                   7.11.2 Accelerator Table  Creation

                                   Several steps are required to create an accelerator table for an application. First, a resource
                                   compiler is used to create  accelerator-table resources  and to add them  to the  application's
                                   executable file. At run time, the LoadAccelerators function is used to load the accelerator table
                                   into memory and retrieve the handle to the accelerator table. This handle is  passed to the
                                   TranslateAccelerator function to activate the accelerator table.
                                   An accelerator table can also be created for an application at run time by passing an array of
                                   ACCEL structures to the CreateAcceleratorTable function. This method supports user-defined
                                   accelerators in the application. Like the LoadAccelerators function, CreateAcceleratorTable returns
                                   an accelerator-table handle that can be passed to TranslateAccelerator to activate the accelerator
                                   table.

                                   The system automatically destroys accelerator tables loaded by LoadAccelerators or created by
                                   CreateAcceleratorTable. However, an  application can  free resources  while it  is running  by
                                   destroying accelerator tables no longer needed by calling the DestroyAcceleratorTable function.
                                   An existing accelerator table can be copied and modified. The existing accelerator table is copied
                                   by using the CopyAcceleratorTable function. After the copy is modified, a handle to the new
                                   accelerator table is retrieved by calling CreateAcceleratorTable. Finally, the handle is passed to
                                   TranslateAccelerator to activate the new table.

                                   7.11.3 Accelerator Keystroke Assignments


                                   An ASCII character code or a virtual-key code can be used to define the accelerator. An ASCII
                                   character code makes the accelerator case sensitive. Thus, using the ASCII "C" character defines
                                   the accelerator as ALT+C rather than ALT+c. However, case-sensitive accelerators can be confusing
                                   to use. For example, the ALT+C accelerator will be generated if the CAPS LOCK key is down or
                                   if the SHIFT key is down, but not if both are down.
                                   Typically, accelerators don't need  to be case sensitive,  so most  applications use virtual-key
                                   codes for accelerators rather than ASCII character codes.




          120                               LOVELY PROFESSIONAL UNIVERSITY
   121   122   123   124   125   126   127   128   129   130   131