Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
W
wine-winehq
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
wine
wine-winehq
Commits
fa7060cb
Commit
fa7060cb
authored
Dec 03, 2003
by
Richard Cohen
Committed by
Alexandre Julliard
Dec 03, 2003
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
- Properly disable the second hand.
- Remove unneeded #include "winnls", #define MIN. - Get the digital clock working.
parent
64fb191c
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
90 additions
and
45 deletions
+90
-45
main.c
programs/clock/main.c
+39
-11
winclock.c
programs/clock/winclock.c
+49
-32
winclock.h
programs/clock/winclock.h
+2
-2
No files found.
programs/clock/main.c
View file @
fa7060cb
...
...
@@ -37,12 +37,38 @@
#define INITIAL_WINDOW_SIZE 200
#define TIMER_ID 1
#define TIMER_PERIOD 50
/* milliseconds */
CLOCK_GLOBALS
Globals
;
/***********************************************************************
*
* CLOCK_ResetTimer
*/
static
BOOL
CLOCK_ResetTimer
(
void
)
{
UINT
period
;
/* milliseconds */
KillTimer
(
Globals
.
hMainWnd
,
TIMER_ID
);
if
(
Globals
.
bSeconds
)
if
(
Globals
.
bAnalog
)
period
=
50
;
else
period
=
500
;
else
period
=
1000
;
if
(
!
SetTimer
(
Globals
.
hMainWnd
,
TIMER_ID
,
period
,
NULL
))
{
CHAR
szApp
[
MAX_STRING_LEN
];
LoadString
(
Globals
.
hInstance
,
IDS_CLOCK
,
szApp
,
sizeof
(
szApp
));
MessageBox
(
0
,
"No available timers"
,
szApp
,
MB_ICONEXCLAMATION
|
MB_OK
);
return
FALSE
;
}
return
TRUE
;
}
/***********************************************************************
*
* CLOCK_MenuCommand
*
* All handling of main menu events
...
...
@@ -57,14 +83,16 @@ int CLOCK_MenuCommand (WPARAM wParam)
case
IDM_ANALOG
:
{
Globals
.
bAnalog
=
TRUE
;
LANGUAGE_UpdateMenuCheckmarks
();
SendMessage
(
Globals
.
hMainWnd
,
WM_PAINT
,
0
,
0
);
CLOCK_ResetTimer
();
InvalidateRect
(
Globals
.
hMainWnd
,
NULL
,
FALSE
);
break
;
}
/* switch to digital */
case
IDM_DIGITAL
:
{
Globals
.
bAnalog
=
FALSE
;
LANGUAGE_UpdateMenuCheckmarks
();
SendMessage
(
Globals
.
hMainWnd
,
WM_PAINT
,
0
,
0
);
CLOCK_ResetTimer
();
InvalidateRect
(
Globals
.
hMainWnd
,
NULL
,
FALSE
);
break
;
}
/* change font */
...
...
@@ -89,7 +117,8 @@ int CLOCK_MenuCommand (WPARAM wParam)
case
IDM_SECONDS
:
{
Globals
.
bSeconds
=
!
Globals
.
bSeconds
;
LANGUAGE_UpdateMenuCheckmarks
();
SendMessage
(
Globals
.
hMainWnd
,
WM_PAINT
,
0
,
0
);
CLOCK_ResetTimer
();
InvalidateRect
(
Globals
.
hMainWnd
,
NULL
,
FALSE
);
break
;
}
/* show or hide date */
...
...
@@ -174,9 +203,9 @@ LRESULT WINAPI CLOCK_WndProc (HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
context
=
BeginPaint
(
hWnd
,
&
ps
);
if
(
Globals
.
bAnalog
)
AnalogClock
(
context
,
Globals
.
MaxX
,
Globals
.
MaxY
);
AnalogClock
(
context
,
Globals
.
MaxX
,
Globals
.
MaxY
,
Globals
.
bSeconds
);
else
DigitalClock
(
context
,
Globals
.
MaxX
,
Globals
.
MaxY
);
DigitalClock
(
context
,
Globals
.
MaxX
,
Globals
.
MaxY
,
Globals
.
bSeconds
);
EndPaint
(
hWnd
,
&
ps
);
break
;
}
...
...
@@ -193,7 +222,7 @@ LRESULT WINAPI CLOCK_WndProc (HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
}
case
WM_TIMER
:
{
/* Could just invalidate
the changed hands
,
/* Could just invalidate
what has changed
,
* but it doesn't really seem worth the effort
*/
InvalidateRect
(
Globals
.
hMainWnd
,
NULL
,
FALSE
);
...
...
@@ -212,7 +241,6 @@ LRESULT WINAPI CLOCK_WndProc (HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
}
/***********************************************************************
*
* WinMain
...
...
@@ -260,10 +288,8 @@ int PASCAL WinMain (HINSTANCE hInstance, HINSTANCE prev, LPSTR cmdline, int show
Globals
.
MaxX
,
Globals
.
MaxY
,
0
,
0
,
Globals
.
hInstance
,
0
);
if
(
!
SetTimer
(
Globals
.
hMainWnd
,
TIMER_ID
,
TIMER_PERIOD
,
NULL
))
{
MessageBox
(
0
,
"No available timers"
,
szWinName
,
MB_ICONEXCLAMATION
|
MB_OK
);
if
(
!
CLOCK_ResetTimer
())
return
FALSE
;
}
LANGUAGE_LoadMenus
();
SetMenu
(
Globals
.
hMainWnd
,
Globals
.
hMainMenu
);
...
...
@@ -278,5 +304,7 @@ int PASCAL WinMain (HINSTANCE hInstance, HINSTANCE prev, LPSTR cmdline, int show
DispatchMessage
(
&
msg
);
}
KillTimer
(
Globals
.
hMainWnd
,
TIMER_ID
);
return
0
;
}
programs/clock/winclock.c
View file @
fa7060cb
...
...
@@ -31,15 +31,14 @@
#include <stdlib.h>
#include <string.h>
#include "windows.h"
#include "winnls.h"
#include "winclock.h"
#define MIN(a,b) (((a)<(b))?(a):(b))
COLORREF
FaceColor
=
RGB
(
192
,
192
,
192
);
COLORREF
HandColor
=
RGB
(
0
,
0
,
0
);
COLORREF
EtchColor
=
RGB
(
0
,
0
,
0
)
;
static
COLORREF
FaceColor
=
RGB
(
192
,
192
,
192
);
static
COLORREF
HandColor
=
RGB
(
0
,
0
,
0
);
static
COLORREF
EtchColor
=
RGB
(
0
,
0
,
0
);
static
COLORREF
GRAY
=
RGB
(
128
,
128
,
128
);
static
const
int
ETCH_DEPTH
=
2
;
typedef
struct
{
POINT
Start
;
...
...
@@ -83,10 +82,11 @@ static void DrawHand(HDC dc,HandData* hand)
LineTo
(
dc
,
hand
->
End
.
x
,
hand
->
End
.
y
);
}
static
void
DrawHands
(
HDC
dc
)
static
void
DrawHands
(
HDC
dc
,
BOOL
bSeconds
)
{
SelectObject
(
dc
,
CreatePen
(
PS_SOLID
,
1
,
HandColor
));
DrawHand
(
dc
,
&
SecondHand
);
if
(
bSeconds
)
DrawHand
(
dc
,
&
SecondHand
);
DrawHand
(
dc
,
&
MinuteHand
);
DrawHand
(
dc
,
&
HourHand
);
DeleteObject
(
SelectObject
(
dc
,
GetStockObject
(
NULL_PEN
)));
...
...
@@ -99,7 +99,7 @@ static void PositionHand(const POINT* centre, double length, double angle, HandD
hand
->
End
.
y
=
centre
->
y
-
cos
(
angle
)
*
length
;
}
static
void
PositionHands
(
const
POINT
*
centre
,
int
radius
)
static
void
PositionHands
(
const
POINT
*
centre
,
int
radius
,
BOOL
bSeconds
)
{
SYSTEMTIME
st
;
double
hour
,
minute
,
second
;
...
...
@@ -114,40 +114,57 @@ static void PositionHands(const POINT* centre, int radius)
PositionHand
(
centre
,
radius
*
0
.
5
,
hour
/
12
*
2
*
M_PI
,
&
HourHand
);
PositionHand
(
centre
,
radius
*
0
.
65
,
minute
/
60
*
2
*
M_PI
,
&
MinuteHand
);
PositionHand
(
centre
,
radius
*
0
.
79
,
second
/
60
*
2
*
M_PI
,
&
SecondHand
);
if
(
bSeconds
)
PositionHand
(
centre
,
radius
*
0
.
79
,
second
/
60
*
2
*
M_PI
,
&
SecondHand
);
}
void
AnalogClock
(
HDC
dc
,
int
x
,
int
y
)
void
AnalogClock
(
HDC
dc
,
int
x
,
int
y
,
BOOL
bSeconds
)
{
POINT
centre
;
int
radius
;
radius
=
MIN
(
x
,
y
)
/
2
;
radius
=
min
(
x
,
y
)
/
2
;
centre
.
x
=
x
/
2
;
centre
.
y
=
y
/
2
;
DrawFace
(
dc
,
&
centre
,
radius
);
PositionHands
(
&
centre
,
radius
);
DrawHands
(
dc
);
PositionHands
(
&
centre
,
radius
,
bSeconds
);
DrawHands
(
dc
,
bSeconds
);
}
void
DigitalClock
(
HDC
dc
,
int
X
,
int
Y
)
void
DigitalClock
(
HDC
dc
,
int
x
,
int
y
,
BOOL
bSeconds
)
{
/* FIXME - this doesn't work very well */
CHAR
szTime
[
255
];
static
short
xChar
,
yChar
;
TEXTMETRIC
tm
;
SYSTEMTIME
st
;
GetLocalTime
(
&
st
);
GetTimeFormat
(
LOCALE_USER_DEFAULT
,
LOCALE_STIMEFORMAT
,
&
st
,
NULL
,
szTime
,
sizeof
szTime
);
xChar
=
tm
.
tmAveCharWidth
;
yChar
=
tm
.
tmHeight
;
xChar
=
100
;
yChar
=
100
;
SelectObject
(
dc
,
CreatePen
(
PS_SOLID
,
1
,
FaceColor
));
TextOut
(
dc
,
xChar
,
yChar
,
szTime
,
strlen
(
szTime
));
DeleteObject
(
SelectObject
(
dc
,
GetStockObject
(
NULL_PEN
)));
SIZE
extent
;
LOGFONT
lf
;
double
xscale
,
yscale
;
HFONT
oldFont
;
GetTimeFormat
(
LOCALE_USER_DEFAULT
,
bSeconds
?
0
:
TIME_NOSECONDS
,
NULL
,
NULL
,
szTime
,
sizeof
(
szTime
));
memset
(
&
lf
,
0
,
sizeof
(
lf
));
lf
.
lfHeight
=
-
20
;
x
-=
2
*
ETCH_DEPTH
;
y
-=
2
*
ETCH_DEPTH
;
oldFont
=
SelectObject
(
dc
,
CreateFontIndirect
(
&
lf
));
GetTextExtentPoint
(
dc
,
szTime
,
strlen
(
szTime
),
&
extent
);
xscale
=
(
double
)
x
/
extent
.
cx
;
yscale
=
(
double
)
y
/
extent
.
cy
;
lf
.
lfHeight
*=
min
(
xscale
,
yscale
);
DeleteObject
(
SelectObject
(
dc
,
CreateFontIndirect
(
&
lf
)));
GetTextExtentPoint
(
dc
,
szTime
,
strlen
(
szTime
),
&
extent
);
SetBkColor
(
dc
,
GRAY
);
/* to match the background brush */
SetTextColor
(
dc
,
EtchColor
);
TextOut
(
dc
,
(
x
-
extent
.
cx
)
/
2
+
ETCH_DEPTH
,
(
y
-
extent
.
cy
)
/
2
+
ETCH_DEPTH
,
szTime
,
strlen
(
szTime
));
SetBkMode
(
dc
,
TRANSPARENT
);
SetTextColor
(
dc
,
FaceColor
);
TextOut
(
dc
,
(
x
-
extent
.
cx
)
/
2
,
(
y
-
extent
.
cy
)
/
2
,
szTime
,
strlen
(
szTime
));
DeleteObject
(
SelectObject
(
dc
,
oldFont
));
}
programs/clock/winclock.h
View file @
fa7060cb
...
...
@@ -21,5 +21,5 @@
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
void
AnalogClock
(
HDC
dc
,
int
X
,
int
Y
);
void
DigitalClock
(
HDC
dc
,
int
X
,
int
Y
);
void
AnalogClock
(
HDC
dc
,
int
X
,
int
Y
,
BOOL
bSeconds
);
void
DigitalClock
(
HDC
dc
,
int
X
,
int
Y
,
BOOL
bSeconds
);
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment