home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Windoware
/
WINDOWARE_1_6.iso
/
winutil
/
adg_4_6
/
meter.c
< prev
next >
Wrap
C/C++ Source or Header
|
1991-02-21
|
6KB
|
178 lines
/****************************************************************************
Module name: Meter.C
Programmer : Jeffrey M. Richter.
*****************************************************************************/
#include "..\nowindws.h"
#define OEMRESOURCE
#undef NOCOLOR
#undef NOCTLMGR
#undef NODRAWTEXT
#undef NOGDI
#undef NOKERNEL
#undef NOLSTRING
#undef NOMEMMGR
#undef NORASTEROPS
#undef NOUSER
#undef NOVIRTUALKEYCODES
#undef NOWINMESSAGES
#undef NOWINOFFSETS
#undef NOWINSTYLES
#include <windows.h>
#include "meter.h"
HANDLE _hInstance = NULL;
char _szControlName[] = "Meter";
#define CBWNDEXTRA (4)
#define GWW_PARTSINJOB (0)
#define GWW_PARTSCOMPLETE (2)
static short NEAR PASCAL RegisterControlClass (HANDLE hInstance);
LONG FAR PASCAL MeterWndFn (HWND hWnd, WORD wMsg, WORD wParam, LONG lParam);
/********* Window's Dynamic-Link Library Initialization Routines ***********/
BOOL FAR PASCAL LibMain (HANDLE hModule, WORD wDataSeg, WORD wHeapSize, LPSTR lpszCmdLine) {
BOOL fOk;
_hInstance = hModule;
if (wHeapSize != 0) UnlockData(0); // Let data segment move
fOk = RegisterControlClass(hModule);
return(fOk); // return TRUE if initialization is successful
}
int FAR PASCAL WEP (int nSystemExit) {
switch (nSystemExit) {
case WEP_SYSTEM_EXIT: // System is shutting down.
break;
case WEP_FREE_DLL: // Usage count is zero (0).
break;
}
UnregisterClass(_szControlName, _hInstance);
return(1); // WEP function successful.
}
static short NEAR PASCAL RegisterControlClass (HANDLE hInstance) {
WNDCLASS wc;
wc.style = CS_GLOBALCLASS | CS_HREDRAW | CS_VREDRAW;
wc.lpfnWndProc = MeterWndFn;
wc.cbClsExtra = 0;
wc.cbWndExtra = CBWNDEXTRA;
wc.hInstance = hInstance;
wc.hIcon = NULL;
wc.hCursor = LoadCursor(NULL, IDC_ARROW);
wc.hbrBackground = NULL;
wc.lpszMenuName = NULL;
wc.lpszClassName = _szControlName;
return(RegisterClass(&wc));
}
LONG FAR PASCAL MeterWndFn (HWND hWnd, WORD wMsg, WORD wParam, LONG lParam) {
LONG lResult = 0;
char szPercentage[10];
RECT rcClient, rcPrcnt;
PAINTSTRUCT ps;
WORD wPartsInJob, wPartsComplete;
HBRUSH hBrush;
DWORD dwColor;
switch (wMsg) {
case WM_GETDLGCODE:
lResult = DLGC_STATIC;
break;
case WM_CREATE: // lParam == &CreateStruct
SendMessage(hWnd, MM_SETPARTSINJOB, 100, 0l);
SendMessage(hWnd, MM_SETPARTSCOMPLETE, 50, 0);
break;
case WM_PAINT:
wPartsInJob = (WORD) SendMessage(hWnd, MM_GETPARTSINJOB, 0, 0l);
wPartsComplete = (WORD) SendMessage(hWnd, MM_GETPARTSCOMPLETE, 0, 0l);
if (wPartsInJob == 0) {
wPartsInJob = 1;
wPartsComplete = 0;
}
wsprintf(szPercentage, "%d%%", (100 * wPartsComplete) / wPartsInJob);
BeginPaint(hWnd, &ps);
// Set-up default foreground and background text colors.
SetBkColor(ps.hdc, GetSysColor(COLOR_WINDOW));
SetTextColor(ps.hdc, GetSysColor(COLOR_WINDOWTEXT));
// Send WM_CTLCOLOR message to parent in case parent want to
// use a different color in the Meter control.
hBrush = (HBRUSH) SendMessage(GetParent(hWnd), WM_CTLCOLOR, ps.hdc,
MAKELONG(hWnd, CTLCOLOR_METER));
// Always use brush returned by parent.
SelectObject(ps.hdc, hBrush);
SetTextAlign(ps.hdc, TA_CENTER | TA_TOP);
// Invert the foreground and background colors.
dwColor = GetBkColor(ps.hdc);
SetBkColor(ps.hdc, SetTextColor(ps.hdc, dwColor));
// Set rectangle coordinates to include only left
// percentage of the window.
GetClientRect(hWnd, &rcClient);
SetRect(&rcPrcnt, 0, 0,
(rcClient.right * wPartsComplete) / wPartsInJob, rcClient.bottom);
// Output the percentage value in the window.
// Function also paints left part of window.
ExtTextOut(ps.hdc, rcClient.right / 2,
(rcClient.bottom - HIWORD(GetTextExtent(ps.hdc, "X", 1))) / 2,
ETO_OPAQUE | ETO_CLIPPED, &rcPrcnt,
szPercentage, lstrlen(szPercentage), NULL);
// Adjust rectangle so that it includes the remaining
// percentage of the window.
rcPrcnt.left = rcPrcnt.right;
rcPrcnt.right = rcClient.right;
// Invert the foreground and background colors.
dwColor = GetBkColor(ps.hdc);
SetBkColor(ps.hdc, SetTextColor(ps.hdc, dwColor));
// Output the percentage value a second time in the window.
// Function also paints right part of window.
ExtTextOut(ps.hdc, rcClient.right / 2,
(rcClient.bottom - HIWORD(GetTextExtent(ps.hdc, "X", 1))) / 2,
ETO_OPAQUE | ETO_CLIPPED, &rcPrcnt,
szPercentage, lstrlen(szPercentage), NULL);
EndPaint(hWnd, &ps);
break;
case MM_SETPARTSINJOB:
SetWindowWord(hWnd, GWW_PARTSINJOB, wParam);
InvalidateRect(hWnd, NULL, FALSE);
UpdateWindow(hWnd);
break;
case MM_GETPARTSINJOB:
lResult = (LONG) GetWindowWord(hWnd, GWW_PARTSINJOB);
break;
case MM_SETPARTSCOMPLETE:
SetWindowWord(hWnd, GWW_PARTSCOMPLETE, wParam);
InvalidateRect(hWnd, NULL, FALSE);
UpdateWindow(hWnd);
break;
case MM_GETPARTSCOMPLETE:
lResult = (LONG) GetWindowWord(hWnd, GWW_PARTSCOMPLETE);
break;
default:
lResult = DefWindowProc(hWnd, wMsg, wParam, lParam);
break;
}
return(lResult);
}