]>
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"
30 #include "wx/msw/gaugemsw.h"
31 #include "wx/msw/private.h"
33 /* gas gauge graph control messages--class "zYzGauge" */
34 #define ZYZG_SETRANGE (WM_USER + 0)
35 #define ZYZG_GETRANGE (WM_USER + 1)
36 #define ZYZG_SETPOSITION (WM_USER + 2)
37 #define ZYZG_GETPOSITION (WM_USER + 3)
38 #define ZYZG_SETORIENTATION (WM_USER + 4)
39 #define ZYZG_GETORIENTATION (WM_USER + 5)
40 #define ZYZG_SETFGCOLOR (WM_USER + 6)
41 #define ZYZG_GETFGCOLOR (WM_USER + 7)
42 #define ZYZG_SETBKCOLOR (WM_USER + 8)
43 #define ZYZG_GETBKCOLOR (WM_USER + 9)
44 #define ZYZG_SETWIDTH3D (WM_USER + 10)
45 #define ZYZG_GETWIDTH3D (WM_USER + 11)
46 #define ZYZG_SETBEZELFACE (WM_USER + 12)
47 #define ZYZG_GETBEZELFACE (WM_USER + 13)
48 #define ZYZG_SETDELTAPOS (WM_USER + 14)
51 /* orientations for ZYZG_WW_ORIENTATION */
52 #define ZYZG_ORIENT_LEFTTORIGHT 0
53 #define ZYZG_ORIENT_RIGHTTOLEFT 1
54 #define ZYZG_ORIENT_BOTTOMTOTOP 2
55 #define ZYZG_ORIENT_TOPTOBOTTOM 3
58 #define ZYZGS_3D 0x8000L /* control will be 3D */
60 /* public function prototypes */
61 BOOL FAR PASCAL
gaugeInit(HINSTANCE hInstance
);
63 #if !USE_SHARED_LIBRARY
64 IMPLEMENT_DYNAMIC_CLASS(wxGaugeMSW
, wxControl
)
67 bool wxGaugeMSW::Create(wxWindow
*parent
, wxWindowID id
,
72 const wxValidator
& validator
,
75 static bool wxGaugeMSWInitialised
= FALSE
;
77 if ( !wxGaugeMSWInitialised
)
79 if (!gaugeInit((HINSTANCE
) wxGetInstance()))
80 wxFatalError("Cannot initalize Gauge library");
81 wxGaugeMSWInitialised
= TRUE
;
85 SetValidator(validator
);
87 if (parent
) parent
->AddChild(this);
91 SetBackgroundColour(parent
->GetBackgroundColour()) ;
92 SetForegroundColour(parent
->GetForegroundColour()) ;
94 m_windowStyle
= style
;
97 m_windowId
= (int)NewControlId();
106 long msFlags
= WS_CHILD
| WS_VISIBLE
| WS_TABSTOP
;
110 CreateWindowEx(MakeExtendedStyle(m_windowStyle
), _T("zYzGauge"), NULL
, msFlags
,
111 0, 0, 0, 0, (HWND
) parent
->GetHWND(), (HMENU
)m_windowId
,
112 wxGetInstance(), NULL
);
114 m_hWnd
= (WXHWND
)wx_button
;
116 // Subclass again for purposes of dialog editing mode
117 SubclassWin((WXHWND
)wx_button
);
121 if (m_windowStyle
& wxGA_HORIZONTAL
)
122 wOrient
= ZYZG_ORIENT_LEFTTORIGHT
;
124 wOrient
= ZYZG_ORIENT_BOTTOMTOTOP
;
126 SendMessage(wx_button
, ZYZG_SETORIENTATION
, wOrient
, 0);
127 SendMessage(wx_button
, ZYZG_SETRANGE
, range
, 0);
129 SendMessage((HWND
) GetHWND(), ZYZG_SETFGCOLOR
, 0, RGB(GetForegroundColour().Red(), GetForegroundColour().Green(), GetForegroundColour().Blue()));
130 SendMessage((HWND
) GetHWND(), ZYZG_SETBKCOLOR
, 0, RGB(GetBackgroundColour().Red(), GetBackgroundColour().Green(), GetBackgroundColour().Blue()));
132 SetFont(parent
->GetFont());
138 SetSize(x
, y
, width
, height
);
140 ShowWindow((HWND
) GetHWND(), SW_SHOW
);
145 void wxGaugeMSW::DoSetSize(int x
, int y
, int width
, int height
, int sizeFlags
)
147 int currentX
, currentY
;
148 GetPosition(¤tX
, ¤tY
);
154 if (x
== -1 || (sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
))
156 if (y
== -1 || (sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
))
159 AdjustForParentClientOrigin(x1
, y1
, sizeFlags
);
161 // If we're prepared to use the existing size, then...
162 if (width
== -1 && height
== -1 && ((sizeFlags
& wxSIZE_AUTO
) != wxSIZE_AUTO
))
167 // Deal with default size (using -1 values)
169 w1
= DEFAULT_ITEM_WIDTH
;
172 h1
= DEFAULT_ITEM_HEIGHT
;
174 MoveWindow((HWND
) GetHWND(), x1
, y1
, w1
, h1
, TRUE
);
177 void wxGaugeMSW::SetShadowWidth(int w
)
179 SendMessage((HWND
) GetHWND(), ZYZG_SETWIDTH3D
, w
, 0);
182 void wxGaugeMSW::SetBezelFace(int w
)
184 SendMessage((HWND
) GetHWND(), ZYZG_SETBEZELFACE
, w
, 0);
187 void wxGaugeMSW::SetRange(int r
)
191 SendMessage((HWND
) GetHWND(), ZYZG_SETRANGE
, r
, 0);
194 void wxGaugeMSW::SetValue(int pos
)
198 SendMessage((HWND
) GetHWND(), ZYZG_SETPOSITION
, pos
, 0);
201 int wxGaugeMSW::GetShadowWidth(void) const
203 return (int) SendMessage((HWND
) GetHWND(), ZYZG_GETWIDTH3D
, 0, 0);
206 int wxGaugeMSW::GetBezelFace(void) const
208 return (int) SendMessage((HWND
) GetHWND(), ZYZG_GETBEZELFACE
, 0, 0);
211 int wxGaugeMSW::GetRange(void) const
213 return (int) SendMessage((HWND
) GetHWND(), ZYZG_GETRANGE
, 0, 0);
216 int wxGaugeMSW::GetValue(void) const
218 return (int) SendMessage((HWND
) GetHWND(), ZYZG_GETPOSITION
, 0, 0);
221 bool wxGaugeMSW::SetForegroundColour(const wxColour
& col
)
223 if ( !wxControl::SetForegroundColour(col
) )
226 SendMessage((HWND
) GetHWND(), ZYZG_SETFGCOLOR
, 0, RGB(col
.Red(), col
.Green(), col
.Blue()));
231 bool wxGaugeMSW::SetBackgroundColour(const wxColour
& col
)
233 if ( !wxControl::SetBackgroundColour(col
) )
236 SendMessage((HWND
) GetHWND(), ZYZG_SETBKCOLOR
, 0, RGB(col
.Red(), col
.Green(), col
.Blue()));
245 * This module contains functions for creating nifty 3D borders
246 * around controls like zYzGauge.
249 * 3/14/91 cjp put in this comment
250 * 6/19/92 cjp touched it a bit
255 // (C) Copyright Microsoft Corp. 1992. All rights reserved.
257 // You have a royalty-free right to use, modify, reproduce and
258 // distribute the Sample Files (and/or any modified version) in
259 // any way you find useful, provided that you agree that
260 // Microsoft has no warranty obligations or liability for any
261 // Sample Application Files which are modified.
265 /* get the includes we need */
268 /* misc. control flag defines */
269 #define DRAW3D_IN 0x0001
270 #define DRAW3D_OUT 0x0002
272 #define DRAW3D_TOPLINE 0x0004
273 #define DRAW3D_BOTTOMLINE 0x0008
274 #define DRAW3D_LEFTLINE 0x0010
275 #define DRAW3D_RIGHTLINE 0x0020
278 /* public function prototypes */
279 void FAR PASCAL
Draw3DFaceFrame(HDC
, LPRECT
, WORD
);
280 void FAR PASCAL
Draw3DRect(HDC
, LPRECT
, WORD
, WORD
);
281 void FAR PASCAL
Draw3DLine(HDC
, WORD
, WORD
, WORD
, WORD
, WORD
);
284 /** void FAR PASCAL Draw3DFaceFrame(HDC hdc, LPRECT rc, WORD wWidth)
287 * This function draws a flat frame with the current button-face
291 * HDC hdc : The DC to draw into.
293 * LPRECT rc : The containing rect for the new frame.
295 * WORD wWidth : The width of the frame to draw.
297 * RETURN (void FAR PASCAL):
298 * The frame will have been drawn into the DC.
304 void FAR PASCAL
Draw3DFaceFrame(HDC hdc
, LPRECT rc
, WORD wWidth
)
309 /* don't go through a bunch of work if we don't have to */
313 /* set up color to be button-face color--so it may not be gray */
314 rgbOld
= SetBkColor(hdc
, GetSysColor(COLOR_BTNFACE
));
316 /* perform CopyRect w/o bloody windows style overhead */
322 rc1
.bottom
= rc
->top
+ wWidth
;
323 rc1
.right
= rc
->right
;
326 ExtTextOut(hdc
, rc1
.left
, rc1
.top
, ETO_OPAQUE
, &rc1
, NULL
, 0, NULL
);
329 rc1
.left
= rc
->right
- wWidth
;
330 rc1
.bottom
= rc
->bottom
;
332 /* blast this part now */
333 ExtTextOut(hdc
, rc1
.left
, rc1
.top
, ETO_OPAQUE
, &rc1
, NULL
, 0, NULL
);
337 rc1
.right
= rc
->left
+ wWidth
;
339 /* and another part */
340 ExtTextOut(hdc
, rc1
.left
, rc1
.top
, ETO_OPAQUE
, &rc1
, NULL
, 0, NULL
);
343 rc1
.right
= rc
->right
;
344 rc1
.top
= rc
->bottom
- wWidth
;
347 ExtTextOut(hdc
, rc1
.left
, rc1
.top
, ETO_OPAQUE
, &rc1
, NULL
, 0, NULL
);
349 /* restore the old bk color */
350 SetBkColor(hdc
, rgbOld
);
351 } /* Draw3DFaceFrame() */
354 /** void FAR PASCAL Draw3DRect(HDC, LPRECT, WORD, WORD)
357 * Draws a 3D rectangle that is shaded. wFlags can be used to
358 * control how the rectangle looks.
361 * HDC hdc : Handle to the device context that will be
362 * used to display the rectangle.
364 * RECT rect : A rectangle describing the dimensions of
365 * the rectangle in device coordinates.
367 * WORD wShadowWidth : Width of the shadow in device coordinates.
369 * WORD wFlags : The following flags may be passed to describe
370 * the style of the rectangle:
372 * DRAW3D_IN : The shadow is drawn such that
373 * the box appears to be sunk in to the screen.
374 * This is default if 0 is passed.
376 * DRAW3D_OUT : The shadow is drawn such that
377 * the box appears to be sticking out of the
380 * RETURN (void FAR PASCAL):
381 * The 3D looking rectangle will have been drawn into the DC.
387 void FAR PASCAL
Draw3DRect(HDC hdc
, LPRECT lpRect
,
388 WORD wShadowWidth
, WORD wFlags
)
390 /* sanity check--don't work if you don't have to! */
391 if (!wShadowWidth
|| !RectVisible(hdc
, lpRect
))
394 /* draw the top line */
395 Draw3DLine(hdc
, lpRect
->left
, lpRect
->top
,
396 lpRect
->right
- lpRect
->left
,
397 wShadowWidth
, DRAW3D_TOPLINE
| wFlags
);
400 Draw3DLine(hdc
, lpRect
->right
, lpRect
->top
,
401 lpRect
->bottom
- lpRect
->top
,
402 wShadowWidth
, DRAW3D_RIGHTLINE
| wFlags
);
405 Draw3DLine(hdc
, lpRect
->left
, lpRect
->bottom
,
406 lpRect
->right
- lpRect
->left
,
407 wShadowWidth
, DRAW3D_BOTTOMLINE
| wFlags
);
410 Draw3DLine(hdc
, lpRect
->left
, lpRect
->top
,
411 lpRect
->bottom
- lpRect
->top
,
412 wShadowWidth
, DRAW3D_LEFTLINE
| wFlags
);
416 /** void FAR PASCAL Draw3DLine(HDC hdc, WORD x, WORD y, WORD nLen,
419 * Draws a 3D line that can be used to make a 3D box.
422 * HDC hdc : Handle to the device context that will be
423 * used to display the 3D line.
425 * WORD x, y : Coordinates of the beginning of the line.
426 * These coordinates are in device units and
427 * represent the _outside_ most point. Horiz-
428 * ontal lines are drawn from left to right and
429 * vertical lines are drawn from top to bottom.
431 * WORD wShadowWidth : Width of the shadow in device coordinates.
433 * WORD wFlags : The following flags may be passed to
434 * describe the style of the 3D line:
436 * DRAW3D_IN : The shadow is drawn such that
437 * the box appears to be sunk in to the screen.
438 * This is default if 0 is passed.
440 * DRAW3D_OUT : The shadow is drawn such that
441 * the box appears to be sticking out of the
444 * DRAW3D_TOPLINE, _BOTTOMLINE, _LEFTLINE, and
445 * _RIGHTLINE : Specifies that a "top",
446 * "Bottom", "Left", or"Right" line is to be
449 * RETURN (void FAR PASCAL):
450 * The line will have been drawn into the DC.
456 void FAR PASCAL
Draw3DLine(HDC hdc
, WORD x
, WORD y
, WORD nLen
,
457 WORD wShadowWidth
, WORD wFlags
)
462 POINT Point
[ 4 ]; /* define a polgon with 4 points */
464 /* if width is zero, don't do nothin'! */
468 /* define shape of polygon--origin is always the same */
472 /* To do this we'll simply draw a polygon with four sides, using
473 * the appropriate brush. I dare you to ask me why this isn't a
476 if (wFlags
& DRAW3D_TOPLINE
)
478 /* across to right */
479 Point
[1].x
= x
+ nLen
- (wShadowWidth
== 1 ? 1 : 0);
483 Point
[2].x
= x
+ nLen
- wShadowWidth
;
484 Point
[2].y
= y
+ wShadowWidth
;
486 /* accross to left */
487 Point
[3].x
= x
+ wShadowWidth
;
488 Point
[3].y
= y
+ wShadowWidth
;
490 /* select 'dark' brush if 'in'--'light' for 'out' */
491 fDark
= (wFlags
& DRAW3D_IN
) ? TRUE
: FALSE
;
494 /* possibly the bottom? */
495 else if (wFlags
& DRAW3D_BOTTOMLINE
)
497 /* across to right */
498 Point
[1].x
= x
+ nLen
;
502 Point
[2].x
= x
+ nLen
- wShadowWidth
;
503 Point
[2].y
= y
- wShadowWidth
;
505 /* accross to left */
506 Point
[3].x
= x
+ wShadowWidth
;
507 Point
[3].y
= y
- wShadowWidth
;
509 /* select 'light' brush if 'in' */
510 fDark
= (wFlags
& DRAW3D_IN
) ? FALSE
: TRUE
;
513 /* ok, it's gotta be left? */
514 else if (wFlags
& DRAW3D_LEFTLINE
)
518 Point
[1].y
= y
+ nLen
- (wShadowWidth
== 1 ? 1 : 0);
521 Point
[2].x
= x
+ wShadowWidth
;
522 Point
[2].y
= y
+ nLen
- wShadowWidth
;
525 Point
[3].x
= x
+ wShadowWidth
;
526 Point
[3].y
= y
+ wShadowWidth
;
528 /* select 'dark' brush if 'in'--'light' for 'out' */
529 fDark
= (wFlags
& DRAW3D_IN
) ? TRUE
: FALSE
;
532 /* well maybe it's for the right side? */
533 else if (wFlags
& DRAW3D_RIGHTLINE
)
537 Point
[1].y
= y
+ nLen
;
540 Point
[2].x
= x
- wShadowWidth
;
541 Point
[2].y
= y
+ nLen
- wShadowWidth
;
544 Point
[3].x
= x
- wShadowWidth
;
545 Point
[3].y
= y
+ wShadowWidth
;
547 /* select 'light' brush if 'in' */
548 fDark
= (wFlags
& DRAW3D_IN
) ? FALSE
: TRUE
;
554 /* select NULL_PEN for no borders */
555 hOldPen
= (HPEN
) SelectObject(hdc
, GetStockObject(NULL_PEN
));
557 /* select the appropriate color for the fill */
559 hOldBrush
= (HBRUSH
) SelectObject(hdc
, GetStockObject(GRAY_BRUSH
));
561 hOldBrush
= (HBRUSH
) SelectObject(hdc
, GetStockObject(WHITE_BRUSH
));
563 /* finally, draw the dern thing */
564 Polygon(hdc
, (LPPOINT
)&Point
, 4);
566 /* restore what we killed */
567 SelectObject(hdc
, hOldBrush
);
568 SelectObject(hdc
, hOldPen
);
576 * Yet another 'Gas Gauge Custom Control.' This control gives you
577 * a 'progress bar' class (named zYzGauge) for use in your applications.
578 * You can set the range, position, font, color, orientation, and 3d
579 * effect of the gauge by sending messages to the control.
581 * Before you can use this control, you MUST first export the window
582 * procedure for the control (or define it with the _export keyword):
584 * EXPORTS gaugeWndProc
586 * You then need initialize the class before you use it:
588 * if (!gaugeInit(hInstance))
589 * die a horrible death
593 * The colors used by the control default to black and white if you
594 * are running on a mono-display. They default to blue and white
595 * if you are on a color display. You enable the 3D effect by setting
596 * the ZYZGS_3D style flag in the styles field of the control (like
597 * any other control).
599 * To select your own colors, you can send the ZYZG_SETFGCOLOR and
600 * ZYZG_SETBKCOLOR messages to set the foreground (percent done) and
601 * background (percent not done) colors. The lParam is the RGB()
602 * value--wParam is ignored.
604 * In all of the following ZYZG_??? messages, the arguments are
605 * WORDS. If you are setting parameters, the value is sent as
606 * the wParam (lParam is ignored). If you are getting parameters,
607 * the value is returned as a LONG and should be cast to a *signed*
610 * To set the depth of the 3D effect (if enabled), you can send the
611 * ZYZG_SETBEZELFACE and ZYZG_SETWIDTH3D messages. The bezel face
612 * is the flat top on the 3D border--its color will be that of the
613 * button-face. The 3D width is the width of the bezel itself; inside
614 * and outside. The light color is white, the dark color is gray.
615 * Both widths *can* be zero--both default to 2 which looks to me.
617 * The range of the control can be set by sending the ZYZG_SETRANGE
618 * message to the control. It can be any integer from 1 to 32767.
619 * What this specifies is the number of pieces that create a whole.
620 * The default is 100. You can get the current range setting by
621 * sending the ZYZG_GETRANGE message to the control.
623 * The position (number of pieces out of the whole have been used) is
624 * set with the ZYZG_SETPOSITION message. It can be any integer from
625 * 0 to the current range setting of the control--it will be clipped
626 * if the position is out of bounds. The default position is 0. You
627 * can get the current position at any time with the ZYZG_GETPOSITION
630 * You can also set the range using a delta from the current range.
631 * This is done by sending the ZYZG_SETDELTAPOS message with wParam
632 * set to a _signed_ integer value within the range of the control.
634 * The font used for the percentage text can be set using the standard
635 * WM_SETFONT message. You can get the current font at any time with
636 * the WM_GETFONT message.
638 * The orientation can be left to right, right to left, bottom to top,
639 * or top to bottom. Whatever suits your needs. You set this by
640 * sending the ZYZG_ORIENTATION message to the control with one of
641 * the following values (default is ZYZG_ORIENT_LEFTTORIGHT):
643 * ZYZG_ORIENT_LEFTTORIGHT (0)
644 * ZYZG_ORIENT_RIGHTTOLEFT (1)
645 * ZYZG_ORIENT_BOTTOMTOTOP (2)
646 * ZYZG_ORIENT_TOPTOBOTTOM (3)
649 * 3/12/91 cjp put in this comment
650 * 6/19/92 cjp touched it a bit
655 // (C) Copyright Microsoft Corp. 1992. All rights reserved.
657 // You have a royalty-free right to use, modify, reproduce and
658 // distribute the Sample Files (and/or any modified version) in
659 // any way you find useful, provided that you agree that
660 // Microsoft has no warranty obligations or liability for any
661 // Sample Application Files which are modified.
665 /* get the includes we need */
666 #if !defined(__GNUWIN32__) && !defined(__SALFORDC__)
672 // #include "zyz3d.h"
673 // #include "zyzgauge.h"
676 /* static global variables */
677 static wxChar gszzYzGaugeClass
[] = _T("zYzGauge");
680 /* window word position definitions */
681 #define ZYZG_WW_PZYZGAUGE 0
682 /* #define ZYZG_WW_EXTRABYTES 2 */
683 #define ZYZG_WW_EXTRABYTES 4
686 /* control block structure typedef */
687 typedef struct tZYZGAUGE
693 WORD wWidthBezelFace
;
698 } ZYZGAUGE
, *PZYZGAUGE
, FAR
*LPZYZGAUGE
;
701 /* some default values for the control */
702 #define ZYZG_DEF_RANGE 100
703 #define ZYZG_DEF_POSITION 0
704 #define ZYZG_DEF_ORIENTATION ZYZG_ORIENT_LEFTTORIGHT
705 #define ZYZG_DEF_WIDTH3D 2
706 #define ZYZG_DEF_BEZELFACE 2
710 /* the default settings for drawing colors--display dependent */
711 static DWORD rgbDefTextColor
;
712 static DWORD rgbDefBkColor
;
713 static BOOL fSupport3D
;
715 #if !defined(APIENTRY) // NT defines APIENTRY, 3.x not
716 #define APIENTRY FAR PASCAL
722 #define _EXPORT _export
723 typedef signed short int SHORT
;
726 /* internal function prototypes */
727 static void PASCAL
gaugePaint(HWND
, HDC
);
728 /* LRESULT FAR PASCAL */
729 LRESULT APIENTRY _EXPORT
gaugeWndProc(HWND
, UINT
, WPARAM
, LPARAM
);
733 /** BOOL FAR PASCAL gaugeInit(HINSTANCE hInstance)
736 * Registers the window class for the zYzGauge control. Performs
737 * other initialization for the zYzGauge text control. This must
738 * be done before the zYzGauge control is used--or it will fail
739 * and your dialog box will not open!
742 * HINSTANCE hInstance : Instance handle to register class with.
745 * The return value is TRUE if the zYzGauge class was successfully
746 * registered. It is FALSE if the initialization fails.
752 //#pragma alloc_text(init, gaugeInit)
754 BOOL FAR PASCAL
gaugeInit(HINSTANCE hInstance
)
756 static BOOL fRegistered
= FALSE
;
760 /* assume already registered if not first instance */
764 /* fill in the class structure for the zyzgauge control */
765 wc
.hCursor
= LoadCursor(NULL
, IDC_ARROW
);
767 wc
.lpszMenuName
= NULL
;
768 wc
.lpszClassName
= gszzYzGaugeClass
;
769 wc
.hbrBackground
= (HBRUSH
)(COLOR_WINDOW
+ 1);
770 wc
.hInstance
= hInstance
;
773 wc
.style
= CS_GLOBALCLASS
| CS_HREDRAW
| CS_VREDRAW
;
775 wc
.style
= CS_HREDRAW
| CS_VREDRAW
;
778 wc
.lpfnWndProc
= gaugeWndProc
;
780 wc
.cbWndExtra
= ZYZG_WW_EXTRABYTES
;
782 /* attempt to register it--return FALSE if fail */
783 if (!RegisterClass(&wc
))
786 /* Get a DC to determine whether device is mono or not, and set
787 * default foreground/background colors as appropriate.
789 if ((hdc
= CreateIC(_T("DISPLAY"), NULL
, NULL
, 0L)))
791 /* check for mono-display */
792 if ((GetDeviceCaps(hdc
, BITSPIXEL
) == 1) &&
793 (GetDeviceCaps(hdc
, PLANES
) == 1))
795 /* using a mono DC--white foreground, black background */
796 rgbDefTextColor
= RGB(255, 255, 255);
797 rgbDefBkColor
= RGB(0, 0, 0);
800 /* good! we have color: blue foreground, white background */
803 rgbDefTextColor
= RGB(0, 0, 255);
804 rgbDefBkColor
= RGB(255, 255, 255);
807 /* need at _least_ 8 for two shades of gray (>=VGA) */
808 fSupport3D
= (GetDeviceCaps(hdc
, NUMCOLORS
) >= 8) ? TRUE
: FALSE
;
810 /* get rid of the DC (IC) */
814 /* uh-oh... can't get DC (IC)... fail */
817 /* unregister the class */
818 UnregisterClass(gszzYzGaugeClass
, hInstance
);
823 return (fRegistered
= TRUE
);
827 /** static void PASCAL gaugePaint(HWND hwnd, HDC hdc)
830 * This function is responsible for painting the zYzGauge control.
833 * HWND hwnd : The window handle for the gauge.
835 * HDC hdc : The DC for the gauge's window.
838 * The control will have been painted.
844 static void PASCAL
gaugePaint(HWND hwnd
, HDC hdc
)
853 WORD dx
, dy
, wGomerX
, wGomerY
;
854 /* Win32s has no GetTextExtent(); let's try GetTextExtentPoint() instead,
855 * which needs a SIZE* parameter */
856 #if defined(__WIN32__)
860 /* get pointer to the control's control block */
861 // pgauge = (PZYZGAUGE)GetWindowWord(hwnd, ZYZG_WW_PZYZGAUGE);
862 pgauge
= (PZYZGAUGE
)GetWindowLong(hwnd
, ZYZG_WW_PZYZGAUGE
);
864 /* set the colors into for the gauge into the control */
865 SetTextColor(hdc
, pgauge
->rgbTextColor
);
866 SetBkColor(hdc
, pgauge
->rgbBkColor
);
868 /* draw black rectangle for gauge */
869 GetClientRect(hwnd
, &rc1
);
871 /* draw a black border on the _outside_ */
872 FrameRect(hdc
, &rc1
, (HBRUSH
) GetStockObject(BLACK_BRUSH
));
874 /* we want to draw _just inside_ the black border */
875 InflateRect(&rc1
, -1, -1);
877 /* one line thick so far... */
878 // Offset = (WORD) 1;
880 /* for 3D stuff, we need to have at least two shades of gray */
881 if ((GetWindowLong(hwnd
, GWL_STYLE
) & ZYZGS_3D
) && fSupport3D
)
883 Draw3DRect(hdc
, &rc1
, pgauge
->wWidth3D
, DRAW3D_OUT
);
884 InflateRect(&rc1
, ~(pgauge
->wWidth3D
), ~(pgauge
->wWidth3D
));
886 Draw3DFaceFrame(hdc
, &rc1
, pgauge
->wWidthBezelFace
);
887 InflateRect(&rc1
, ~(pgauge
->wWidthBezelFace
), ~(pgauge
->wWidthBezelFace
));
889 Draw3DRect(hdc
, &rc1
, pgauge
->wWidth3D
, DRAW3D_IN
);
890 InflateRect(&rc1
, ~(pgauge
->wWidth3D
), ~(pgauge
->wWidth3D
));
892 /* draw a black border on the _inside_ */
893 FrameRect(hdc
, &rc1
, (HBRUSH
) GetStockObject(BLACK_BRUSH
));
895 /* we want to draw _just inside_ the black border */
896 InflateRect(&rc1
, -1, -1);
898 /* add all the other pixels into the border width */
899 Offset
+= (2 * pgauge
->wWidth3D
) + pgauge
->wWidthBezelFace
+ 1;
902 /* dup--one rc for 'how much filled', one rc for 'how much empty' */
905 /* get the range--make sure it's a valid range */
906 if ((iRange
= pgauge
->wRange
) <= 0)
909 /* get the position--greater than 100% would be bad */
910 if ((iPos
= pgauge
->wPosition
) > iRange
)
913 /* compute the actual size of the gauge */
914 dx
= rc1
.right
- rc1
.left
;
915 dy
= rc1
.bottom
- rc1
.top
;
916 wGomerX
= (WORD
)((DWORD
)iPos
* dx
/ iRange
);
917 wGomerY
= (WORD
)((DWORD
)iPos
* dy
/ iRange
);
919 /* get the orientation and munge rects accordingly */
920 switch (pgauge
->wOrientation
)
922 case ZYZG_ORIENT_RIGHTTOLEFT
:
923 rc1
.left
= rc2
.right
= rc1
.right
- wGomerX
;
926 case ZYZG_ORIENT_BOTTOMTOTOP
:
927 rc1
.top
= rc2
.bottom
= rc1
.bottom
- wGomerY
;
930 case ZYZG_ORIENT_TOPTOBOTTOM
:
931 rc1
.bottom
= rc2
.top
+= wGomerY
;
935 rc1
.right
= rc2
.left
+= wGomerX
;
939 /* select the correct font */
940 hFont
= (HFONT
) SelectObject(hdc
, pgauge
->hFont
);
942 /* build up a string to blit out--ie the meaning of life: "42%" */
943 wsprintf(ach
, _T("%3d%%"), (WORD
)((DWORD
)iPos
* 100 / iRange
));
944 /* Win32s has no GetTextExtent(); let's try GetTextExtentPoint() instead */
945 #if defined(__WIN32__)
946 GetTextExtentPoint(hdc
, ach
, wGomerX
= lstrlen(ach
), &size
);
949 dwExtent
= GetTextExtent(hdc
, ach
, wGomerX
= lstrlen(ach
));
953 /* Draw the finished (ie the percent done) side of box. If
954 * ZYZG_WW_POSITION is 42, (in range of 0 to 100) this ExtTextOut
955 * draws the meaning of life (42%) bar.
957 ExtTextOut(hdc
, (dx
- LOWORD(dwExtent
)) / 2 + Offset
,
958 (dy
- HIWORD(dwExtent
)) / 2 + Offset
,
959 ETO_OPAQUE
| ETO_CLIPPED
, &rc2
, ach
, wGomerX
, NULL
);
961 /* Reverse fore and back colors for drawing the undone (ie the non-
962 * finished) side of the box.
964 SetBkColor(hdc
, pgauge
->rgbTextColor
);
965 SetTextColor(hdc
, pgauge
->rgbBkColor
);
967 ExtTextOut(hdc
, (dx
- LOWORD(dwExtent
)) / 2 + Offset
,
968 (dy
- HIWORD(dwExtent
)) / 2 + Offset
,
969 ETO_OPAQUE
| ETO_CLIPPED
, &rc1
, ach
, wGomerX
, NULL
);
971 /* unselect the font */
972 SelectObject(hdc
, hFont
);
976 /** LRESULT FAR PASCAL gaugeWndProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
979 * This is the control's window procedure. Its purpose is to handle
980 * special messages for this custom control.
982 * The special control messages for the gauge control are:
984 * ZYZG_SETRANGE : Sets the range of the gauge. In other
985 * words, the number of parts that make a
988 * ZYZG_GETRANGE : Returns the current range of the gauge.
990 * ZYZG_SETORIENTATION : Sets the orientation of the gauge. This
991 * can be one of the ZYZG_ORIENT_?? msgs.
993 * ZYZG_GETORIENTATION : Gets the current orientation of the
996 * ZYZG_SETPOSITION : Sets the current position of the gauge.
997 * In other words, how many pieces of the
998 * whole have been used.
1000 * ZYZG_GETPOSITION : Gets the current position of the gauge.
1002 * ZYZG_SETDELTAPOS : Sets the position of the gauge +/- the
1005 * ZYZG_SETFGCOLOR : Sets the foreground (percent done) color.
1007 * ZYZG_GETFGCOLOR : Gets the foreground (percent done) color.
1009 * ZYZG_SETBKCOLOR : Sets the background (percent not done)
1012 * ZYZG_GETBKCOLOR : Gets the background (percent not done)
1015 * WM_SETFONT : Sets the font to use for the percentage
1016 * text of the gauge.
1018 * WM_GETFONT : Gets the current font in use by the
1025 /* LRESULT FAR PASCAL */
1027 LRESULT APIENTRY _EXPORT
gaugeWndProc(HWND hwnd
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
)
1034 // pgauge = (PZYZGAUGE)GetWindowWord(hwnd, ZYZG_WW_PZYZGAUGE);
1035 pgauge
= (PZYZGAUGE
)GetWindowLong(hwnd
, ZYZG_WW_PZYZGAUGE
);
1037 /* break to get DefWindowProc() */
1041 /* need to allocate a control block */
1042 // pgauge = (PZYZGAUGE)LocalAlloc(LPTR, sizeof(ZYZGAUGE));
1043 pgauge
= (PZYZGAUGE
)malloc(sizeof(ZYZGAUGE
));
1047 /* hang on to this control block */
1048 // SetWindowWord(hwnd, ZYZG_WW_PZYZGAUGE, (WORD)pgauge);
1049 SetWindowLong(hwnd
, ZYZG_WW_PZYZGAUGE
, (LONG
)pgauge
);
1051 /* fill control block with defaults */
1052 pgauge
->wRange
= ZYZG_DEF_RANGE
;
1053 pgauge
->wPosition
= ZYZG_DEF_POSITION
;
1054 pgauge
->wOrientation
= ZYZG_DEF_ORIENTATION
;
1055 pgauge
->wWidth3D
= ZYZG_DEF_WIDTH3D
;
1056 pgauge
->wWidthBezelFace
= ZYZG_DEF_BEZELFACE
;
1057 pgauge
->rgbTextColor
= rgbDefTextColor
;
1058 pgauge
->rgbBkColor
= rgbDefBkColor
;
1060 /* use system font */
1061 SendMessage(hwnd
, WM_SETFONT
, (WPARAM
)NULL
, 0L);
1063 /* go to DefWindowProc() to finish the job */
1067 /* get rid of the control's memory */
1069 // LocalFree((HANDLE)pgauge);
1073 case ZYZG_GETPOSITION
:
1074 return (pgauge
->wPosition
);
1077 return (pgauge
->wRange
);
1079 case ZYZG_GETORIENTATION
:
1080 return (pgauge
->wOrientation
);
1082 case ZYZG_GETWIDTH3D
:
1083 return (pgauge
->wWidth3D
);
1085 case ZYZG_GETBEZELFACE
:
1086 return (pgauge
->wWidthBezelFace
);
1088 case ZYZG_GETBKCOLOR
:
1089 return (pgauge
->rgbTextColor
);
1091 case ZYZG_GETFGCOLOR
:
1092 return (pgauge
->rgbBkColor
);
1094 case ZYZG_SETBKCOLOR
:
1095 pgauge
->rgbBkColor
= lParam
;
1098 case ZYZG_SETFGCOLOR
:
1099 pgauge
->rgbTextColor
= lParam
;
1103 case ZYZG_SETPOSITION
:
1104 pgauge
->wPosition
= wParam
;
1107 GetClientRect(hwnd
, &rc
);
1108 if ((GetWindowLong(hwnd
, GWL_STYLE
) & ZYZGS_3D
) && fSupport3D
)
1110 wParam
= (2 * pgauge
->wWidth3D
) +
1111 pgauge
->wWidthBezelFace
+ 2;
1117 InflateRect(&rc
, ~(wParam
), ~(wParam
));
1118 InvalidateRect(hwnd
, &rc
, FALSE
);
1123 pgauge
->wRange
= wParam
;
1124 goto zyzgForceRepaint
;
1126 case ZYZG_SETORIENTATION
:
1127 pgauge
->wOrientation
= wParam
;
1128 goto zyzgForceRepaint
;
1130 case ZYZG_SETWIDTH3D
:
1131 pgauge
->wWidth3D
= wParam
;
1134 InvalidateRect(hwnd
, NULL
, FALSE
);
1138 case ZYZG_SETBEZELFACE
:
1139 pgauge
->wWidthBezelFace
= wParam
;
1140 goto zyzgForceRepaint3D
;
1142 case ZYZG_SETDELTAPOS
:
1143 /* Watcom doesn't like the following line so removing typecasts */
1144 /* (int)pgauge->wPosition += (int)wParam; */
1145 pgauge
->wPosition
+= wParam
;
1146 goto zyzgForceRepaint
;
1149 BeginPaint(hwnd
, &ps
);
1150 gaugePaint(hwnd
, ps
.hdc
);
1151 EndPaint(hwnd
, &ps
);
1155 hFont
= pgauge
->hFont
;
1157 /* if system font, then return NULL handle */
1158 return (long)((hFont
== GetStockObject(SYSTEM_FONT
)) ? NULL
: hFont
);
1161 /* if NULL hFont, use system font */
1162 if (!(hFont
= (HFONT
)wParam
))
1163 hFont
= (HFONT
) GetStockObject(SYSTEM_FONT
);
1165 pgauge
->hFont
= hFont
;
1167 /* redraw if indicated in message */
1170 InvalidateRect(hwnd
, NULL
, TRUE
);
1176 /* let the dialog mangler take care of this message */
1177 return (DefWindowProc(hwnd
, uMsg
, wParam
, lParam
));
1178 } /* gaugeWndProc() */
1181 /** EOF: zyzgauge.c **/
1183 #endif // wxUSE_GAUGE