home *** CD-ROM | disk | FTP | other *** search
/ Microsoft Programmer's Library 1.3 / Microsoft-Programers-Library-v1.3.iso / sampcode / win_lrn / menu / gmenuiti.c < prev    next >
Text File  |  1988-08-10  |  2KB  |  70 lines

  1. /*
  2.  *  GetMenuItemID
  3.  *  
  4.  *  This program demonstrates the use of the function GetMenuItemID.
  5.  *  This function 
  6.  *  
  7.  *  Windows Version 2.0 function demonstration application
  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[] = "gmenuiti";
  21.   static char szFuncName[] = "GetMenuItemID";
  22.   HMENU hMenu;
  23.   WORD wID;
  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 ID of menu item Before", (LPSTR) szFuncName,
  55.      MB_OK);
  56.  
  57.   wID = GetMenuItemID ( hMenu, 0 );
  58.  
  59.   if ( wID != -1 )
  60.      {
  61.      sprintf ( szBuff, "%s%d", "ID of menu item Before is ", wID );
  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.