home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 10 / 10.iso / m / m003_1 / sb_bc.ddi / BC / CH6 / WMENU-2.C < prev    next >
Encoding:
C/C++ Source or Header  |  1991-11-18  |  3.4 KB  |  130 lines

  1. /***    Windows Application --- Menu example     ***/
  2. /***                                             ***/
  3. /***    WMENU-2 includes                         ***/
  4. /***            (1) WMENU-2.C                    ***/
  5. /***            (2) WMENU-2.RES                  ***/
  6. /***            (3) WMENU-2.DEF                  ***/
  7.  
  8. #pragma hdrfile "windows.sym"
  9. #include <windows.h>
  10. #pragma hdrstop
  11.  
  12. #include "wmenu.h"
  13.  
  14. // Declaration
  15.  
  16. void InitFirstInstance(HANDLE) ;
  17. void InitEachInstance(HANDLE, int) ;
  18. long FAR PASCAL AppWndProc (HWND, WORD, WORD, LONG) ;
  19.  
  20. static char  szAppName[]  = "WinMenu" ;
  21. static char  szMenuName[] = "WMenu" ;
  22. HWND  hwnd ;
  23.  
  24. // Definition
  25.  
  26. int PASCAL WinMain(HANDLE hInstance,
  27.            HANDLE hPrevInstance,
  28.            LPSTR  lpszCmdLine,
  29.            int    nCmdShow)
  30. { MSG msg ;
  31.  
  32.   if ( !hPrevInstance ) InitFirstInstance(hInstance) ;
  33.  
  34.   InitEachInstance(hInstance,nCmdShow) ;
  35.  
  36.   while ( GetMessage(&msg, NULL, 0, 0) )
  37.     { TranslateMessage(&msg) ;
  38.       DispatchMessage(&msg) ;
  39.     }
  40.   return msg.wParam ;
  41. }
  42.  
  43.  
  44. void InitFirstInstance(HANDLE hInstance)
  45. { WNDCLASS wndclass ;
  46.  
  47.   wndclass.style      = CS_HREDRAW | CS_VREDRAW ;
  48.   wndclass.lpfnWndProc      = AppWndProc ;
  49.   wndclass.cbClsExtra       = 0 ;
  50.   wndclass.cbWndExtra      = 0 ;
  51.   wndclass.hInstance      = hInstance ;
  52.   wndclass.hIcon             = LoadIcon(NULL,IDI_APPLICATION) ;
  53.   wndclass.hCursor      = LoadCursor(NULL,IDC_ARROW) ;
  54.   wndclass.hbrBackground  = GetStockObject(WHITE_BRUSH) ;
  55.   wndclass.lpszMenuName      = szMenuName ;
  56.   wndclass.lpszClassName  = szAppName ;
  57.  
  58.   RegisterClass(&wndclass) ;
  59. }
  60.  
  61.  
  62. void InitEachInstance(HANDLE hInstance, int nCmdShow)
  63. {
  64.   hwnd = CreateWindow(szAppName,               // window class name
  65.               "Windows Application", // window caption
  66.               WS_OVERLAPPEDWINDOW ,
  67.               CW_USEDEFAULT,      // initial x position
  68.               0,                  // initial y position
  69.               CW_USEDEFAULT,      // initial x length
  70.               0,                  // initial y length
  71.               NULL,               // parent window handle
  72.               NULL,               // window menu handle
  73.               hInstance,          // program instance handle
  74.               NULL) ;             // parameters
  75.  
  76.   ShowWindow(hwnd,nCmdShow) ;
  77.   UpdateWindow(hwnd) ;
  78. }
  79.  
  80.  
  81. long FAR PASCAL AppWndProc (HWND hwnd,
  82.                 WORD message,
  83.                 WORD wParam,
  84.                 LONG lParam)
  85. { static WORD Cursor_Check = IDM_CURSOR1,
  86.           Icon_Check   = IDM_ICON1,
  87.           Bitmap_Check = IDM_BITMAP1 ;
  88.   HMENU hMenu ;
  89.  
  90.   switch (message)
  91.     { case WM_COMMAND :
  92.        hMenu = GetMenu(hwnd) ;
  93.        switch(wParam)
  94.          { case IDM_CURSOR1 :
  95.            case IDM_CURSOR2 :
  96.            case IDM_CURSOR3 :
  97.             CheckMenuItem(hMenu, Cursor_Check, MF_UNCHECKED) ;
  98.             Cursor_Check = wParam ;
  99.             CheckMenuItem(hMenu, Cursor_Check, MF_CHECKED) ;
  100.             break ;
  101.  
  102.            case IDM_ICON1 :
  103.            case IDM_ICON2 :
  104.             CheckMenuItem(hMenu, Icon_Check, MF_UNCHECKED) ;
  105.             Icon_Check = wParam ;
  106.             CheckMenuItem(hMenu, Icon_Check, MF_CHECKED) ;
  107.             break ;
  108.  
  109.            case IDM_BITMAP1 :
  110.            case IDM_BITMAP2 :
  111.            case IDM_BITMAP3 :
  112.             CheckMenuItem(hMenu, Bitmap_Check, MF_UNCHECKED) ;
  113.             Bitmap_Check = wParam ;
  114.             CheckMenuItem(hMenu, Bitmap_Check, MF_CHECKED) ;
  115.             break ;
  116.          }
  117.        break ;
  118.  
  119.       case WM_DESTROY :
  120.        PostQuitMessage(0) ;
  121.        break ;
  122.  
  123.       default :
  124.        return DefWindowProc(hwnd, message, wParam, lParam) ;
  125.     }
  126.  
  127.   return 0 ;
  128. }
  129.  
  130.