home *** CD-ROM | disk | FTP | other *** search
/ Media Share 9 / MEDIASHARE_09.ISO / mag&info / ptv3n5.zip / STATUS.ARJ / STATUS.CPP < prev    next >
C/C++ Source or Header  |  1992-08-28  |  4KB  |  124 lines

  1. // status.cpp -- TStatusBar class implementation
  2.  
  3. #include <owl.h>
  4. #pragma hdrstop
  5. #include "status.h"
  6.  
  7. // Construct TStatusBar object
  8. TStatusBar::TStatusBar(PTWindowsObject AParent)
  9.   : TWindow(AParent, NULL)
  10. {
  11.   Attr.Style = WS_CHILD | WS_VISIBLE | WS_BORDER;
  12.   Attr.X = 0;     // Actual coordinates set later
  13.   Attr.Y = 0;     //    "    "    "    "    "
  14.   Attr.W = 0;     // Actual dimensions set later
  15.   Attr.H = 0;     //    "    "    "    "    "
  16.   currentID = 0;  // Displays blank string
  17.   if (AParent == NULL)  // Child windows must have parents
  18.     Status = EM_INVALIDCHILD;
  19. }
  20.  
  21. // Perform initializations requiring a window handle
  22. void TStatusBar::SetupWindow()
  23. {
  24.   TEXTMETRIC tm;  // Text "metrics" (i.e. specifications)
  25.  
  26. // Call base class member function
  27.   TWindow::SetupWindow();
  28.  
  29. // Calculate height of child status-bar window
  30.   HDC hDC = GetDC(HWindow);
  31.   GetTextMetrics(hDC, &tm);
  32.   ReleaseDC(HWindow, hDC);
  33.   childHeight = tm.tmHeight + (tm.tmHeight / 3);
  34.  
  35. // Initialize popup menu handles for easy identification
  36.   HMENU hmenu = GetMenu(Parent->HWindow);
  37.   hmenuSystem = GetSystemMenu(Parent->HWindow, 0);
  38.   hmenuFile = GetSubMenu(hmenu, 0);
  39.   hmenuEdit = GetSubMenu(hmenu, 1);
  40. }
  41.  
  42. // Modify window's registered class
  43. void TStatusBar::GetWindowClass(WNDCLASS &AWndClass)
  44. {
  45.   TWindow::GetWindowClass(AWndClass);
  46.   AWndClass.hbrBackground = (HBRUSH)GetStockObject(LTGRAY_BRUSH);
  47. }
  48.  
  49. // Give registered class a name
  50. LPSTR TStatusBar::GetClassName()
  51. {
  52.   return "TStatusBar";
  53. }
  54.  
  55. // Adjust child window size to match parent window
  56. void TStatusBar::AdjustSize(WORD parentWidth, WORD parentHeight)
  57. {
  58.   int x = 0, y = parentHeight - childHeight + 1;
  59.   MoveWindow(HWindow, x, y, parentWidth, childHeight, TRUE);
  60. }
  61.  
  62. // Show on-line message according to menu selection
  63. void TStatusBar::WMMenuSelect(RTMessage msg)
  64. {
  65.   WORD wIDItem = msg.WParam;       // ID or popup menu handle
  66.   WORD fwMenu = msg.LP.Lo;         // Message flags
  67.   HMENU hmenu = (HMENU)msg.LP.Hi;  // NULL or system menu handle
  68.   int resourceID = 0;
  69.  
  70. // Set a flag if menu is closing (so we can erase the string)
  71.   int menuClosing = ((fwMenu == 0xffff) && (hmenu == 0));
  72.  
  73. // Select message IDs for menu names (e.g. File and Edit)
  74.   if (fwMenu & MF_POPUP) {
  75.     if ((HMENU)wIDItem == hmenuSystem)
  76.       resourceID = 1;
  77.     else if ((HMENU)wIDItem == hmenuFile)
  78.       resourceID = 2;
  79.     else if ((HMENU)wIDItem == hmenuEdit)
  80.       resourceID = 3;
  81.   }
  82.  
  83. // Select message IDs for menu commands (e.g. File|Open)
  84.   else if (!menuClosing)
  85.     resourceID = wIDItem;
  86.  
  87. // Display selected string; zero to erase status bar
  88.   DisplayString(resourceID);
  89. }
  90.  
  91. // Display string in child window
  92. void TStatusBar::DisplayString(int resourceID)
  93. {
  94.   RECT r;
  95.   char s[128];
  96.  
  97. // Load string from resource string table
  98.   s[0] = 0;
  99.   if (resourceID != 0)
  100.     LoadString(GetApplication()->hInstance,
  101.     resourceID, s, sizeof(s));
  102.   currentID = resourceID;  // Save ID for Paint()
  103.  
  104. // Draw background and "chiseled steel" border
  105.   GetClientRect(HWindow, &r);
  106.   HDC hDC = GetDC(HWindow);
  107.   OffsetRect(&r, 1, 1);
  108.   FillRect(hDC, &r, (HBRUSH)GetStockObject(LTGRAY_BRUSH));
  109.   FrameRect(hDC, &r, (HBRUSH)GetStockObject(DKGRAY_BRUSH));
  110.   OffsetRect(&r, -1, -1);
  111.   FrameRect(hDC, &r, (HBRUSH)GetStockObject(WHITE_BRUSH));
  112.  
  113. // Draw text in child status-bar window
  114.   SetBkMode(hDC, TRANSPARENT);
  115.   ExtTextOut(hDC, 4, 0, ETO_CLIPPED, &r, s, lstrlen(s), NULL);
  116.   ReleaseDC(HWindow, hDC);
  117. }
  118.  
  119. // Redisplay current string in status-bar window
  120. void TStatusBar::Paint(HDC, PAINTSTRUCT &)
  121. {
  122.   DisplayString(currentID);
  123. }
  124.