- /* return success */
- return (fRegistered = TRUE);
-} /* gaugeInit() */
-
-
-/** static void PASCAL gaugePaint(HWND hwnd, HDC hdc)
- *
- * DESCRIPTION:
- * This function is responsible for painting the zYzGauge control.
- *
- * ARGUMENTS:
- * HWND hwnd : The window handle for the gauge.
- *
- * HDC hdc : The DC for the gauge's window.
- *
- * RETURN (void):
- * The control will have been painted.
- *
- * NOTES:
- *
- ** cjp */
-
-static void PASCAL gaugePaint(HWND hwnd, HDC hdc)
-{
- PZYZGAUGE pgauge;
- WORD iRange, iPos;
- WORD Offset = 1;
- DWORD dwExtent;
- RECT rc1, rc2;
- HFONT hFont;
- char ach[ 6 ];
- WORD dx, dy, wGomerX, wGomerY;
-/* Win32s has no GetTextExtent(); let's try GetTextExtentPoint() instead,
- * which needs a SIZE* parameter */
-#if defined(__WIN32__)
- SIZE size;
-#endif
-
- /* get pointer to the control's control block */
-// pgauge = (PZYZGAUGE)GetWindowWord(hwnd, ZYZG_WW_PZYZGAUGE);
- pgauge = (PZYZGAUGE)GetWindowLong(hwnd, ZYZG_WW_PZYZGAUGE);
-
- /* set the colors into for the gauge into the control */
- SetTextColor(hdc, pgauge->rgbTextColor);
- SetBkColor(hdc, pgauge->rgbBkColor);
-
- /* draw black rectangle for gauge */
- GetClientRect(hwnd, &rc1);
-
- /* draw a black border on the _outside_ */
- FrameRect(hdc, &rc1, GetStockObject(BLACK_BRUSH));
-
- /* we want to draw _just inside_ the black border */
- InflateRect(&rc1, -1, -1);
-
- /* one line thick so far... */
-// Offset = (WORD) 1;
-
- /* for 3D stuff, we need to have at least two shades of gray */
- if ((GetWindowLong(hwnd, GWL_STYLE) & ZYZGS_3D) && fSupport3D)
- {
- Draw3DRect(hdc, &rc1, pgauge->wWidth3D, DRAW3D_OUT);
- InflateRect(&rc1, ~(pgauge->wWidth3D), ~(pgauge->wWidth3D));
-
- Draw3DFaceFrame(hdc, &rc1, pgauge->wWidthBezelFace);
- InflateRect(&rc1, ~(pgauge->wWidthBezelFace), ~(pgauge->wWidthBezelFace));
-
- Draw3DRect(hdc, &rc1, pgauge->wWidth3D, DRAW3D_IN);
- InflateRect(&rc1, ~(pgauge->wWidth3D), ~(pgauge->wWidth3D));
-
- /* draw a black border on the _inside_ */
- FrameRect(hdc, &rc1, GetStockObject(BLACK_BRUSH));
-
- /* we want to draw _just inside_ the black border */
- InflateRect(&rc1, -1, -1);
-
- /* add all the other pixels into the border width */
- Offset += (2 * pgauge->wWidth3D) + pgauge->wWidthBezelFace + 1;
- }
-
- /* dup--one rc for 'how much filled', one rc for 'how much empty' */
- rc2 = rc1;
-
- /* get the range--make sure it's a valid range */
- if ((iRange = pgauge->wRange) <= 0)
- iRange = 1;
-
- /* get the position--greater than 100% would be bad */
- if ((iPos = pgauge->wPosition) > iRange)
- iPos = iRange;
-
- /* compute the actual size of the gauge */
- dx = rc1.right - rc1.left;
- dy = rc1.bottom - rc1.top;
- wGomerX = (WORD)((DWORD)iPos * dx / iRange);
- wGomerY = (WORD)((DWORD)iPos * dy / iRange);
-
- /* get the orientation and munge rects accordingly */
- switch (pgauge->wOrientation)
- {
- case ZYZG_ORIENT_RIGHTTOLEFT:
- rc1.left = rc2.right = rc1.right - wGomerX;
- break;
-
- case ZYZG_ORIENT_BOTTOMTOTOP:
- rc1.top = rc2.bottom = rc1.bottom - wGomerY;
- break;
-
- case ZYZG_ORIENT_TOPTOBOTTOM:
- rc1.bottom = rc2.top += wGomerY;
- break;
-
- default:
- rc1.right = rc2.left += wGomerX;
- break;
- } /* switch () */
-
- /* select the correct font */
- hFont = SelectObject(hdc, pgauge->hFont);
-
- /* build up a string to blit out--ie the meaning of life: "42%" */
- wsprintf(ach, "%3d%%", (WORD)((DWORD)iPos * 100 / iRange));
-/* Win32s has no GetTextExtent(); let's try GetTextExtentPoint() instead */
-#if defined(__WIN32__)
- GetTextExtentPoint(hdc, ach, wGomerX = lstrlen(ach), &size);
- dwExtent = size.cx;
-#else
- dwExtent = GetTextExtent(hdc, ach, wGomerX = lstrlen(ach));
-#endif
-
-
- /* Draw the finished (ie the percent done) side of box. If
- * ZYZG_WW_POSITION is 42, (in range of 0 to 100) this ExtTextOut
- * draws the meaning of life (42%) bar.
- */
- ExtTextOut(hdc, (dx - LOWORD(dwExtent)) / 2 + Offset,
- (dy - HIWORD(dwExtent)) / 2 + Offset,
- ETO_OPAQUE | ETO_CLIPPED, &rc2, ach, wGomerX, NULL);
-
- /* Reverse fore and back colors for drawing the undone (ie the non-
- * finished) side of the box.
- */
- SetBkColor(hdc, pgauge->rgbTextColor);
- SetTextColor(hdc, pgauge->rgbBkColor);
-
- ExtTextOut(hdc, (dx - LOWORD(dwExtent)) / 2 + Offset,
- (dy - HIWORD(dwExtent)) / 2 + Offset,
- ETO_OPAQUE | ETO_CLIPPED, &rc1, ach, wGomerX, NULL);
-
- /* unselect the font */
- SelectObject(hdc, hFont);
-} /* gaugePaint() */
-
-
-/** LRESULT FAR PASCAL gaugeWndProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
- *
- * DESCRIPTION:
- * This is the control's window procedure. Its purpose is to handle
- * special messages for this custom control.
- *
- * The special control messages for the gauge control are:
- *
- * ZYZG_SETRANGE : Sets the range of the gauge. In other
- * words, the number of parts that make a
- * whole.
- *
- * ZYZG_GETRANGE : Returns the current range of the gauge.
- *
- * ZYZG_SETORIENTATION : Sets the orientation of the gauge. This
- * can be one of the ZYZG_ORIENT_?? msgs.
- *
- * ZYZG_GETORIENTATION : Gets the current orientation of the
- * gauge.
- *
- * ZYZG_SETPOSITION : Sets the current position of the gauge.
- * In other words, how many pieces of the
- * whole have been used.
- *
- * ZYZG_GETPOSITION : Gets the current position of the gauge.
- *
- * ZYZG_SETDELTAPOS : Sets the position of the gauge +/- the
- * specified amount.
- *
- * ZYZG_SETFGCOLOR : Sets the foreground (percent done) color.
- *
- * ZYZG_GETFGCOLOR : Gets the foreground (percent done) color.
- *
- * ZYZG_SETBKCOLOR : Sets the background (percent not done)
- * color.
- *
- * ZYZG_GETBKCOLOR : Gets the background (percent not done)
- * color.
- *
- * WM_SETFONT : Sets the font to use for the percentage
- * text of the gauge.
- *
- * WM_GETFONT : Gets the current font in use by the
- * gauge.
- *
- * NOTES:
- *
- ** cjp */
-
-/* LRESULT FAR PASCAL */
-
-LRESULT APIENTRY _EXPORT gaugeWndProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
-{
- HFONT hFont;
- PAINTSTRUCT ps;
- PZYZGAUGE pgauge;
- RECT rc;
-
-// pgauge = (PZYZGAUGE)GetWindowWord(hwnd, ZYZG_WW_PZYZGAUGE);
- pgauge = (PZYZGAUGE)GetWindowLong(hwnd, ZYZG_WW_PZYZGAUGE);
-
- /* break to get DefWindowProc() */
- switch (uMsg)
- {
- case WM_CREATE:
- /* need to allocate a control block */
-// pgauge = (PZYZGAUGE)LocalAlloc(LPTR, sizeof(ZYZGAUGE));
- pgauge = (PZYZGAUGE)malloc(sizeof(ZYZGAUGE));
- if (!pgauge)
- return (0L);
-
- /* hang on to this control block */
-// SetWindowWord(hwnd, ZYZG_WW_PZYZGAUGE, (WORD)pgauge);
- SetWindowLong(hwnd, ZYZG_WW_PZYZGAUGE, (LONG)pgauge);
-
- /* fill control block with defaults */
- pgauge->wRange = ZYZG_DEF_RANGE;
- pgauge->wPosition = ZYZG_DEF_POSITION;
- pgauge->wOrientation = ZYZG_DEF_ORIENTATION;
- pgauge->wWidth3D = ZYZG_DEF_WIDTH3D;
- pgauge->wWidthBezelFace = ZYZG_DEF_BEZELFACE;
- pgauge->rgbTextColor = rgbDefTextColor;
- pgauge->rgbBkColor = rgbDefBkColor;
-
- /* use system font */
- SendMessage(hwnd, WM_SETFONT, (WPARAM)NULL, 0L);
-
- /* go to DefWindowProc() to finish the job */
- break;
-
- case WM_DESTROY:
- /* get rid of the control's memory */
- if (pgauge)
-// LocalFree((HANDLE)pgauge);
- free(pgauge);
- break;
-
- case ZYZG_GETPOSITION:
- return (pgauge->wPosition);
-
- case ZYZG_GETRANGE:
- return (pgauge->wRange);
-
- case ZYZG_GETORIENTATION:
- return (pgauge->wOrientation);
-
- case ZYZG_GETWIDTH3D:
- return (pgauge->wWidth3D);
-
- case ZYZG_GETBEZELFACE:
- return (pgauge->wWidthBezelFace);
-
- case ZYZG_GETBKCOLOR:
- return (pgauge->rgbTextColor);
-
- case ZYZG_GETFGCOLOR:
- return (pgauge->rgbBkColor);
-
- case ZYZG_SETBKCOLOR:
- pgauge->rgbBkColor = lParam;
- return (0L);
-
- case ZYZG_SETFGCOLOR:
- pgauge->rgbTextColor = lParam;
- return (0L);
-
-
- case ZYZG_SETPOSITION:
- pgauge->wPosition = wParam;
-
-zyzgForceRepaint:
- GetClientRect(hwnd, &rc);
- if ((GetWindowLong(hwnd, GWL_STYLE) & ZYZGS_3D) && fSupport3D)
- {
- wParam = (2 * pgauge->wWidth3D) +
- pgauge->wWidthBezelFace + 2;
- }
-
- else
- wParam = 1;
-
- InflateRect(&rc, ~(wParam), ~(wParam));
- InvalidateRect(hwnd, &rc, FALSE);
- UpdateWindow(hwnd);
- return (0L);
-
- case ZYZG_SETRANGE:
- pgauge->wRange = wParam;
- goto zyzgForceRepaint;
-
- case ZYZG_SETORIENTATION:
- pgauge->wOrientation = wParam;
- goto zyzgForceRepaint;
-
- case ZYZG_SETWIDTH3D:
- pgauge->wWidth3D = wParam;
-
-zyzgForceRepaint3D:
- InvalidateRect(hwnd, NULL, FALSE);
- UpdateWindow(hwnd);
- return (0L);
-
- case ZYZG_SETBEZELFACE:
- pgauge->wWidthBezelFace = wParam;
- goto zyzgForceRepaint3D;
-
- case ZYZG_SETDELTAPOS:
-/* Watcom doesn't like the following line so removing typecasts */
-/* (int)pgauge->wPosition += (int)wParam; */
- pgauge->wPosition += wParam;
- goto zyzgForceRepaint;
-
- case WM_PAINT:
- BeginPaint(hwnd, &ps);
- gaugePaint(hwnd, ps.hdc);
- EndPaint(hwnd, &ps);
- return (0L);
-
- case WM_GETFONT:
- hFont = pgauge->hFont;
-
- /* if system font, then return NULL handle */
- return (long)((hFont == GetStockObject(SYSTEM_FONT)) ? NULL : hFont);
-
- case WM_SETFONT:
- /* if NULL hFont, use system font */
- if (!(hFont = (HFONT)wParam))
- hFont = GetStockObject(SYSTEM_FONT);
-
- pgauge->hFont = hFont;
-
- /* redraw if indicated in message */
- if ((BOOL)lParam)
- {
- InvalidateRect(hwnd, NULL, TRUE);
- UpdateWindow(hwnd);
- }
- return (0L);
- } /* switch () */
-
- /* let the dialog mangler take care of this message */
- return (DefWindowProc(hwnd, uMsg, wParam, lParam));
-} /* gaugeWndProc() */
-
-
-/** EOF: zyzgauge.c **/
-
-#endif // USE_GAUGE