home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
The World of Computer Software
/
World_Of_Computer_Software-02-385-Vol-1of3.iso
/
p
/
ptv3n5.zip
/
STATUS.ZIP
/
STATUS.CPP
< prev
next >
Wrap
C/C++ Source or Header
|
1992-08-28
|
4KB
|
124 lines
// status.cpp -- TStatusBar class implementation
#include <owl.h>
#pragma hdrstop
#include "status.h"
// Construct TStatusBar object
TStatusBar::TStatusBar(PTWindowsObject AParent)
: TWindow(AParent, NULL)
{
Attr.Style = WS_CHILD | WS_VISIBLE | WS_BORDER;
Attr.X = 0; // Actual coordinates set later
Attr.Y = 0; // " " " " "
Attr.W = 0; // Actual dimensions set later
Attr.H = 0; // " " " " "
currentID = 0; // Displays blank string
if (AParent == NULL) // Child windows must have parents
Status = EM_INVALIDCHILD;
}
// Perform initializations requiring a window handle
void TStatusBar::SetupWindow()
{
TEXTMETRIC tm; // Text "metrics" (i.e. specifications)
// Call base class member function
TWindow::SetupWindow();
// Calculate height of child status-bar window
HDC hDC = GetDC(HWindow);
GetTextMetrics(hDC, &tm);
ReleaseDC(HWindow, hDC);
childHeight = tm.tmHeight + (tm.tmHeight / 3);
// Initialize popup menu handles for easy identification
HMENU hmenu = GetMenu(Parent->HWindow);
hmenuSystem = GetSystemMenu(Parent->HWindow, 0);
hmenuFile = GetSubMenu(hmenu, 0);
hmenuEdit = GetSubMenu(hmenu, 1);
}
// Modify window's registered class
void TStatusBar::GetWindowClass(WNDCLASS &AWndClass)
{
TWindow::GetWindowClass(AWndClass);
AWndClass.hbrBackground = (HBRUSH)GetStockObject(LTGRAY_BRUSH);
}
// Give registered class a name
LPSTR TStatusBar::GetClassName()
{
return "TStatusBar";
}
// Adjust child window size to match parent window
void TStatusBar::AdjustSize(WORD parentWidth, WORD parentHeight)
{
int x = 0, y = parentHeight - childHeight + 1;
MoveWindow(HWindow, x, y, parentWidth, childHeight, TRUE);
}
// Show on-line message according to menu selection
void TStatusBar::WMMenuSelect(RTMessage msg)
{
WORD wIDItem = msg.WParam; // ID or popup menu handle
WORD fwMenu = msg.LP.Lo; // Message flags
HMENU hmenu = (HMENU)msg.LP.Hi; // NULL or system menu handle
int resourceID = 0;
// Set a flag if menu is closing (so we can erase the string)
int menuClosing = ((fwMenu == 0xffff) && (hmenu == 0));
// Select message IDs for menu names (e.g. File and Edit)
if (fwMenu & MF_POPUP) {
if ((HMENU)wIDItem == hmenuSystem)
resourceID = 1;
else if ((HMENU)wIDItem == hmenuFile)
resourceID = 2;
else if ((HMENU)wIDItem == hmenuEdit)
resourceID = 3;
}
// Select message IDs for menu commands (e.g. File|Open)
else if (!menuClosing)
resourceID = wIDItem;
// Display selected string; zero to erase status bar
DisplayString(resourceID);
}
// Display string in child window
void TStatusBar::DisplayString(int resourceID)
{
RECT r;
char s[128];
// Load string from resource string table
s[0] = 0;
if (resourceID != 0)
LoadString(GetApplication()->hInstance,
resourceID, s, sizeof(s));
currentID = resourceID; // Save ID for Paint()
// Draw background and "chiseled steel" border
GetClientRect(HWindow, &r);
HDC hDC = GetDC(HWindow);
OffsetRect(&r, 1, 1);
FillRect(hDC, &r, (HBRUSH)GetStockObject(LTGRAY_BRUSH));
FrameRect(hDC, &r, (HBRUSH)GetStockObject(DKGRAY_BRUSH));
OffsetRect(&r, -1, -1);
FrameRect(hDC, &r, (HBRUSH)GetStockObject(WHITE_BRUSH));
// Draw text in child status-bar window
SetBkMode(hDC, TRANSPARENT);
ExtTextOut(hDC, 4, 0, ETO_CLIPPED, &r, s, lstrlen(s), NULL);
ReleaseDC(HWindow, hDC);
}
// Redisplay current string in status-bar window
void TStatusBar::Paint(HDC, PAINTSTRUCT &)
{
DisplayString(currentID);
}