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

  1. /*
  2.  *
  3.  *  GetMenu
  4.  *  
  5.  *  This program demonstrates the use of the function GetMenu.
  6.  *  This function retrieves a handle to the menu of the specified window.
  7.  *
  8.  */
  9.  
  10. #include <windows.h>
  11. #include "getmenu.h"
  12.  
  13. long FAR PASCAL GMWndProc (HWND, unsigned int, WORD, LONG);
  14.  
  15. static HANDLE hWnd;
  16.  
  17. int PASCAL WinMain(hInstance, hPrevInstance, lpszCmdLine, cmdShow)
  18. HANDLE hInstance, hPrevInstance;
  19. LPSTR  lpszCmdLine;
  20. int    cmdShow;
  21. {
  22.   static char szFileName[] = "getmenu";
  23.   static char szFuncName[] = "GetMenu";
  24.   MSG   msg;
  25.   HMENU hMenu;
  26.   
  27.   if (!hPrevInstance)
  28.      {
  29.      WNDCLASS rClass;
  30.  
  31.      rClass.lpszClassName = (LPSTR)szFileName;
  32.      rClass.hInstance     = hInstance;
  33.      rClass.lpfnWndProc   = DefWindowProc;
  34.      rClass.hCursor       = LoadCursor(NULL, IDC_ARROW);
  35.      rClass.hIcon         = LoadIcon(hInstance, IDI_APPLICATION);
  36.      rClass.lpszMenuName  = (LPSTR)"GetMenuFunc";
  37.      rClass.hbrBackground = GetStockObject(WHITE_BRUSH);
  38.      rClass.style         = CS_HREDRAW | CS_VREDRAW;
  39.      rClass.cbClsExtra    = 0;
  40.      rClass.cbWndExtra    = 0;
  41.    
  42.      RegisterClass((LPWNDCLASS)&rClass);
  43.      }
  44.  
  45.   hWnd = CreateWindow((LPSTR)szFileName, (LPSTR)szFuncName,
  46.                       WS_OVERLAPPEDWINDOW,
  47.                       CW_USEDEFAULT, CW_USEDEFAULT,
  48.                       CW_USEDEFAULT, CW_USEDEFAULT,
  49.                       (HWND)NULL, (HMENU)NULL,
  50.                       (HANDLE)hInstance, (LPSTR)NULL);
  51.  
  52.    ShowWindow(hWnd, cmdShow);
  53.    UpdateWindow(hWnd);
  54.  
  55.    MessageBox(GetFocus(), (LPSTR)"Getting Menu Handle",
  56.               (LPSTR)"GetMenu()", MB_OK);
  57.    hMenu = GetMenu(hWnd);
  58.    if (hMenu == NULL)
  59.       MessageBox(GetFocus(), (LPSTR)"Error In Getting Menu Handle",
  60.                  (LPSTR)"GetMenu()", MB_OK);
  61.    else
  62.       MessageBox(GetFocus(), (LPSTR)"Menu Handle Obtained Successfully",
  63.                  (LPSTR)"GetMenu()", MB_OK);
  64.    EnableMenuItem(hMenu, ENTRY_1, MF_BYCOMMAND | MF_GRAYED);
  65.    DrawMenuBar(hWnd);
  66.    MessageBox(GetFocus(), (LPSTR)"'Item_1' Grayed",
  67.               (LPSTR)"GetMenu()", MB_OK);
  68.  
  69.   return 0;
  70. }
  71.  
  72.