home *** CD-ROM | disk | FTP | other *** search
/ Microsoft Programmer's Library 1.3 / Microsoft-Programers-Library-v1.3.iso / sampcode / win_lrn / menu / drmenubr.c < prev    next >
Encoding:
C/C++ Source or Header  |  1988-08-11  |  2.5 KB  |  95 lines

  1. /*
  2.  *  Function Name:   DrawMenuBar
  3.  *
  4.  *  Description:
  5.  *   The program below will redraw a window's menu, usually with
  6.  *   modifications by ChangeMenu.  DrawMenuBar gives the same result as
  7.  *   SetMenu, but DrawMenuBar cannot initially create the menu bar like
  8.  *   SetMenu can.  The program below uses SetMenu to set and display
  9.  *   'Heading1'and uses DrawMenuBar to display the addition 'Heading2'
  10.  *   by ChangeMenu.
  11.  *
  12.  */
  13.  
  14. #include "windows.h"
  15.  
  16. long    FAR PASCAL WndProc (HWND, unsigned, WORD, LONG);
  17.  
  18. int     PASCAL WinMain (hInstance, hPrevInstance, lpszCmdLine, cmdShow)
  19. HANDLE    hInstance, hPrevInstance;
  20. LPSTR     lpszCmdLine;
  21. int       cmdShow;
  22.   {
  23.   MSG         msg;
  24.   HWND         hWnd;
  25.   WNDCLASS   wcClass;
  26.  
  27.   if (!hPrevInstance)
  28.     {
  29.     wcClass.style       = CS_HREDRAW | CS_VREDRAW;
  30.     wcClass.lpfnWndProc    = WndProc;
  31.     wcClass.cbClsExtra       = 0;
  32.     wcClass.cbWndExtra       = 0;
  33.     wcClass.hInstance       = hInstance;
  34.     wcClass.hIcon          = LoadIcon (hInstance, NULL);
  35.     wcClass.hCursor        = LoadCursor (NULL, IDC_ARROW);
  36.     wcClass.hbrBackground  = (HBRUSH)GetStockObject (WHITE_BRUSH);
  37.     wcClass.lpszMenuName   = NULL;
  38.     wcClass.lpszClassName  = "DrawMenuBar";
  39.  
  40.     if (!RegisterClass (&wcClass))
  41.       return FALSE;
  42.     }
  43.  
  44.   hWnd = CreateWindow ("DrawMenuBar",
  45.       "DrawMenuBar ()",
  46.       WS_OVERLAPPEDWINDOW,
  47.       CW_USEDEFAULT,
  48.       CW_USEDEFAULT,
  49.       CW_USEDEFAULT,
  50.       CW_USEDEFAULT,
  51.       NULL,
  52.       NULL,
  53.       hInstance,
  54.       NULL);
  55.   ShowWindow (hWnd, cmdShow);
  56.   UpdateWindow (hWnd);
  57.   while (GetMessage (&msg, NULL, 0, 0))
  58.     {
  59.     TranslateMessage (&msg);
  60.     DispatchMessage (&msg);
  61.     }
  62.   return msg.wParam;
  63.   }
  64.  
  65.  
  66. long    FAR PASCAL WndProc (hWnd, message, wParam, lParam)
  67. HWND      hWnd;
  68. unsigned  message;
  69. WORD      wParam;
  70. LONG      lParam;
  71.   {
  72.   HMENU      hCurrentWindowMenu;
  73.   unsigned   wIDItem;
  74.  
  75.   switch (message)
  76.     {
  77.     case WM_CREATE:
  78.       hCurrentWindowMenu = CreateMenu ();
  79.       ChangeMenu (hCurrentWindowMenu, NULL, "Heading1", wIDItem,
  80.                   MF_APPEND | MF_BYCOMMAND | MF_STRING);
  81.       SetMenu (hWnd, hCurrentWindowMenu);
  82.       ChangeMenu (hCurrentWindowMenu, NULL, "Heading2", wIDItem,
  83.                   MF_APPEND | MF_BYCOMMAND | MF_STRING);
  84.       DrawMenuBar (hWnd);
  85.       break;
  86.  
  87.     case WM_DESTROY:
  88.       PostQuitMessage (0);
  89.       break;
  90.     default:
  91.       return DefWindowProc (hWnd, message, wParam, lParam);
  92.     }
  93.   return (0L);
  94.   }
  95.