home *** CD-ROM | disk | FTP | other *** search
/ The World of Computer Software / World_Of_Computer_Software-02-385-Vol-1of3.iso / m / msgbar10.zip / SOURCE.EXE / SAMPLE.C < prev    next >
C/C++ Source or Header  |  1992-12-29  |  7KB  |  227 lines

  1. /*****************************************************************************
  2.  
  3. *       FILE:           SAMPLE.C
  4.  
  5. *       PURPOSE:        Sample appliction showing the use of the Message Bar
  6.  
  7. *       Copyright 1992-1993 Paul King, All rights reserved.
  8.  
  9. *       Revision History:
  10.  
  11. *       Date        Name        Description
  12.         ----        ----        -----------
  13. *       12/29/92    Paul King   Original version
  14.  
  15. *****************************************************************************/
  16.  
  17. #define STRICT
  18. #include <windows.h>
  19. #include "sample.h"
  20.  
  21. //Header file for Message Bar functions
  22. #include "mb.h"
  23.  
  24. //Prototypes
  25. LPARAM FAR PASCAL MainDlgProc(HWND, UINT, WPARAM, LPARAM);
  26.  
  27.  
  28. //Global variables
  29. HINSTANCE   hInst;
  30. HMENU       hMenu;
  31.  
  32. //Internal Definitions
  33. #define     GREY    RGB (192, 192, 192)
  34. #define     WHITE   RGB (0, 0, 0)
  35.  
  36. /*****************************************************************************
  37.  
  38. *       Funciton:       WinMain(HINSTANCE, HINSTANCE, LPSTR, int)
  39.  
  40. *       Purpose:        Application entry point
  41.  
  42. *****************************************************************************/
  43.  
  44. int PASCAL WinMain(HINSTANCE hInstance, HINSTANCE hPrevInst,
  45.                    LPSTR lpszCmdLine, int nCmdShow)
  46. {
  47. static char     szAppName[] = "MessageBar";
  48. HWND            hWnd;
  49. MSG             msg;
  50. WNDCLASS        wc;
  51.  
  52.     hInst = hInstance;
  53.  
  54.     if (!hPrevInst)
  55.         {
  56.         wc.style            = CS_HREDRAW | CS_VREDRAW;
  57.         wc.lpfnWndProc      = (WNDPROC) MainDlgProc;
  58.         wc.cbClsExtra       = 0;
  59.         wc.cbWndExtra       = 0;
  60.         wc.hInstance        = hInst;
  61.         wc.hIcon            = LoadIcon (hInst, szAppName);
  62.         wc.hCursor          = LoadCursor (NULL, IDC_ARROW);
  63.         wc.hbrBackground    = (HBRUSH) (COLOR_WINDOW + 1);
  64.         wc.lpszMenuName     = szAppName;
  65.         wc.lpszClassName    = szAppName;
  66.  
  67.         RegisterClass (&wc);
  68.         }
  69.     
  70.     //Load the Menu
  71.     hMenu = LoadMenu (hInst, szAppName);
  72.  
  73.     hWnd = CreateWindow (szAppName, "Sample Application",
  74.             WS_OVERLAPPEDWINDOW | WS_CLIPCHILDREN, CW_USEDEFAULT,
  75.             CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, NULL, 
  76.             hMenu, hInst, NULL);
  77.  
  78.     ShowWindow (hWnd, nCmdShow);
  79.     UpdateWindow (hWnd);
  80.  
  81.     while (GetMessage (&msg, NULL, 0, 0))
  82.         {
  83.         TranslateMessage (&msg);
  84.         DispatchMessage (&msg);
  85.         }
  86.  
  87.     return msg.wParam;
  88.  
  89. }
  90.  
  91.  
  92.  
  93.  
  94. /*****************************************************************************
  95.  
  96. *       Function:       MainDlgProc(HWND, UINT, WPARAM, LPARAM)
  97.  
  98. *       Purpose:        Application callback function
  99.  
  100. *****************************************************************************/
  101.  
  102. LPARAM FAR PASCAL MainDlgProc(HWND hDlg, UINT msg, WPARAM wParam,
  103.                               LPARAM lParam)
  104.  
  105. {
  106. static  BOOL    bMessageBar;
  107.         BOOL    bState;
  108.  
  109.     switch (msg)
  110.         {
  111.         case WM_CREATE:
  112.             //Init the Message Bar
  113.             bMessageBar = InitMB (hDlg, hInst, GREY, WHITE, TRUE);
  114.  
  115.             return TRUE;
  116.         
  117.         case WM_CTLCOLOR:
  118.             //Needed to color our message bar
  119.             return ColorMB (wParam, lParam);
  120.         
  121.         case WM_SIZE:
  122.             //Needed to resize the message bar
  123.             ResizeMB();
  124.             break;
  125.  
  126.         case WM_MENUSELECT:
  127.  
  128.             //Display some help text to the user in the status bar
  129.  
  130.             if ((LOWORD (lParam) == -1) && (HIWORD (lParam) == 0))
  131.                 //User left the menu.  Clear the message text
  132.                 MBText ("");
  133.  
  134.             else
  135.                 {
  136.                 switch (LOWORD (lParam) & (MF_POPUP | MF_SYSMENU))
  137.                     {
  138.                     case 0:
  139.                         //wParam is a menu ID from a nonsystem menu
  140.                         //Make sure it is not a separator
  141.                         if (wParam)
  142.                             switch ((int) wParam)
  143.                                 {
  144.                                 case IDM_EXIT:
  145.                                     MBText ("Terminate this application");
  146.                                     break;
  147.  
  148.                                 case IDM_MBAR:
  149.                                     MBText ("Turn the Message Bar ON or OFF");
  150.                                     break;
  151.  
  152.                                 case IDM_JUNK1:
  153.                                     MBText ("Bogus Message 1");
  154.                                     break;
  155.  
  156.                                 case IDM_JUNK2:
  157.                                     MBText ("Bogus Message 2");
  158.                                     break;
  159.  
  160.                                 case IDM_JUNK3:
  161.                                     MBText ("Bogus Message 3");
  162.                                     break;
  163.                                 }
  164.                         else
  165.                             MBText ("");
  166.                         break;
  167.  
  168.                     case MF_POPUP:
  169.                         //wParam is handle to a nonsystem popup menu
  170.                         MBText ("");
  171.                         break;
  172.  
  173.                     case MF_SYSMENU:
  174.                         //wParam is a menu ID from the system menu
  175.                         MBText ("");
  176.                         break;
  177.  
  178.                     case MF_POPUP | MF_SYSMENU:
  179.                         //wParam is the handle to the system menu
  180.                         MBText ("");
  181.                         break;
  182.                     }
  183.                 }
  184.  
  185.             break;
  186.  
  187.         case WM_COMMAND:
  188.             switch (wParam)
  189.                 {
  190.                 case IDM_EXIT:
  191.                     DestroyWindow (hDlg);
  192.                     break;
  193.  
  194.                 case IDM_MBAR:
  195.                     bState = GetMenuState (hMenu, IDM_MBAR, 
  196.                              MF_BYCOMMAND) & MF_CHECKED;
  197.  
  198.                     //Turn the Message Bar ON or OFF
  199.                     MBShow (!bState);
  200.  
  201.                     //Toggle menuitem
  202.                     CheckMenuItem (hMenu, IDM_MBAR, MF_BYCOMMAND | 
  203.                                   (bState ? MF_UNCHECKED : MF_CHECKED));
  204.                     break;
  205.  
  206.                 }
  207.  
  208.             return FALSE;
  209.                 
  210.         case WM_CLOSE:
  211.             DestroyWindow (hDlg);
  212.             return FALSE;
  213.  
  214.         case WM_DESTROY:
  215.             //If our Message bar was created, delete it
  216.             if (bMessageBar)
  217.                 KillMB ();
  218.  
  219.             PostQuitMessage (0);
  220.             return FALSE;
  221.             
  222.         }
  223.  
  224.     return DefWindowProc (hDlg, msg, wParam, lParam);
  225.  
  226. }
  227.