home *** CD-ROM | disk | FTP | other *** search
/ Microsoft Programmer's Library 1.3 / Microsoft-Programers-Library-v1.3.iso / sampcode / win_lrn / accell / transacc.lst < prev    next >
Encoding:
File List  |  1988-08-11  |  9.4 KB  |  234 lines

  1.  
  2.  
  3.  
  4.                                                                        PAGE   1
  5.                                                                        08-01-88
  6.                                                                        10:24:03
  7.  
  8.  Line#  Source Line                           Microsoft C Compiler Version 5.10
  9.  
  10.       1  /*
  11.       2   *  TranslateAccelerator
  12.       3   *  transacc.c
  13.       4   *
  14.       5   * This program demonstrates the use of the function TranslateAccelera
  15.          tor.
  16.       6   * When the function keys F9 or F10 are pressed then a message box app
  17.          ears
  18.       7   * which notifies the user that the TranslateAccelerator function has
  19.       8   * successfully converted and dispatched an accelerator message.
  20.       9   *
  21.      10   * All messages to this application are first passed to the
  22.      11   * TranslateAccelerator function.  TranslateAccelerator will compare
  23.      12   * the message to a predefined accelerator to see if they match.  If
  24.      13   * the message doesn't match then TranslateAccelerator returns a 0,
  25.      14   * and the message will be processed normally using TranslateMessage
  26.      15   * and DispatchMessage.  If they do match, the message is an accelerat
  27.          or,
  28.      16   * and the routine translates the message into a WM_COMMAND or
  29.      17   * WM_SYSCOMMAND message.
  30.      18   */
  31.      19  
  32.      20  #include <windows.h>
  33.      21  #include "transacc.h"
  34.      22  
  35.      23  static HANDLE hInst;
  36.      24  
  37.      25  int     PASCAL WinMain (hInstance, hPrevInstance, lpszCmdLine, cmdShow
  38.          )
  39.      26  HANDLE    hInstance, hPrevInstance;
  40.      27  LPSTR     lpszCmdLine;
  41.      28  int       cmdShow;
  42.      29    {
  43.      30    MSG       msg;
  44.      31    HWND      hWnd;
  45.      32    BOOL      bDecrementDisplayCount = 0;
  46.      33    BOOL      bIncrementDisplayCount = 1;
  47.      34    short     nResult;
  48.      35    WNDCLASS  Class;
  49.      36  
  50.      37    Class.lpfnWndProc    = TransAccelWindowProc;
  51.      38    Class.hCursor        = LoadCursor (NULL, IDC_ARROW);
  52.      39    Class.lpszMenuName   = MAKEINTRESOURCE (TRANSACCELMENU1);
  53.      40    Class.lpszClassName  = (LPSTR)"Window";
  54.      41    Class.hbrBackground  = (HBRUSH)GetStockObject (WHITE_BRUSH);
  55.      42    Class.hInstance      = hInstance;
  56.      43    Class.style          = CS_HREDRAW | CS_VREDRAW;
  57.      44  
  58.      45    if (!RegisterClass ( (LPWNDCLASS)&Class))
  59.      46      return FALSE;
  60.      47  
  61.      48    hInst = hInstance;
  62.      49  
  63.      50    hWnd = CreateWindow ( (LPSTR)"Window",
  64.      51                       (LPSTR)"ShowCaret",
  65.      52                       WS_OVERLAPPEDWINDOW,
  66.  
  67.  
  68.  
  69.                                                                        PAGE   2
  70.                                                                        08-01-88
  71.                                                                        10:24:03
  72.  
  73.  Line#  Source Line                           Microsoft C Compiler Version 5.10
  74.  
  75.      53                       CW_USEDEFAULT,          /* x         */
  76.      54                       CW_USEDEFAULT,          /* y         */
  77.      55                       CW_USEDEFAULT,          /* width     */
  78.      56                       CW_USEDEFAULT,          /* height    */
  79.      57                       (HWND)NULL,             /* no parent */
  80.      58                       (HMENU)NULL,            /* use class menu */
  81.      59                       (HANDLE)hInstance,      /* handle to window insta
  82.          nce */
  83.      60                       (LPSTR)NULL);           /* no params to pass on *
  84.          /
  85.      61  
  86.      62    ShowWindow (hWnd, cmdShow);
  87.      63    UpdateWindow (hWnd);
  88.      64  
  89.      65    while (GetMessage ( (LPMSG) & msg, NULL, 0, 0))
  90.      66      if (TranslateAccelerator (msg.hwnd, LoadAccelerators (hInstance,
  91.      67          MAKEINTRESOURCE (TRANSACCELMENU1)), (LPMSG) & msg) == 1)
  92.      68        MessageBox (hWnd, (LPSTR)"TranslateAccelerator processed a messa
  93.          ge",
  94.      69            (LPSTR)"Done", MB_OK);
  95.      70      else
  96.      71        {
  97.      72        TranslateMessage ( (LPMSG) & msg);
  98.      73        DispatchMessage ( (LPMSG) & msg);
  99.      74        }
  100.      75  
  101.      76    return TRUE;
  102.      77    }
  103.  
  104.  
  105. WinMain  Local Symbols
  106.  
  107. Name                      Class   Type              Size   Offset  Register
  108.  
  109. nResult . . . . . . . . . auto                             -0034 
  110. bDecrementDisplayCount. . auto                             -0032 
  111. msg . . . . . . . . . . . auto                             -0030 
  112. bIncrementDisplayCount. . auto                             -001e 
  113. Class . . . . . . . . . . auto                             -001c 
  114. hWnd. . . . . . . . . . . auto                             -0002 
  115. cmdShow . . . . . . . . . param                             0004
  116. lpszCmdLine . . . . . . . param                             0006
  117. hPrevInstance . . . . . . param                             000a
  118. hInstance . . . . . . . . param                             000c
  119.  
  120.      78  
  121.      79  long    FAR PASCAL TransAccelWindowProc (hWnd, message, wParam, lParam
  122.          )
  123.      80  HWND     hWnd;
  124.      81  unsigned message;
  125.      82  WORD     wParam;
  126.      83  LONG     lParam;
  127.      84    {
  128.      85    switch (message)
  129.      86      {
  130.      87      case WM_COMMAND:
  131.  
  132.  
  133.  
  134.                                                                        PAGE   3
  135.                                                                        08-01-88
  136.                                                                        10:24:03
  137.  
  138.  Line#  Source Line                           Microsoft C Compiler Version 5.10
  139.  
  140.      88        TransAccelMenuProc (hWnd, wParam);
  141.      89        break;
  142.      90  
  143.      91      default:
  144.      92        return (DefWindowProc (hWnd, message, wParam, lParam));
  145.      93        break;
  146.      94      }
  147.      95    return (0L);
  148.      96    }
  149.  
  150.  
  151. TransAccelWindowProc  Local Symbols
  152.  
  153. Name                      Class   Type              Size   Offset  Register
  154.  
  155. lParam. . . . . . . . . . param                             0006
  156. wParam. . . . . . . . . . param                             000a
  157. message . . . . . . . . . param                             000c
  158. hWnd. . . . . . . . . . . param                             000e
  159.  
  160.      97  
  161.      98  void TransAccelMenuProc (hWnd, wId)
  162.      99  HWND hWnd;
  163.     100  WORD wId;
  164.     101    {
  165.     102    HMENU hMenu;
  166.     103  
  167.     104    switch (wId)
  168.     105      {
  169.     106      case ID_NEXT:
  170.     107        hMenu = GetMenu (hWnd);  /*  Get the old menu  */
  171.     108        DestroyMenu (hMenu);     /*  Get rid of it  */
  172.     109        hMenu = LoadMenu (hInst, MAKEINTRESOURCE (TRANSACCELMENU2));
  173.     110        SetMenu (hWnd, hMenu);
  174.     111        DrawMenuBar (hWnd);
  175.     112        break;
  176.     113  
  177.     114      case ID_PREV:
  178.     115        hMenu = GetMenu (hWnd);  /*  Get the old menu  */
  179.     116        DestroyMenu (hMenu);     /*  Get rid of it  */
  180.     117        hMenu = LoadMenu (hInst, MAKEINTRESOURCE (TRANSACCELMENU1));
  181.     118        SetMenu (hWnd, hMenu);
  182.     119        DrawMenuBar (hWnd);
  183.     120        break;
  184.     121      }
  185.     122    }
  186.  
  187.  
  188. TransAccelMenuProc  Local Symbols
  189.  
  190. Name                      Class   Type              Size   Offset  Register
  191.  
  192. hMenu . . . . . . . . . . auto                             -0002 
  193. hWnd. . . . . . . . . . . param                             0004
  194. wId . . . . . . . . . . . param                             0006
  195.  
  196.  
  197.  
  198.  
  199.                                                                        PAGE   4
  200.                                                                        08-01-88
  201.                                                                        10:24:03
  202.  
  203.                                               Microsoft C Compiler Version 5.10
  204.  
  205. Global Symbols
  206.  
  207. Name                      Class   Type              Size   Offset  
  208.  
  209. CreateWindow. . . . . . . extern  far function       ***     ***
  210. DefWindowProc . . . . . . extern  far function       ***     ***
  211. DestroyMenu . . . . . . . extern  far function       ***     ***
  212. DispatchMessage . . . . . extern  far function       ***     ***
  213. DrawMenuBar . . . . . . . extern  far function       ***     ***
  214. GetMenu . . . . . . . . . extern  far function       ***     ***
  215. GetMessage. . . . . . . . extern  far function       ***     ***
  216. GetStockObject. . . . . . extern  far function       ***     ***
  217. LoadAccelerators. . . . . extern  far function       ***     ***
  218. LoadCursor. . . . . . . . extern  far function       ***     ***
  219. LoadMenu. . . . . . . . . extern  far function       ***     ***
  220. MessageBox. . . . . . . . extern  far function       ***     ***
  221. RegisterClass . . . . . . extern  far function       ***     ***
  222. SetMenu . . . . . . . . . extern  far function       ***     ***
  223. ShowWindow. . . . . . . . extern  far function       ***     ***
  224. TransAccelMenuProc. . . . global  near function      ***    01aa
  225. TransAccelWindowProc. . . global  far function       ***    0147
  226. TranslateAccelerator. . . extern  far function       ***     ***
  227. TranslateMessage. . . . . extern  far function       ***     ***
  228. UpdateWindow. . . . . . . extern  far function       ***     ***
  229. WinMain . . . . . . . . . global  near function      ***    0000
  230. hInst . . . . . . . . . . static  unsigned int         2    0000
  231. pLocalHeap. . . . . . . . common  near pointer         2     ***
  232.  
  233. Code size = 0250 (592)
  234. Data size = 0046 (70)
  235. Bss size  = 0002 (2)
  236.  
  237. No errors detected
  238.