]>
git.saurik.com Git - wxWidgets.git/blob - src/msw/gaugemsw.cpp
1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: wxGaugeMSW class
4 // Author: Julian Smart
8 // Copyright: (c) Julian Smart and Markus Holzem
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
13 #pragma implementation "gauge.h"
16 // For compilers that support precompilation, includes "wx.h".
17 #include "wx/wxprec.h"
29 #include "wx/msw/gaugemsw.h"
30 #include "wx/msw/private.h"
32 /* gas gauge graph control messages--class "zYzGauge" */
33 #define ZYZG_SETRANGE (WM_USER + 0)
34 #define ZYZG_GETRANGE (WM_USER + 1)
35 #define ZYZG_SETPOSITION (WM_USER + 2)
36 #define ZYZG_GETPOSITION (WM_USER + 3)
37 #define ZYZG_SETORIENTATION (WM_USER + 4)
38 #define ZYZG_GETORIENTATION (WM_USER + 5)
39 #define ZYZG_SETFGCOLOR (WM_USER + 6)
40 #define ZYZG_GETFGCOLOR (WM_USER + 7)
41 #define ZYZG_SETBKCOLOR (WM_USER + 8)
42 #define ZYZG_GETBKCOLOR (WM_USER + 9)
43 #define ZYZG_SETWIDTH3D (WM_USER + 10)
44 #define ZYZG_GETWIDTH3D (WM_USER + 11)
45 #define ZYZG_SETBEZELFACE (WM_USER + 12)
46 #define ZYZG_GETBEZELFACE (WM_USER + 13)
47 #define ZYZG_SETDELTAPOS (WM_USER + 14)
50 /* orientations for ZYZG_WW_ORIENTATION */
51 #define ZYZG_ORIENT_LEFTTORIGHT 0
52 #define ZYZG_ORIENT_RIGHTTOLEFT 1
53 #define ZYZG_ORIENT_BOTTOMTOTOP 2
54 #define ZYZG_ORIENT_TOPTOBOTTOM 3
57 #define ZYZGS_3D 0x8000L /* control will be 3D */
59 /* public function prototypes */
60 BOOL FAR PASCAL
gaugeInit(HINSTANCE hInstance
);
62 #if !USE_SHARED_LIBRARY
63 IMPLEMENT_DYNAMIC_CLASS(wxGaugeMSW
, wxControl
)
66 bool wxGaugeMSW::Create(wxWindow
*parent
, const wxWindowID id
,
71 const wxValidator
& validator
,
74 static bool wxGaugeMSWInitialised
= FALSE
;
76 if ( !wxGaugeMSWInitialised
)
78 if (!gaugeInit((HWND
) wxGetInstance()))
79 wxFatalError("Cannot initalize Gauge library");
80 wxGaugeMSWInitialised
= TRUE
;
84 SetValidator(validator
);
86 if (parent
) parent
->AddChild(this);
89 SetBackgroundColour(parent
->GetDefaultBackgroundColour()) ;
90 SetForegroundColour(parent
->GetDefaultForegroundColour()) ;
92 m_windowStyle
= style
;
95 m_windowId
= (int)NewControlId();
104 long msFlags
= WS_CHILD
| WS_VISIBLE
| WS_TABSTOP
;
108 CreateWindowEx(MakeExtendedStyle(m_windowStyle
), "zYzGauge", NULL
, msFlags
,
109 0, 0, 0, 0, (HWND
) parent
->GetHWND(), (HMENU
)m_windowId
,
110 wxGetInstance(), NULL
);
112 m_hWnd
= (WXHWND
)wx_button
;
114 // Subclass again for purposes of dialog editing mode
115 SubclassWin((WXHWND
)wx_button
);
119 if (m_windowStyle
& wxGA_HORIZONTAL
)
120 wOrient
= ZYZG_ORIENT_LEFTTORIGHT
;
122 wOrient
= ZYZG_ORIENT_BOTTOMTOTOP
;
124 SendMessage(wx_button
, ZYZG_SETORIENTATION
, wOrient
, 0);
125 SendMessage(wx_button
, ZYZG_SETRANGE
, range
, 0);
127 SendMessage((HWND
) GetHWND(), ZYZG_SETFGCOLOR
, 0, RGB(GetForegroundColour().Red(), GetForegroundColour().Green(), GetForegroundColour().Blue()));
128 SendMessage((HWND
) GetHWND(), ZYZG_SETBKCOLOR
, 0, RGB(GetBackgroundColour().Red(), GetBackgroundColour().Green(), GetBackgroundColour().Blue()));
130 SetFont(* parent
->GetFont());
136 SetSize(x
, y
, width
, height
);
138 ShowWindow((HWND
) GetHWND(), SW_SHOW
);
143 void wxGaugeMSW::SetSize(const int x
, const int y
, const int width
, const int height
, const int sizeFlags
)
145 int currentX
, currentY
;
146 GetPosition(¤tX
, ¤tY
);
152 if (x
== -1 || (sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
))
154 if (y
== -1 || (sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
))
157 // If we're prepared to use the existing size, then...
158 if (width
== -1 && height
== -1 && ((sizeFlags
& wxSIZE_AUTO
) != wxSIZE_AUTO
))
163 // Deal with default size (using -1 values)
165 w1
= DEFAULT_ITEM_WIDTH
;
168 h1
= DEFAULT_ITEM_HEIGHT
;
170 MoveWindow((HWND
) GetHWND(), x1
, y1
, w1
, h1
, TRUE
);
172 #if WXWIN_COMPATIBILITY
173 GetEventHandler()->OldOnSize(width
, height
);
175 wxSizeEvent
event(wxSize(width
, height
), m_windowId
);
176 event
.eventObject
= this;
177 GetEventHandler()->ProcessEvent(event
);
181 void wxGaugeMSW::SetShadowWidth(const int w
)
183 SendMessage((HWND
) GetHWND(), ZYZG_SETWIDTH3D
, w
, 0);
186 void wxGaugeMSW::SetBezelFace(const int w
)
188 SendMessage((HWND
) GetHWND(), ZYZG_SETBEZELFACE
, w
, 0);
191 void wxGaugeMSW::SetRange(const int r
)
195 SendMessage((HWND
) GetHWND(), ZYZG_SETRANGE
, r
, 0);
198 void wxGaugeMSW::SetValue(const int pos
)
202 SendMessage((HWND
) GetHWND(), ZYZG_SETPOSITION
, pos
, 0);
205 int wxGaugeMSW::GetShadowWidth(void) const
207 return (int) SendMessage((HWND
) GetHWND(), ZYZG_GETWIDTH3D
, 0, 0);
210 int wxGaugeMSW::GetBezelFace(void) const
212 return (int) SendMessage((HWND
) GetHWND(), ZYZG_GETBEZELFACE
, 0, 0);
215 int wxGaugeMSW::GetRange(void) const
217 return (int) SendMessage((HWND
) GetHWND(), ZYZG_GETRANGE
, 0, 0);
220 int wxGaugeMSW::GetValue(void) const
222 return (int) SendMessage((HWND
) GetHWND(), ZYZG_GETPOSITION
, 0, 0);
225 void wxGaugeMSW::SetForegroundColour(const wxColour
& col
)
227 m_foregroundColour
= col
;
228 SendMessage((HWND
) GetHWND(), ZYZG_SETFGCOLOR
, 0, RGB(col
.Red(), col
.Green(), col
.Blue()));
231 void wxGaugeMSW::SetBackgroundColour(const wxColour
& col
)
233 m_backgroundColour
= col
;
234 SendMessage((HWND
) GetHWND(), ZYZG_SETBKCOLOR
, 0, RGB(col
.Red(), col
.Green(), col
.Blue()));
241 * This module contains functions for creating nifty 3D borders
242 * around controls like zYzGauge.
245 * 3/14/91 cjp put in this comment
246 * 6/19/92 cjp touched it a bit
251 // (C) Copyright Microsoft Corp. 1992. All rights reserved.
253 // You have a royalty-free right to use, modify, reproduce and
254 // distribute the Sample Files (and/or any modified version) in
255 // any way you find useful, provided that you agree that
256 // Microsoft has no warranty obligations or liability for any
257 // Sample Application Files which are modified.
261 /* get the includes we need */
264 /* misc. control flag defines */
265 #define DRAW3D_IN 0x0001
266 #define DRAW3D_OUT 0x0002
268 #define DRAW3D_TOPLINE 0x0004
269 #define DRAW3D_BOTTOMLINE 0x0008
270 #define DRAW3D_LEFTLINE 0x0010
271 #define DRAW3D_RIGHTLINE 0x0020
274 /* public function prototypes */
275 void FAR PASCAL
Draw3DFaceFrame(HDC
, LPRECT
, WORD
);
276 void FAR PASCAL
Draw3DRect(HDC
, LPRECT
, WORD
, WORD
);
277 void FAR PASCAL
Draw3DLine(HDC
, WORD
, WORD
, WORD
, WORD
, WORD
);
280 /** void FAR PASCAL Draw3DFaceFrame(HDC hdc, LPRECT rc, WORD wWidth)
283 * This function draws a flat frame with the current button-face
287 * HDC hdc : The DC to draw into.
289 * LPRECT rc : The containing rect for the new frame.
291 * WORD wWidth : The width of the frame to draw.
293 * RETURN (void FAR PASCAL):
294 * The frame will have been drawn into the DC.
300 void FAR PASCAL
Draw3DFaceFrame(HDC hdc
, LPRECT rc
, WORD wWidth
)
305 /* don't go through a bunch of work if we don't have to */
309 /* set up color to be button-face color--so it may not be gray */
310 rgbOld
= SetBkColor(hdc
, GetSysColor(COLOR_BTNFACE
));
312 /* perform CopyRect w/o bloody windows style overhead */
318 rc1
.bottom
= rc
->top
+ wWidth
;
319 rc1
.right
= rc
->right
;
322 ExtTextOut(hdc
, rc1
.left
, rc1
.top
, ETO_OPAQUE
, &rc1
, NULL
, 0, NULL
);
325 rc1
.left
= rc
->right
- wWidth
;
326 rc1
.bottom
= rc
->bottom
;
328 /* blast this part now */
329 ExtTextOut(hdc
, rc1
.left
, rc1
.top
, ETO_OPAQUE
, &rc1
, NULL
, 0, NULL
);
333 rc1
.right
= rc
->left
+ wWidth
;
335 /* and another part */
336 ExtTextOut(hdc
, rc1
.left
, rc1
.top
, ETO_OPAQUE
, &rc1
, NULL
, 0, NULL
);
339 rc1
.right
= rc
->right
;
340 rc1
.top
= rc
->bottom
- wWidth
;
343 ExtTextOut(hdc
, rc1
.left
, rc1
.top
, ETO_OPAQUE
, &rc1
, NULL
, 0, NULL
);
345 /* restore the old bk color */
346 SetBkColor(hdc
, rgbOld
);
347 } /* Draw3DFaceFrame() */
350 /** void FAR PASCAL Draw3DRect(HDC, LPRECT, WORD, WORD)
353 * Draws a 3D rectangle that is shaded. wFlags can be used to
354 * control how the rectangle looks.
357 * HDC hdc : Handle to the device context that will be
358 * used to display the rectangle.
360 * RECT rect : A rectangle describing the dimensions of
361 * the rectangle in device coordinates.
363 * WORD wShadowWidth : Width of the shadow in device coordinates.
365 * WORD wFlags : The following flags may be passed to describe
366 * the style of the rectangle:
368 * DRAW3D_IN : The shadow is drawn such that
369 * the box appears to be sunk in to the screen.
370 * This is default if 0 is passed.
372 * DRAW3D_OUT : The shadow is drawn such that
373 * the box appears to be sticking out of the
376 * RETURN (void FAR PASCAL):
377 * The 3D looking rectangle will have been drawn into the DC.
383 void FAR PASCAL
Draw3DRect(HDC hdc
, LPRECT lpRect
,
384 WORD wShadowWidth
, WORD wFlags
)
386 /* sanity check--don't work if you don't have to! */
387 if (!wShadowWidth
|| !RectVisible(hdc
, lpRect
))
390 /* draw the top line */
391 Draw3DLine(hdc
, lpRect
->left
, lpRect
->top
,
392 lpRect
->right
- lpRect
->left
,
393 wShadowWidth
, DRAW3D_TOPLINE
| wFlags
);
396 Draw3DLine(hdc
, lpRect
->right
, lpRect
->top
,
397 lpRect
->bottom
- lpRect
->top
,
398 wShadowWidth
, DRAW3D_RIGHTLINE
| wFlags
);
401 Draw3DLine(hdc
, lpRect
->left
, lpRect
->bottom
,
402 lpRect
->right
- lpRect
->left
,
403 wShadowWidth
, DRAW3D_BOTTOMLINE
| wFlags
);
406 Draw3DLine(hdc
, lpRect
->left
, lpRect
->top
,
407 lpRect
->bottom
- lpRect
->top
,
408 wShadowWidth
, DRAW3D_LEFTLINE
| wFlags
);
412 /** void FAR PASCAL Draw3DLine(HDC hdc, WORD x, WORD y, WORD nLen,
415 * Draws a 3D line that can be used to make a 3D box.
418 * HDC hdc : Handle to the device context that will be
419 * used to display the 3D line.
421 * WORD x, y : Coordinates of the beginning of the line.
422 * These coordinates are in device units and
423 * represent the _outside_ most point. Horiz-
424 * ontal lines are drawn from left to right and
425 * vertical lines are drawn from top to bottom.
427 * WORD wShadowWidth : Width of the shadow in device coordinates.
429 * WORD wFlags : The following flags may be passed to
430 * describe the style of the 3D line:
432 * DRAW3D_IN : The shadow is drawn such that
433 * the box appears to be sunk in to the screen.
434 * This is default if 0 is passed.
436 * DRAW3D_OUT : The shadow is drawn such that
437 * the box appears to be sticking out of the
440 * DRAW3D_TOPLINE, _BOTTOMLINE, _LEFTLINE, and
441 * _RIGHTLINE : Specifies that a "top",
442 * "Bottom", "Left", or"Right" line is to be
445 * RETURN (void FAR PASCAL):
446 * The line will have been drawn into the DC.
452 void FAR PASCAL
Draw3DLine(HDC hdc
, WORD x
, WORD y
, WORD nLen
,
453 WORD wShadowWidth
, WORD wFlags
)
458 POINT Point
[ 4 ]; /* define a polgon with 4 points */
460 /* if width is zero, don't do nothin'! */
464 /* define shape of polygon--origin is always the same */
468 /* To do this we'll simply draw a polygon with four sides, using
469 * the appropriate brush. I dare you to ask me why this isn't a
472 if (wFlags
& DRAW3D_TOPLINE
)
474 /* across to right */
475 Point
[1].x
= x
+ nLen
- (wShadowWidth
== 1 ? 1 : 0);
479 Point
[2].x
= x
+ nLen
- wShadowWidth
;
480 Point
[2].y
= y
+ wShadowWidth
;
482 /* accross to left */
483 Point
[3].x
= x
+ wShadowWidth
;
484 Point
[3].y
= y
+ wShadowWidth
;
486 /* select 'dark' brush if 'in'--'light' for 'out' */
487 fDark
= (wFlags
& DRAW3D_IN
) ? TRUE
: FALSE
;
490 /* possibly the bottom? */
491 else if (wFlags
& DRAW3D_BOTTOMLINE
)
493 /* across to right */
494 Point
[1].x
= x
+ nLen
;
498 Point
[2].x
= x
+ nLen
- wShadowWidth
;
499 Point
[2].y
= y
- wShadowWidth
;
501 /* accross to left */
502 Point
[3].x
= x
+ wShadowWidth
;
503 Point
[3].y
= y
- wShadowWidth
;
505 /* select 'light' brush if 'in' */
506 fDark
= (wFlags
& DRAW3D_IN
) ? FALSE
: TRUE
;
509 /* ok, it's gotta be left? */
510 else if (wFlags
& DRAW3D_LEFTLINE
)
514 Point
[1].y
= y
+ nLen
- (wShadowWidth
== 1 ? 1 : 0);
517 Point
[2].x
= x
+ wShadowWidth
;
518 Point
[2].y
= y
+ nLen
- wShadowWidth
;
521 Point
[3].x
= x
+ wShadowWidth
;
522 Point
[3].y
= y
+ wShadowWidth
;
524 /* select 'dark' brush if 'in'--'light' for 'out' */
525 fDark
= (wFlags
& DRAW3D_IN
) ? TRUE
: FALSE
;
528 /* well maybe it's for the right side? */
529 else if (wFlags
& DRAW3D_RIGHTLINE
)
533 Point
[1].y
= y
+ nLen
;
536 Point
[2].x
= x
- wShadowWidth
;
537 Point
[2].y
= y
+ nLen
- wShadowWidth
;
540 Point
[3].x
= x
- wShadowWidth
;
541 Point
[3].y
= y
+ wShadowWidth
;
543 /* select 'light' brush if 'in' */
544 fDark
= (wFlags
& DRAW3D_IN
) ? FALSE
: TRUE
;
550 /* select NULL_PEN for no borders */
551 hOldPen
= SelectObject(hdc
, GetStockObject(NULL_PEN
));
553 /* select the appropriate color for the fill */
555 hOldBrush
= SelectObject(hdc
, GetStockObject(GRAY_BRUSH
));
557 hOldBrush
= SelectObject(hdc
, GetStockObject(WHITE_BRUSH
));
559 /* finally, draw the dern thing */
560 Polygon(hdc
, (LPPOINT
)&Point
, 4);
562 /* restore what we killed */
563 SelectObject(hdc
, hOldBrush
);
564 SelectObject(hdc
, hOldPen
);
572 * Yet another 'Gas Gauge Custom Control.' This control gives you
573 * a 'progress bar' class (named zYzGauge) for use in your applications.
574 * You can set the range, position, font, color, orientation, and 3d
575 * effect of the gauge by sending messages to the control.
577 * Before you can use this control, you MUST first export the window
578 * procedure for the control (or define it with the _export keyword):
580 * EXPORTS gaugeWndProc
582 * You then need initialize the class before you use it:
584 * if (!gaugeInit(hInstance))
585 * die a horrible death
589 * The colors used by the control default to black and white if you
590 * are running on a mono-display. They default to blue and white
591 * if you are on a color display. You enable the 3D effect by setting
592 * the ZYZGS_3D style flag in the styles field of the control (like
593 * any other control).
595 * To select your own colors, you can send the ZYZG_SETFGCOLOR and
596 * ZYZG_SETBKCOLOR messages to set the foreground (percent done) and
597 * background (percent not done) colors. The lParam is the RGB()
598 * value--wParam is ignored.
600 * In all of the following ZYZG_??? messages, the arguments are
601 * WORDS. If you are setting parameters, the value is sent as
602 * the wParam (lParam is ignored). If you are getting parameters,
603 * the value is returned as a LONG and should be cast to a *signed*
606 * To set the depth of the 3D effect (if enabled), you can send the
607 * ZYZG_SETBEZELFACE and ZYZG_SETWIDTH3D messages. The bezel face
608 * is the flat top on the 3D border--its color will be that of the
609 * button-face. The 3D width is the width of the bezel itself; inside
610 * and outside. The light color is white, the dark color is gray.
611 * Both widths *can* be zero--both default to 2 which looks to me.
613 * The range of the control can be set by sending the ZYZG_SETRANGE
614 * message to the control. It can be any integer from 1 to 32767.
615 * What this specifies is the number of pieces that create a whole.
616 * The default is 100. You can get the current range setting by
617 * sending the ZYZG_GETRANGE message to the control.
619 * The position (number of pieces out of the whole have been used) is
620 * set with the ZYZG_SETPOSITION message. It can be any integer from
621 * 0 to the current range setting of the control--it will be clipped
622 * if the position is out of bounds. The default position is 0. You
623 * can get the current position at any time with the ZYZG_GETPOSITION
626 * You can also set the range using a delta from the current range.
627 * This is done by sending the ZYZG_SETDELTAPOS message with wParam
628 * set to a _signed_ integer value within the range of the control.
630 * The font used for the percentage text can be set using the standard
631 * WM_SETFONT message. You can get the current font at any time with
632 * the WM_GETFONT message.
634 * The orientation can be left to right, right to left, bottom to top,
635 * or top to bottom. Whatever suits your needs. You set this by
636 * sending the ZYZG_ORIENTATION message to the control with one of
637 * the following values (default is ZYZG_ORIENT_LEFTTORIGHT):
639 * ZYZG_ORIENT_LEFTTORIGHT (0)
640 * ZYZG_ORIENT_RIGHTTOLEFT (1)
641 * ZYZG_ORIENT_BOTTOMTOTOP (2)
642 * ZYZG_ORIENT_TOPTOBOTTOM (3)
645 * 3/12/91 cjp put in this comment
646 * 6/19/92 cjp touched it a bit
651 // (C) Copyright Microsoft Corp. 1992. All rights reserved.
653 // You have a royalty-free right to use, modify, reproduce and
654 // distribute the Sample Files (and/or any modified version) in
655 // any way you find useful, provided that you agree that
656 // Microsoft has no warranty obligations or liability for any
657 // Sample Application Files which are modified.
661 /* get the includes we need */
668 // #include "zyz3d.h"
669 // #include "zyzgauge.h"
672 /* static global variables */
673 static char gszzYzGaugeClass
[] = "zYzGauge";
676 /* window word position definitions */
677 #define ZYZG_WW_PZYZGAUGE 0
678 /* #define ZYZG_WW_EXTRABYTES 2 */
679 #define ZYZG_WW_EXTRABYTES 4
682 /* control block structure typedef */
683 typedef struct tZYZGAUGE
689 WORD wWidthBezelFace
;
694 } ZYZGAUGE
, *PZYZGAUGE
, FAR
*LPZYZGAUGE
;
697 /* some default values for the control */
698 #define ZYZG_DEF_RANGE 100
699 #define ZYZG_DEF_POSITION 0
700 #define ZYZG_DEF_ORIENTATION ZYZG_ORIENT_LEFTTORIGHT
701 #define ZYZG_DEF_WIDTH3D 2
702 #define ZYZG_DEF_BEZELFACE 2
706 /* the default settings for drawing colors--display dependent */
707 static DWORD rgbDefTextColor
;
708 static DWORD rgbDefBkColor
;
709 static BOOL fSupport3D
;
711 #if !defined(APIENTRY) // NT defines APIENTRY, 3.x not
712 #define APIENTRY FAR PASCAL
718 #define _EXPORT _export
719 typedef signed short int SHORT
;
722 /* internal function prototypes */
723 static void PASCAL
gaugePaint(HWND
, HDC
);
724 /* LRESULT FAR PASCAL */
725 LRESULT APIENTRY _EXPORT
gaugeWndProc(HWND
, UINT
, WPARAM
, LPARAM
);
729 /** BOOL FAR PASCAL gaugeInit(HINSTANCE hInstance)
732 * Registers the window class for the zYzGauge control. Performs
733 * other initialization for the zYzGauge text control. This must
734 * be done before the zYzGauge control is used--or it will fail
735 * and your dialog box will not open!
738 * HINSTANCE hInstance : Instance handle to register class with.
741 * The return value is TRUE if the zYzGauge class was successfully
742 * registered. It is FALSE if the initialization fails.
748 //#pragma alloc_text(init, gaugeInit)
750 BOOL FAR PASCAL
gaugeInit(HINSTANCE hInstance
)
752 static BOOL fRegistered
= FALSE
;
756 /* assume already registered if not first instance */
760 /* fill in the class structure for the zyzgauge control */
761 wc
.hCursor
= LoadCursor(NULL
, IDC_ARROW
);
763 wc
.lpszMenuName
= NULL
;
764 wc
.lpszClassName
= gszzYzGaugeClass
;
765 wc
.hbrBackground
= (HBRUSH
)(COLOR_WINDOW
+ 1);
766 wc
.hInstance
= hInstance
;
769 wc
.style
= CS_GLOBALCLASS
| CS_HREDRAW
| CS_VREDRAW
;
771 wc
.style
= CS_HREDRAW
| CS_VREDRAW
;
774 wc
.lpfnWndProc
= gaugeWndProc
;
776 wc
.cbWndExtra
= ZYZG_WW_EXTRABYTES
;
778 /* attempt to register it--return FALSE if fail */
779 if (!RegisterClass(&wc
))
782 /* Get a DC to determine whether device is mono or not, and set
783 * default foreground/background colors as appropriate.
785 if ((hdc
= CreateIC("DISPLAY", NULL
, NULL
, 0L)))
787 /* check for mono-display */
788 if ((GetDeviceCaps(hdc
, BITSPIXEL
) == 1) &&
789 (GetDeviceCaps(hdc
, PLANES
) == 1))
791 /* using a mono DC--white foreground, black background */
792 rgbDefTextColor
= RGB(255, 255, 255);
793 rgbDefBkColor
= RGB(0, 0, 0);
796 /* good! we have color: blue foreground, white background */
799 rgbDefTextColor
= RGB(0, 0, 255);
800 rgbDefBkColor
= RGB(255, 255, 255);
803 /* need at _least_ 8 for two shades of gray (>=VGA) */
804 fSupport3D
= (GetDeviceCaps(hdc
, NUMCOLORS
) >= 8) ? TRUE
: FALSE
;
806 /* get rid of the DC (IC) */
810 /* uh-oh... can't get DC (IC)... fail */
813 /* unregister the class */
814 UnregisterClass(gszzYzGaugeClass
, hInstance
);
819 return (fRegistered
= TRUE
);
823 /** static void PASCAL gaugePaint(HWND hwnd, HDC hdc)
826 * This function is responsible for painting the zYzGauge control.
829 * HWND hwnd : The window handle for the gauge.
831 * HDC hdc : The DC for the gauge's window.
834 * The control will have been painted.
840 static void PASCAL
gaugePaint(HWND hwnd
, HDC hdc
)
849 WORD dx
, dy
, wGomerX
, wGomerY
;
850 /* Win32s has no GetTextExtent(); let's try GetTextExtentPoint() instead,
851 * which needs a SIZE* parameter */
852 #if defined(__WIN32__)
856 /* get pointer to the control's control block */
857 // pgauge = (PZYZGAUGE)GetWindowWord(hwnd, ZYZG_WW_PZYZGAUGE);
858 pgauge
= (PZYZGAUGE
)GetWindowLong(hwnd
, ZYZG_WW_PZYZGAUGE
);
860 /* set the colors into for the gauge into the control */
861 SetTextColor(hdc
, pgauge
->rgbTextColor
);
862 SetBkColor(hdc
, pgauge
->rgbBkColor
);
864 /* draw black rectangle for gauge */
865 GetClientRect(hwnd
, &rc1
);
867 /* draw a black border on the _outside_ */
868 FrameRect(hdc
, &rc1
, GetStockObject(BLACK_BRUSH
));
870 /* we want to draw _just inside_ the black border */
871 InflateRect(&rc1
, -1, -1);
873 /* one line thick so far... */
874 // Offset = (WORD) 1;
876 /* for 3D stuff, we need to have at least two shades of gray */
877 if ((GetWindowLong(hwnd
, GWL_STYLE
) & ZYZGS_3D
) && fSupport3D
)
879 Draw3DRect(hdc
, &rc1
, pgauge
->wWidth3D
, DRAW3D_OUT
);
880 InflateRect(&rc1
, ~(pgauge
->wWidth3D
), ~(pgauge
->wWidth3D
));
882 Draw3DFaceFrame(hdc
, &rc1
, pgauge
->wWidthBezelFace
);
883 InflateRect(&rc1
, ~(pgauge
->wWidthBezelFace
), ~(pgauge
->wWidthBezelFace
));
885 Draw3DRect(hdc
, &rc1
, pgauge
->wWidth3D
, DRAW3D_IN
);
886 InflateRect(&rc1
, ~(pgauge
->wWidth3D
), ~(pgauge
->wWidth3D
));
888 /* draw a black border on the _inside_ */
889 FrameRect(hdc
, &rc1
, GetStockObject(BLACK_BRUSH
));
891 /* we want to draw _just inside_ the black border */
892 InflateRect(&rc1
, -1, -1);
894 /* add all the other pixels into the border width */
895 Offset
+= (2 * pgauge
->wWidth3D
) + pgauge
->wWidthBezelFace
+ 1;
898 /* dup--one rc for 'how much filled', one rc for 'how much empty' */
901 /* get the range--make sure it's a valid range */
902 if ((iRange
= pgauge
->wRange
) <= 0)
905 /* get the position--greater than 100% would be bad */
906 if ((iPos
= pgauge
->wPosition
) > iRange
)
909 /* compute the actual size of the gauge */
910 dx
= rc1
.right
- rc1
.left
;
911 dy
= rc1
.bottom
- rc1
.top
;
912 wGomerX
= (WORD
)((DWORD
)iPos
* dx
/ iRange
);
913 wGomerY
= (WORD
)((DWORD
)iPos
* dy
/ iRange
);
915 /* get the orientation and munge rects accordingly */
916 switch (pgauge
->wOrientation
)
918 case ZYZG_ORIENT_RIGHTTOLEFT
:
919 rc1
.left
= rc2
.right
= rc1
.right
- wGomerX
;
922 case ZYZG_ORIENT_BOTTOMTOTOP
:
923 rc1
.top
= rc2
.bottom
= rc1
.bottom
- wGomerY
;
926 case ZYZG_ORIENT_TOPTOBOTTOM
:
927 rc1
.bottom
= rc2
.top
+= wGomerY
;
931 rc1
.right
= rc2
.left
+= wGomerX
;
935 /* select the correct font */
936 hFont
= SelectObject(hdc
, pgauge
->hFont
);
938 /* build up a string to blit out--ie the meaning of life: "42%" */
939 wsprintf(ach
, "%3d%%", (WORD
)((DWORD
)iPos
* 100 / iRange
));
940 /* Win32s has no GetTextExtent(); let's try GetTextExtentPoint() instead */
941 #if defined(__WIN32__)
942 GetTextExtentPoint(hdc
, ach
, wGomerX
= lstrlen(ach
), &size
);
945 dwExtent
= GetTextExtent(hdc
, ach
, wGomerX
= lstrlen(ach
));
949 /* Draw the finished (ie the percent done) side of box. If
950 * ZYZG_WW_POSITION is 42, (in range of 0 to 100) this ExtTextOut
951 * draws the meaning of life (42%) bar.
953 ExtTextOut(hdc
, (dx
- LOWORD(dwExtent
)) / 2 + Offset
,
954 (dy
- HIWORD(dwExtent
)) / 2 + Offset
,
955 ETO_OPAQUE
| ETO_CLIPPED
, &rc2
, ach
, wGomerX
, NULL
);
957 /* Reverse fore and back colors for drawing the undone (ie the non-
958 * finished) side of the box.
960 SetBkColor(hdc
, pgauge
->rgbTextColor
);
961 SetTextColor(hdc
, pgauge
->rgbBkColor
);
963 ExtTextOut(hdc
, (dx
- LOWORD(dwExtent
)) / 2 + Offset
,
964 (dy
- HIWORD(dwExtent
)) / 2 + Offset
,
965 ETO_OPAQUE
| ETO_CLIPPED
, &rc1
, ach
, wGomerX
, NULL
);
967 /* unselect the font */
968 SelectObject(hdc
, hFont
);
972 /** LRESULT FAR PASCAL gaugeWndProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
975 * This is the control's window procedure. Its purpose is to handle
976 * special messages for this custom control.
978 * The special control messages for the gauge control are:
980 * ZYZG_SETRANGE : Sets the range of the gauge. In other
981 * words, the number of parts that make a
984 * ZYZG_GETRANGE : Returns the current range of the gauge.
986 * ZYZG_SETORIENTATION : Sets the orientation of the gauge. This
987 * can be one of the ZYZG_ORIENT_?? msgs.
989 * ZYZG_GETORIENTATION : Gets the current orientation of the
992 * ZYZG_SETPOSITION : Sets the current position of the gauge.
993 * In other words, how many pieces of the
994 * whole have been used.
996 * ZYZG_GETPOSITION : Gets the current position of the gauge.
998 * ZYZG_SETDELTAPOS : Sets the position of the gauge +/- the
1001 * ZYZG_SETFGCOLOR : Sets the foreground (percent done) color.
1003 * ZYZG_GETFGCOLOR : Gets the foreground (percent done) color.
1005 * ZYZG_SETBKCOLOR : Sets the background (percent not done)
1008 * ZYZG_GETBKCOLOR : Gets the background (percent not done)
1011 * WM_SETFONT : Sets the font to use for the percentage
1012 * text of the gauge.
1014 * WM_GETFONT : Gets the current font in use by the
1021 /* LRESULT FAR PASCAL */
1023 LRESULT APIENTRY _EXPORT
gaugeWndProc(HWND hwnd
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
)
1030 // pgauge = (PZYZGAUGE)GetWindowWord(hwnd, ZYZG_WW_PZYZGAUGE);
1031 pgauge
= (PZYZGAUGE
)GetWindowLong(hwnd
, ZYZG_WW_PZYZGAUGE
);
1033 /* break to get DefWindowProc() */
1037 /* need to allocate a control block */
1038 // pgauge = (PZYZGAUGE)LocalAlloc(LPTR, sizeof(ZYZGAUGE));
1039 pgauge
= (PZYZGAUGE
)malloc(sizeof(ZYZGAUGE
));
1043 /* hang on to this control block */
1044 // SetWindowWord(hwnd, ZYZG_WW_PZYZGAUGE, (WORD)pgauge);
1045 SetWindowLong(hwnd
, ZYZG_WW_PZYZGAUGE
, (LONG
)pgauge
);
1047 /* fill control block with defaults */
1048 pgauge
->wRange
= ZYZG_DEF_RANGE
;
1049 pgauge
->wPosition
= ZYZG_DEF_POSITION
;
1050 pgauge
->wOrientation
= ZYZG_DEF_ORIENTATION
;
1051 pgauge
->wWidth3D
= ZYZG_DEF_WIDTH3D
;
1052 pgauge
->wWidthBezelFace
= ZYZG_DEF_BEZELFACE
;
1053 pgauge
->rgbTextColor
= rgbDefTextColor
;
1054 pgauge
->rgbBkColor
= rgbDefBkColor
;
1056 /* use system font */
1057 SendMessage(hwnd
, WM_SETFONT
, (WPARAM
)NULL
, 0L);
1059 /* go to DefWindowProc() to finish the job */
1063 /* get rid of the control's memory */
1065 // LocalFree((HANDLE)pgauge);
1069 case ZYZG_GETPOSITION
:
1070 return (pgauge
->wPosition
);
1073 return (pgauge
->wRange
);
1075 case ZYZG_GETORIENTATION
:
1076 return (pgauge
->wOrientation
);
1078 case ZYZG_GETWIDTH3D
:
1079 return (pgauge
->wWidth3D
);
1081 case ZYZG_GETBEZELFACE
:
1082 return (pgauge
->wWidthBezelFace
);
1084 case ZYZG_GETBKCOLOR
:
1085 return (pgauge
->rgbTextColor
);
1087 case ZYZG_GETFGCOLOR
:
1088 return (pgauge
->rgbBkColor
);
1090 case ZYZG_SETBKCOLOR
:
1091 pgauge
->rgbBkColor
= lParam
;
1094 case ZYZG_SETFGCOLOR
:
1095 pgauge
->rgbTextColor
= lParam
;
1099 case ZYZG_SETPOSITION
:
1100 pgauge
->wPosition
= wParam
;
1103 GetClientRect(hwnd
, &rc
);
1104 if ((GetWindowLong(hwnd
, GWL_STYLE
) & ZYZGS_3D
) && fSupport3D
)
1106 wParam
= (2 * pgauge
->wWidth3D
) +
1107 pgauge
->wWidthBezelFace
+ 2;
1113 InflateRect(&rc
, ~(wParam
), ~(wParam
));
1114 InvalidateRect(hwnd
, &rc
, FALSE
);
1119 pgauge
->wRange
= wParam
;
1120 goto zyzgForceRepaint
;
1122 case ZYZG_SETORIENTATION
:
1123 pgauge
->wOrientation
= wParam
;
1124 goto zyzgForceRepaint
;
1126 case ZYZG_SETWIDTH3D
:
1127 pgauge
->wWidth3D
= wParam
;
1130 InvalidateRect(hwnd
, NULL
, FALSE
);
1134 case ZYZG_SETBEZELFACE
:
1135 pgauge
->wWidthBezelFace
= wParam
;
1136 goto zyzgForceRepaint3D
;
1138 case ZYZG_SETDELTAPOS
:
1139 /* Watcom doesn't like the following line so removing typecasts */
1140 /* (int)pgauge->wPosition += (int)wParam; */
1141 pgauge
->wPosition
+= wParam
;
1142 goto zyzgForceRepaint
;
1145 BeginPaint(hwnd
, &ps
);
1146 gaugePaint(hwnd
, ps
.hdc
);
1147 EndPaint(hwnd
, &ps
);
1151 hFont
= pgauge
->hFont
;
1153 /* if system font, then return NULL handle */
1154 return (long)((hFont
== GetStockObject(SYSTEM_FONT
)) ? NULL
: hFont
);
1157 /* if NULL hFont, use system font */
1158 if (!(hFont
= (HFONT
)wParam
))
1159 hFont
= GetStockObject(SYSTEM_FONT
);
1161 pgauge
->hFont
= hFont
;
1163 /* redraw if indicated in message */
1166 InvalidateRect(hwnd
, NULL
, TRUE
);
1172 /* let the dialog mangler take care of this message */
1173 return (DefWindowProc(hwnd
, uMsg
, wParam
, lParam
));
1174 } /* gaugeWndProc() */
1177 /** EOF: zyzgauge.c **/