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

  1. /*
  2.  *  Function Name:   CreateMenu
  3.  *
  4.  *  Description:
  5.  *   This program creates a blank menu that the user can fill in from the
  6.  *   program instead of the resource file.  ChangeMenu must be used to enter
  7.  *   the heading and items of the menu.  The program below will add the menu
  8.  *   called "Heading" to the menu bar in CurrentWindowMenu.
  9.  */
  10.  
  11. #include "windows.h"
  12.  
  13. long    FAR PASCAL WndProc (HWND, unsigned, WORD, LONG);
  14.  
  15. int     PASCAL WinMain (hInstance, hPrevInstance, lpszCmdLine, cmdShow)
  16. HANDLE hInstance, hPrevInstance;
  17. LPSTR lpszCmdLine;
  18. int    cmdShow;
  19.   {
  20.   MSG   msg;
  21.   HWND  hWnd;
  22.   HMENU hMenu;
  23.  
  24.   if (!hPrevInstance)
  25.     {
  26.     WNDCLASS   wcClass;
  27.  
  28.     wcClass.style          = CS_HREDRAW | CS_VREDRAW;
  29.     wcClass.lpfnWndProc    = WndProc;
  30.     wcClass.cbClsExtra     = 0;
  31.     wcClass.cbWndExtra     = 0;
  32.     wcClass.hInstance      = hInstance;
  33.     wcClass.hIcon          = LoadIcon (hInstance, NULL);
  34.     wcClass.hCursor        = LoadCursor (NULL, IDC_ARROW);
  35.     wcClass.hbrBackground  = (HBRUSH)GetStockObject (WHITE_BRUSH);
  36.     wcClass.lpszMenuName   = (LPSTR)NULL;
  37.     wcClass.lpszClassName  = (LPSTR)"CreateMenu";
  38.  
  39.     if (!RegisterClass ( (LPWNDCLASS) & wcClass))
  40.       return FALSE;
  41.     }
  42.  
  43.   hMenu = CreateMenu ();
  44.   ChangeMenu (hMenu, NULL, "MenuItem", 100, MF_APPEND);
  45.  
  46.   hWnd = CreateWindow ( (LPSTR)"CreateMenu",
  47.                       (LPSTR)"CreateMenu ()",
  48.                       WS_OVERLAPPEDWINDOW,
  49.                       CW_USEDEFAULT,
  50.                       CW_USEDEFAULT,
  51.                       CW_USEDEFAULT,
  52.                       CW_USEDEFAULT,
  53.                       (HWND)NULL,        /* no parent */
  54.                       (HMENU)hMenu,      /* use our menu */
  55.                       (HANDLE)hInstance, /* handle to window instance */
  56.                       (LPSTR)NULL);      /* no params to pass on */
  57.  
  58.   ShowWindow (hWnd, cmdShow);
  59.   UpdateWindow (hWnd);
  60.  
  61.   while (GetMessage ( (LPMSG) & msg, NULL, 0, 0))
  62.     {
  63.     TranslateMessage ( (LPMSG) & msg);
  64.     DispatchMessage ( (LPMSG) & msg);
  65.     }
  66.   return (int)msg.wParam;
  67.   }
  68.  
  69. /* Procedures which make up the window class. */
  70. long    FAR PASCAL WndProc (hWnd, message, wParam, lParam)
  71. HWND      hWnd;
  72. unsigned  message;
  73. WORD      wParam;
  74. LONG      lParam;
  75.   {
  76.   switch (message)
  77.     {
  78.     case WM_DESTROY:
  79.       PostQuitMessage (0);
  80.       break;
  81.  
  82.     default:
  83.       return DefWindowProc (hWnd, message, wParam, lParam);
  84.     }
  85.   return (0L);
  86.   }
  87.