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

  1. /*
  2.  *
  3.  *  GetMenuItemCount
  4.  *  
  5.  *  This program demonstrates the use of the function GetMenuItemCount.
  6.  *  This function determines the number of items in the menu identifed by
  7.  *  the parameter.  This may be either a pop-up of top-level menu.
  8.  *  
  9.  */
  10.  
  11. #include <windows.h>
  12.  
  13. static HANDLE hWnd;
  14.  
  15. int PASCAL WinMain( hInstance, hPrevInstance, lpszCmdLine, cmdShow )
  16. HANDLE hInstance, hPrevInstance;
  17. LPSTR  lpszCmdLine;
  18. int    cmdShow;
  19. {
  20.   static char szFileName[] = "gmenuitc";
  21.   static char szFuncName[] = "GetMenuItemCount";
  22.   HMENU hMenu;
  23.   WORD wCount;
  24.   char szBuff[80];
  25.   
  26.   if ( !hPrevInstance )
  27.      {
  28.      WNDCLASS rClass;
  29.  
  30.      rClass.lpszClassName = ( LPSTR ) szFileName;
  31.      rClass.hInstance     = hInstance;
  32.      rClass.lpfnWndProc   = DefWindowProc;
  33.      rClass.hCursor       = LoadCursor ( NULL , IDC_ARROW );
  34.      rClass.hIcon         = LoadIcon ( hInstance, IDI_APPLICATION );
  35.      rClass.lpszMenuName  = ( LPSTR ) "GetMenuItemCountFunc";
  36.      rClass.hbrBackground = GetStockObject ( WHITE_BRUSH );
  37.      rClass.style         = CS_HREDRAW | CS_VREDRAW;
  38.      rClass.cbClsExtra    = 0;
  39.      rClass.cbWndExtra    = 0;
  40.    
  41.      RegisterClass ( ( LPWNDCLASS ) &rClass );
  42.      }
  43.  
  44.   hWnd = CreateWindow ( ( LPSTR ) szFileName, ( LPSTR ) szFuncName,
  45.                       WS_OVERLAPPEDWINDOW,
  46.                       CW_USEDEFAULT, CW_USEDEFAULT,
  47.                       CW_USEDEFAULT, CW_USEDEFAULT,
  48.                       ( HWND ) NULL, ( HMENU ) NULL,
  49.                       ( HANDLE ) hInstance, ( LPSTR ) NULL );
  50.  
  51.   ShowWindow ( hWnd , cmdShow );
  52.   hMenu = GetMenu ( hWnd );
  53.   
  54.   MessageBox (NULL, (LPSTR)"Getting number of menu items", (LPSTR) szFuncName,
  55.      MB_OK);
  56.  
  57.   wCount = GetMenuItemCount ( hMenu );
  58.  
  59.   if ( wCount != -1 )
  60.      {
  61.      sprintf ( szBuff, "%s%d", "Number of menu items is ", wCount );
  62.      MessageBox (NULL, (LPSTR) szBuff, (LPSTR) szFuncName, MB_OK);
  63.      }
  64.   else
  65.      MessageBox (NULL, (LPSTR)"Error", (LPSTR) szFuncName,
  66.         MB_OK|MB_ICONEXCLAMATION);
  67.  
  68.   return 0;
  69. }
  70.