From 366dbd2f814f6619d8e252645ccec154b318f723 Mon Sep 17 00:00:00 2001 From: Alexandre Julliard Date: Mon, 5 Mar 2007 16:42:30 +0100 Subject: [PATCH] clock: Make the window round in no title bar mode, to exercise SetWindowRgn. --- programs/clock/main.c | 16 +++++++++++++++- programs/clock/winclock.c | 14 +++++++++----- programs/clock/winclock.h | 2 +- 3 files changed, 25 insertions(+), 7 deletions(-) diff --git a/programs/clock/main.c b/programs/clock/main.c index 4dfef095d4f..e1d22882e7c 100644 --- a/programs/clock/main.c +++ b/programs/clock/main.c @@ -180,6 +180,7 @@ static VOID CLOCK_ToggleTitle(VOID) else { style = (style & ~(WS_POPUP|WS_THICKFRAME)) | WS_OVERLAPPEDWINDOW; SetMenu(Globals.hMainWnd, Globals.hMainMenu); + SetWindowRgn(Globals.hMainWnd, 0, TRUE); } SetWindowLong(Globals.hMainWnd, GWL_STYLE, style); SetWindowPos(Globals.hMainWnd, 0,0,0,0,0, @@ -311,7 +312,7 @@ static VOID CLOCK_Paint(HWND hWnd) FillRect(dcMem, &ps.rcPaint, GetStockObject(LTGRAY_BRUSH)); if(Globals.bAnalog) - AnalogClock(dcMem, Globals.MaxX, Globals.MaxY, Globals.bSeconds); + AnalogClock(dcMem, Globals.MaxX, Globals.MaxY, Globals.bSeconds, Globals.bWithoutTitle); else DigitalClock(dcMem, Globals.MaxX, Globals.MaxY, Globals.bSeconds, Globals.hFont); @@ -361,6 +362,19 @@ static LRESULT WINAPI CLOCK_WndProc (HWND hWnd, UINT msg, WPARAM wParam, LPARAM case WM_SIZE: { Globals.MaxX = LOWORD(lParam); Globals.MaxY = HIWORD(lParam); + if (Globals.bAnalog && Globals.bWithoutTitle) + { + RECT rect; + INT diameter = min( Globals.MaxX, Globals.MaxY ); + HRGN hrgn = CreateEllipticRgn( (Globals.MaxX - diameter) / 2, + (Globals.MaxY - diameter) / 2, + (Globals.MaxX + diameter) / 2, + (Globals.MaxY + diameter) / 2 ); + GetWindowRect( hWnd, &rect ); + MapWindowPoints( 0, hWnd, (LPPOINT)&rect, 2 ); + OffsetRgn( hrgn, -rect.left, -rect.top ); + SetWindowRgn( Globals.hMainWnd, hrgn, TRUE ); + } CLOCK_ResetFont(); break; } diff --git a/programs/clock/winclock.c b/programs/clock/winclock.c index d699973143c..eb31eb1ff7f 100644 --- a/programs/clock/winclock.c +++ b/programs/clock/winclock.c @@ -82,7 +82,7 @@ static void DrawTicks(HDC dc, const POINT* centre, int radius) } } -static void DrawFace(HDC dc, const POINT* centre, int radius) +static void DrawFace(HDC dc, const POINT* centre, int radius, int border) { /* Ticks */ SelectObject(dc, CreatePen(PS_SOLID, 2, ShadowColor)); @@ -91,8 +91,12 @@ static void DrawFace(HDC dc, const POINT* centre, int radius) DeleteObject(SelectObject(dc, CreatePen(PS_SOLID, 2, TickColor))); OffsetWindowOrgEx(dc, SHADOW_DEPTH, SHADOW_DEPTH, NULL); DrawTicks(dc, centre, radius); - - DeleteObject(SelectObject(dc, GetStockObject(NULL_BRUSH))); + if (border) + { + SelectObject(dc, GetStockObject(NULL_BRUSH)); + DeleteObject(SelectObject(dc, CreatePen(PS_SOLID, 5, ShadowColor))); + Ellipse(dc, centre->x - radius, centre->y - radius, centre->x + radius, centre->y + radius); + } DeleteObject(SelectObject(dc, GetStockObject(NULL_PEN))); } @@ -159,7 +163,7 @@ static void PositionHands(const POINT* centre, int radius, BOOL bSeconds) PositionHand(centre, radius * 0.79, second/60 * 2*M_PI, &SecondHand); } -void AnalogClock(HDC dc, int x, int y, BOOL bSeconds) +void AnalogClock(HDC dc, int x, int y, BOOL bSeconds, BOOL border) { POINT centre; int radius; @@ -171,7 +175,7 @@ void AnalogClock(HDC dc, int x, int y, BOOL bSeconds) centre.x = x/2; centre.y = y/2; - DrawFace(dc, ¢re, radius); + DrawFace(dc, ¢re, radius, border); PositionHands(¢re, radius, bSeconds); DrawHands(dc, bSeconds); diff --git a/programs/clock/winclock.h b/programs/clock/winclock.h index 8cc0a8597b6..bcd26374f8e 100644 --- a/programs/clock/winclock.h +++ b/programs/clock/winclock.h @@ -21,6 +21,6 @@ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA */ -void AnalogClock(HDC dc, int X, int Y, BOOL bSeconds); +void AnalogClock(HDC dc, int X, int Y, BOOL bSeconds, BOOL border); HFONT SizeFont(HDC dc, int x, int y, BOOL bSeconds, const LOGFONT* font); void DigitalClock(HDC dc, int X, int Y, BOOL bSeconds, HFONT font);