clock: Make the window round in no title bar mode, to exercise SetWindowRgn.

oldstable
Alexandre Julliard 2007-03-05 16:42:30 +01:00
parent 69299c7738
commit 366dbd2f81
3 changed files with 25 additions and 7 deletions

View File

@ -180,6 +180,7 @@ static VOID CLOCK_ToggleTitle(VOID)
else { else {
style = (style & ~(WS_POPUP|WS_THICKFRAME)) | WS_OVERLAPPEDWINDOW; style = (style & ~(WS_POPUP|WS_THICKFRAME)) | WS_OVERLAPPEDWINDOW;
SetMenu(Globals.hMainWnd, Globals.hMainMenu); SetMenu(Globals.hMainWnd, Globals.hMainMenu);
SetWindowRgn(Globals.hMainWnd, 0, TRUE);
} }
SetWindowLong(Globals.hMainWnd, GWL_STYLE, style); SetWindowLong(Globals.hMainWnd, GWL_STYLE, style);
SetWindowPos(Globals.hMainWnd, 0,0,0,0,0, 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)); FillRect(dcMem, &ps.rcPaint, GetStockObject(LTGRAY_BRUSH));
if(Globals.bAnalog) if(Globals.bAnalog)
AnalogClock(dcMem, Globals.MaxX, Globals.MaxY, Globals.bSeconds); AnalogClock(dcMem, Globals.MaxX, Globals.MaxY, Globals.bSeconds, Globals.bWithoutTitle);
else else
DigitalClock(dcMem, Globals.MaxX, Globals.MaxY, Globals.bSeconds, Globals.hFont); 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: { case WM_SIZE: {
Globals.MaxX = LOWORD(lParam); Globals.MaxX = LOWORD(lParam);
Globals.MaxY = HIWORD(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(); CLOCK_ResetFont();
break; break;
} }

View File

@ -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 */ /* Ticks */
SelectObject(dc, CreatePen(PS_SOLID, 2, ShadowColor)); 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))); DeleteObject(SelectObject(dc, CreatePen(PS_SOLID, 2, TickColor)));
OffsetWindowOrgEx(dc, SHADOW_DEPTH, SHADOW_DEPTH, NULL); OffsetWindowOrgEx(dc, SHADOW_DEPTH, SHADOW_DEPTH, NULL);
DrawTicks(dc, centre, radius); DrawTicks(dc, centre, radius);
if (border)
DeleteObject(SelectObject(dc, GetStockObject(NULL_BRUSH))); {
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))); 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); 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; POINT centre;
int radius; int radius;
@ -171,7 +175,7 @@ void AnalogClock(HDC dc, int x, int y, BOOL bSeconds)
centre.x = x/2; centre.x = x/2;
centre.y = y/2; centre.y = y/2;
DrawFace(dc, &centre, radius); DrawFace(dc, &centre, radius, border);
PositionHands(&centre, radius, bSeconds); PositionHands(&centre, radius, bSeconds);
DrawHands(dc, bSeconds); DrawHands(dc, bSeconds);

View File

@ -21,6 +21,6 @@
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA * 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); 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); void DigitalClock(HDC dc, int X, int Y, BOOL bSeconds, HFONT font);