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

  1. /*
  2.  *   HiliteMenuItem
  3.  *
  4.  *   This program demonstrates the use of the HiliteMenuItem function. The
  5.  *   HiliteMenuItem function hilites or removes hiliting from an item in a
  6.  *   menu. In this program, the 4th item in the system menu was hilited in
  7.  *   the WinMain procedure.
  8.  */
  9.  
  10. #include "windows.h"
  11.  
  12. long    FAR PASCAL HelloWndProc (HWND, unsigned, WORD, LONG);
  13.  
  14. /* Procedure called when the application is loaded for the first time */
  15. BOOL HelloInit (hInstance)
  16. HANDLE hInstance;
  17.   {
  18.   PWNDCLASS   pHelloClass;
  19.  
  20.   pHelloClass = (PWNDCLASS)LocalAlloc (LPTR, sizeof (WNDCLASS));
  21.  
  22.   pHelloClass->hCursor        = LoadCursor (NULL, IDC_ARROW);
  23.   pHelloClass->hIcon             = LoadIcon (hInstance, NULL);
  24.   pHelloClass->lpszMenuName   = (LPSTR)NULL;
  25.   pHelloClass->lpszClassName     = (LPSTR)"Sample Application";
  26.   pHelloClass->hbrBackground  = (HBRUSH)GetStockObject (WHITE_BRUSH);
  27.   pHelloClass->hInstance      = hInstance;
  28.   pHelloClass->style          = CS_HREDRAW | CS_VREDRAW;
  29.   pHelloClass->lpfnWndProc    = HelloWndProc;
  30.  
  31.   if (!RegisterClass ( (LPWNDCLASS)pHelloClass))
  32.     return FALSE;
  33.  
  34.   LocalFree ( (HANDLE)pHelloClass);
  35.   return TRUE;        /* Initialization succeeded */
  36.   }
  37.  
  38. int     PASCAL WinMain (hInstance, hPrevInstance, lpszCmdLine, cmdShow)
  39. HANDLE hInstance, hPrevInstance;
  40. LPSTR lpszCmdLine;
  41. int    cmdShow;
  42.   {
  43.   MSG   msg;
  44.   HWND  hWnd;
  45.   HMENU hMenu;
  46.  
  47.   HelloInit (hInstance);
  48.   hWnd = CreateWindow ( (LPSTR)"Sample Application",
  49.       (LPSTR)"Sample Application",
  50.       WS_OVERLAPPEDWINDOW,
  51.       CW_USEDEFAULT,
  52.       CW_USEDEFAULT,
  53.       CW_USEDEFAULT,
  54.       CW_USEDEFAULT,
  55.       (HWND)NULL,        /* no parent */
  56.   (HMENU)NULL,       /* use class menu */
  57.   (HANDLE)hInstance, /* handle to window instance */
  58.   (LPSTR)NULL        /* no params to pass on */
  59.  );
  60.  
  61. /*** get the handle to the system menu *********************************/
  62.   hMenu = GetSystemMenu (hWnd, FALSE);
  63.  
  64. /*** hilite the 4th item in the system menu *****************************/
  65.   HiliteMenuItem (hWnd, hMenu, 3, MF_BYPOSITION | MF_HILITE);
  66.  
  67. /* Make window visible according to the way the app is activated */
  68.   ShowWindow (hWnd, cmdShow);
  69.   UpdateWindow (hWnd);
  70.  
  71.   MessageBox (hWnd, (LPSTR)" ...the fourth menu-item will be hilited.",
  72.       (LPSTR)"  Click on the System Menu and...  ", MB_OK);
  73.  
  74. /* Polling messages from event queue */
  75.   while (GetMessage ( (LPMSG) & msg, NULL, 0, 0))
  76.     {
  77.     TranslateMessage ( (LPMSG) & msg);
  78.     DispatchMessage ( (LPMSG) & msg);
  79.     }
  80.  
  81.   return (int)msg.wParam;
  82.   }
  83.  
  84. /* Procedures which make up the window class. */
  85. long    FAR PASCAL HelloWndProc (hWnd, message, wParam, lParam)
  86. HWND     hWnd;
  87. unsigned message;
  88. WORD     wParam;
  89. LONG     lParam;
  90.   {
  91.   switch (message)
  92.     {
  93.     case WM_DESTROY:
  94.       PostQuitMessage (0);
  95.       break;
  96.  
  97.     default:
  98.       return DefWindowProc (hWnd, message, wParam, lParam);
  99.     }
  100.   return (0L);
  101.   }
  102.