2 * Copyright 2000, International Business Machines Corporation and others.
5 * This software has been released under the terms of the IBM Public
6 * License. For details, see the LICENSE file in the top-level source
7 * directory or online at http://www.openafs.org/dl/license10.html
11 #include <afs/param.h>
18 #include <WINNT/dialog.h>
19 #include <WINNT/resize.h> // for GetRectInParent()
20 #include <WINNT/subclass.h>
21 #include <WINNT/ctl_spinner.h>
22 #include <WINNT/ctl_elapsed.h>
23 #include <WINNT/TaLocale.h>
26 #define cchRESOURCE 256
31 * MISCELLANEOUS ______________________________________________________________
36 #define REALLOC(_a,_c,_r,_i) ElapsedReallocFunction ((LPVOID*)&_a,sizeof(*_a),&_c,_r,_i)
37 BOOL
ElapsedReallocFunction (LPVOID
*ppTarget
, size_t cbElement
, size_t *pcTarget
, size_t cReq
, size_t cInc
)
42 if (cReq
<= *pcTarget
)
45 if ((cNew
= cInc
* ((cReq
+ cInc
-1) / cInc
)) <= 0)
48 if ((pNew
= (LPVOID
)Allocate (cbElement
* cNew
)) == NULL
)
50 memset (pNew
, 0x00, cbElement
* cNew
);
54 memcpy (pNew
, *ppTarget
, cbElement
* (*pcTarget
));
67 * ELAPSEDS ___________________________________________________________________
86 SYSTEMTIME timeMin
; // only hour, minute, second fields are relevant
87 SYSTEMTIME timeNow
; // only hour, minute, second fields are relevant
88 SYSTEMTIME timeMax
; // only hour, minute, second fields are relevant
94 static CRITICAL_SECTION csElapsed
;
95 static ElapsedInfo
*aElapsed
= NULL
;
96 static size_t cElapsed
= 0;
98 #define cszELAPSEDCLASS TEXT("Elapsed")
100 HRESULT CALLBACK
ElapsedProc (HWND hElapsed
, UINT msg
, WPARAM wp
, LPARAM lp
);
101 HRESULT CALLBACK
ElapsedEditProc (HWND hEdit
, UINT msg
, WPARAM wp
, LPARAM lp
);
102 HRESULT CALLBACK
ElapsedDlgProc (HWND hDlg
, UINT msg
, WPARAM wp
, LPARAM lp
);
104 void Elapsed_SendCallback (ElapsedInfo
*pei
, WORD eln
, LPARAM lp
);
106 void Elapsed_OnCreate (ElapsedInfo
*psi
);
107 void Elapsed_OnDestroy (ElapsedInfo
*psi
);
108 void Elapsed_OnButtonDown (ElapsedInfo
*pei
, UINT msg
, WPARAM wp
, LPARAM lp
);
109 BOOL
Elapsed_OnGetRange (ElapsedInfo
*psi
, WPARAM wp
, LPARAM lp
);
110 BOOL
Elapsed_OnSetRange (ElapsedInfo
*psi
, WPARAM wp
, LPARAM lp
);
111 BOOL
Elapsed_OnGetTime (ElapsedInfo
*psi
, WPARAM wp
, LPARAM lp
);
112 BOOL
Elapsed_OnSetTime (ElapsedInfo
*psi
, WPARAM wp
, LPARAM lp
);
114 void Elapsed_Edit_OnSetFocus (ElapsedInfo
*pei
, HWND hEdit
);
115 void Elapsed_Edit_GetSpinnerRange (ElapsedInfo
*pei
, HWND hEdit
, DWORD
*pdwMin
, DWORD
*pdwPos
, DWORD
*pdwMax
);
116 void Elapsed_Edit_OnUpdate (ElapsedInfo
*pei
, HWND hEdit
, DWORD dwNew
);
117 void Elapsed_Edit_OnEnforceRange (ElapsedInfo
*pei
, HWND hEdit
);
118 void Elapsed_Edit_SetText (ElapsedInfo
*pei
, HWND hEdit
);
121 BOOL
RegisterElapsedClass (void)
123 static BOOL fRegistered
= FALSE
;
127 InitializeCriticalSection (&csElapsed
);
130 memset (&wc
, 0x00, sizeof(wc
));
131 wc
.style
= CS_GLOBALCLASS
;
132 wc
.lpfnWndProc
= (WNDPROC
)ElapsedProc
;
133 wc
.hInstance
= THIS_HINST
;
134 wc
.hCursor
= LoadCursor (NULL
, MAKEINTRESOURCE (IDC_ARROW
));
135 wc
.hbrBackground
= CreateSolidBrush (GetSysColor (COLOR_BTNFACE
));
136 wc
.lpszClassName
= cszELAPSEDCLASS
;
138 if (RegisterClass (&wc
))
146 void Elapsed_SendCallback (ElapsedInfo
*pei
, WORD eln
, LPARAM lp
)
148 if ((pei
->fCanCallBack
== TRUE
) && !pei
->fCallingBack
)
150 pei
->fCallingBack
= TRUE
;
152 SendMessage (GetParent (pei
->hElapsed
),
154 MAKELONG ((WORD
)GetWindowLong (pei
->hElapsed
, GWL_ID
), eln
),
157 pei
->fCallingBack
= FALSE
;
162 HRESULT CALLBACK
ElapsedProc (HWND hElapsed
, UINT msg
, WPARAM wp
, LPARAM lp
)
164 ElapsedInfo
*pei
= NULL
;
166 EnterCriticalSection (&csElapsed
);
168 if (msg
== WM_CREATE
)
171 for (iElapsed
= 0; iElapsed
< cElapsed
; ++iElapsed
)
173 if (aElapsed
[ iElapsed
].hElapsed
== NULL
)
176 if (iElapsed
>= cElapsed
)
178 if (!REALLOC (aElapsed
, cElapsed
, 1+iElapsed
, 4))
182 memset (&aElapsed
[ iElapsed
], 0x00, sizeof(ElapsedInfo
));
183 aElapsed
[ iElapsed
].hElapsed
= hElapsed
;
185 pei
= &aElapsed
[ iElapsed
];
189 for (size_t iElapsed
= 0; !pei
&& iElapsed
< cElapsed
; ++iElapsed
)
191 if (aElapsed
[ iElapsed
].hElapsed
== hElapsed
)
192 pei
= &aElapsed
[ iElapsed
];
196 LeaveCriticalSection (&csElapsed
);
203 Elapsed_OnCreate (pei
);
207 Elapsed_OnDestroy (pei
);
212 Elapsed_OnButtonDown (pei
, msg
, wp
, lp
);
216 PostMessage (GetParent(hElapsed
), WM_NEXTDLGCTL
, (WPARAM
)pei
->hHours
, TRUE
);
220 EnableWindow (pei
->hHours
, IsWindowEnabled (hElapsed
));
221 EnableWindow (pei
->hSep1
, IsWindowEnabled (hElapsed
));
222 EnableWindow (pei
->hMinutes
, IsWindowEnabled (hElapsed
));
223 EnableWindow (pei
->hSep2
, IsWindowEnabled (hElapsed
));
224 EnableWindow (pei
->hSeconds
, IsWindowEnabled (hElapsed
));
225 EnableWindow (pei
->hSpinner
, IsWindowEnabled (hElapsed
));
228 GetRectInParent (hElapsed
, &rElapsed
);
229 InvalidateRect (GetParent(hElapsed
), &rElapsed
, TRUE
);
230 UpdateWindow (GetParent(hElapsed
));
238 PostMessage (GetParent(pei
->hSpinner
), WM_VSCROLL
, SB_LINEUP
, (LPARAM
)pei
->hSpinner
);
242 PostMessage (GetParent(pei
->hSpinner
), WM_VSCROLL
, SB_LINEDOWN
, (LPARAM
)pei
->hSpinner
);
246 PostMessage (GetParent(pei
->hSpinner
), WM_VSCROLL
, SB_PAGEUP
, (LPARAM
)pei
->hSpinner
);
250 PostMessage (GetParent(pei
->hSpinner
), WM_VSCROLL
, SB_PAGEDOWN
, (LPARAM
)pei
->hSpinner
);
254 PostMessage (GetParent(pei
->hSpinner
), WM_VSCROLL
, SB_TOP
, (LPARAM
)pei
->hSpinner
);
258 PostMessage (GetParent(pei
->hSpinner
), WM_VSCROLL
, SB_BOTTOM
, (LPARAM
)pei
->hSpinner
);
264 return Elapsed_OnGetRange (pei
, wp
, lp
);
267 return Elapsed_OnSetRange (pei
, wp
, lp
);
270 return Elapsed_OnGetTime (pei
, wp
, lp
);
273 return Elapsed_OnSetTime (pei
, wp
, lp
);
277 return DefWindowProc (hElapsed
, msg
, wp
, lp
);
281 void Elapsed_OnCreate (ElapsedInfo
*pei
)
283 Subclass_AddHook (GetParent(pei
->hElapsed
), ElapsedDlgProc
);
285 TCHAR szTimeSep
[ cchRESOURCE
];
286 if (!GetLocaleInfo (LOCALE_USER_DEFAULT
, LOCALE_STIME
, szTimeSep
, cchRESOURCE
))
287 lstrcpy (szTimeSep
, TEXT(":"));
290 GetClientRect (pei
->hElapsed
, &rElapsed
);
292 POINT ptElapsed
= {0,0};
293 ClientToScreen (pei
->hElapsed
, &ptElapsed
);
294 ScreenToClient (GetParent (pei
->hElapsed
), &ptElapsed
);
296 SIZE s88
; // size of widest likely double-digit number
297 SIZE s888
; // maximum width to which we'll go for second- and minute- fields
298 SIZE sTimeSep
; // size of ":"
300 HDC hdc
= GetDC (GetParent (pei
->hElapsed
));
301 GetTextExtentPoint (hdc
, TEXT("88"), lstrlen(TEXT("88")), &s88
);
302 GetTextExtentPoint (hdc
, szTimeSep
, lstrlen(szTimeSep
), &sTimeSep
);
303 ReleaseDC (GetParent (pei
->hElapsed
), hdc
);
306 s888
.cx
= (LONG
)( (double)(s88
.cx
) * 1.2 );
308 LONG cxNumbers
= cxRECT(rElapsed
) - (2 * sTimeSep
.cx
) - GetSystemMetrics (SM_CXVSCROLL
);
309 LONG cxSeconds
= min( max( cxNumbers
/3, s88
.cx
), s888
.cx
);
310 LONG cxMinutes
= min( max( cxNumbers
/3, s88
.cx
), s888
.cx
);
311 LONG cxHours
= cxNumbers
- cxSeconds
- cxMinutes
;
312 LONG yy
= ptElapsed
.y
;
313 LONG cy
= cyRECT(rElapsed
);
315 pei
->idHours
= 100+NextControlID (GetParent (pei
->hElapsed
));
316 pei
->hHours
= CreateWindow (
319 WS_CHILD
| WS_TABSTOP
| ES_RIGHT
| ES_NUMBER
,
320 ptElapsed
.x
, yy
, cxHours
, cy
,
321 GetParent(pei
->hElapsed
),
326 pei
->hSep1
= CreateWindow (
330 ptElapsed
.x
+ cxHours
, yy
, sTimeSep
.cx
, cy
,
331 GetParent(pei
->hElapsed
),
336 pei
->idMinutes
= 100+NextControlID (GetParent (pei
->hElapsed
));
337 pei
->hMinutes
= CreateWindow (
340 WS_CHILD
| WS_TABSTOP
| ES_RIGHT
| ES_NUMBER
,
341 ptElapsed
.x
+ cxHours
+ sTimeSep
.cx
, yy
, cxMinutes
, cy
,
342 GetParent(pei
->hElapsed
),
343 (HMENU
)pei
->idMinutes
,
347 pei
->hSep2
= CreateWindow (
351 ptElapsed
.x
+ cxHours
+ cxMinutes
+ sTimeSep
.cx
, yy
, sTimeSep
.cx
, cy
,
352 GetParent(pei
->hElapsed
),
357 pei
->idSeconds
= 100+NextControlID (GetParent (pei
->hElapsed
));
358 pei
->hSeconds
= CreateWindow (
361 WS_CHILD
| WS_TABSTOP
| ES_RIGHT
| ES_NUMBER
,
362 ptElapsed
.x
+ cxHours
+ cxMinutes
+ 2 * sTimeSep
.cx
, yy
, cxSeconds
, cy
,
363 GetParent(pei
->hElapsed
),
364 (HMENU
)pei
->idSeconds
,
368 Subclass_AddHook (pei
->hHours
, ElapsedEditProc
);
369 Subclass_AddHook (pei
->hMinutes
, ElapsedEditProc
);
370 Subclass_AddHook (pei
->hSeconds
, ElapsedEditProc
);
372 HFONT hf
= (HFONT
)SendMessage (GetParent (pei
->hElapsed
), WM_GETFONT
, 0, 0);
373 SendMessage (pei
->hHours
, WM_SETFONT
, (WPARAM
)hf
, MAKELPARAM(TRUE
,0));
374 SendMessage (pei
->hSep1
, WM_SETFONT
, (WPARAM
)hf
, MAKELPARAM(TRUE
,0));
375 SendMessage (pei
->hMinutes
, WM_SETFONT
, (WPARAM
)hf
, MAKELPARAM(TRUE
,0));
376 SendMessage (pei
->hSep2
, WM_SETFONT
, (WPARAM
)hf
, MAKELPARAM(TRUE
,0));
377 SendMessage (pei
->hSeconds
, WM_SETFONT
, (WPARAM
)hf
, MAKELPARAM(TRUE
,0));
379 EnableWindow (pei
->hHours
, IsWindowEnabled (pei
->hElapsed
));
380 EnableWindow (pei
->hSep1
, IsWindowEnabled (pei
->hElapsed
));
381 EnableWindow (pei
->hMinutes
, IsWindowEnabled (pei
->hElapsed
));
382 EnableWindow (pei
->hSep2
, IsWindowEnabled (pei
->hElapsed
));
383 EnableWindow (pei
->hSeconds
, IsWindowEnabled (pei
->hElapsed
));
385 ShowWindow (pei
->hHours
, TRUE
);
386 ShowWindow (pei
->hSep1
, TRUE
);
387 ShowWindow (pei
->hMinutes
, TRUE
);
388 ShowWindow (pei
->hSep2
, TRUE
);
389 ShowWindow (pei
->hSeconds
, TRUE
);
392 GetWindowRect (pei
->hElapsed
, &rWindow
);
393 rWindow
.right
+= (cxHours
+ cxMinutes
+ cxSeconds
+ 2 * sTimeSep
.cx
) - cxRECT(rElapsed
);
395 SetWindowPos (pei
->hElapsed
, NULL
, 0, 0, cxRECT(rWindow
), cyRECT(rWindow
),
396 SWP_NOMOVE
| SWP_NOACTIVATE
| SWP_NOZORDER
);
398 SET_ELAPSED_TIME(&pei
->timeMin
, 0, 0, 0);
399 SET_ELAPSED_TIME(&pei
->timeMax
, 24, 0, 0);
401 Elapsed_Edit_OnEnforceRange (pei
, pei
->hHours
);
402 Elapsed_Edit_OnEnforceRange (pei
, pei
->hMinutes
);
403 Elapsed_Edit_OnEnforceRange (pei
, pei
->hSeconds
);
405 Elapsed_Edit_OnSetFocus (pei
, pei
->hHours
);
407 pei
->fCanCallBack
= TRUE
;
411 void Elapsed_OnDestroy (ElapsedInfo
*pei
)
413 Subclass_RemoveHook (GetParent(pei
->hElapsed
), ElapsedDlgProc
);
414 pei
->hElapsed
= NULL
;
418 void Elapsed_OnButtonDown (ElapsedInfo
*pei
, UINT msg
, WPARAM wp
, LPARAM lp
)
420 DWORD dw
= GetMessagePos();
423 pt
.y
= HIWORD(dw
); // in screen coordinates
428 GetWindowRect (pei
->hHours
, &rTarget
);
429 if (PtInRect (&rTarget
, pt
))
430 hTarget
= pei
->hHours
;
432 GetWindowRect (pei
->hMinutes
, &rTarget
);
433 if (PtInRect (&rTarget
, pt
))
434 hTarget
= pei
->hMinutes
;
436 GetWindowRect (pei
->hSeconds
, &rTarget
);
437 if (PtInRect (&rTarget
, pt
))
438 hTarget
= pei
->hSeconds
;
442 PostMessage (hTarget
, msg
, wp
, lp
);
447 BOOL
Elapsed_OnGetRange (ElapsedInfo
*pei
, WPARAM wp
, LPARAM lp
)
449 SYSTEMTIME
*ptimeMin
= (SYSTEMTIME
*)wp
;
450 SYSTEMTIME
*ptimeMax
= (SYSTEMTIME
*)lp
;
452 *ptimeMin
= pei
->timeMin
;
453 *ptimeMax
= pei
->timeMax
;
458 BOOL
Elapsed_OnSetRange (ElapsedInfo
*pei
, WPARAM wp
, LPARAM lp
)
460 SYSTEMTIME
*ptimeMin
= (SYSTEMTIME
*)wp
;
461 SYSTEMTIME
*ptimeMax
= (SYSTEMTIME
*)lp
;
463 pei
->timeMin
= *ptimeMin
;
464 pei
->timeMax
= *ptimeMax
;
466 Elapsed_Edit_OnEnforceRange (pei
, pei
->hHours
);
467 Elapsed_Edit_OnEnforceRange (pei
, pei
->hMinutes
);
468 Elapsed_Edit_OnEnforceRange (pei
, pei
->hSeconds
);
474 BOOL
Elapsed_OnGetTime (ElapsedInfo
*pei
, WPARAM wp
, LPARAM lp
)
476 SYSTEMTIME
*ptime
= (SYSTEMTIME
*)lp
;
477 *ptime
= pei
->timeNow
;
482 BOOL
Elapsed_OnSetTime (ElapsedInfo
*pei
, WPARAM wp
, LPARAM lp
)
484 SYSTEMTIME
*ptime
= (SYSTEMTIME
*)lp
;
485 pei
->timeNow
= *ptime
;
486 Elapsed_Edit_SetText (pei
, pei
->hHours
);
487 Elapsed_Edit_SetText (pei
, pei
->hMinutes
);
488 Elapsed_Edit_SetText (pei
, pei
->hSeconds
);
493 HRESULT CALLBACK
ElapsedDlgProc (HWND hDlg
, UINT msg
, WPARAM wp
, LPARAM lp
)
495 PVOID oldProc
= Subclass_FindNextHook (hDlg
, ElapsedDlgProc
);
500 case WM_CTLCOLOREDIT
:
501 case WM_CTLCOLORSTATIC
:
502 for (iElapsed
= 0; iElapsed
< cElapsed
; ++iElapsed
)
504 if (aElapsed
[ iElapsed
].hElapsed
== NULL
)
506 if ( (aElapsed
[ iElapsed
].hHours
== (HWND
)lp
) ||
507 (aElapsed
[ iElapsed
].hSep1
== (HWND
)lp
) ||
508 (aElapsed
[ iElapsed
].hMinutes
== (HWND
)lp
) ||
509 (aElapsed
[ iElapsed
].hSep2
== (HWND
)lp
) ||
510 (aElapsed
[ iElapsed
].hSeconds
== (HWND
)lp
) )
513 if (IsWindowEnabled (aElapsed
[ iElapsed
].hElapsed
))
514 clr
= GetSysColor (COLOR_WINDOW
);
516 clr
= GetSysColor (COLOR_BTNFACE
);
517 SetBkColor ((HDC
)wp
, clr
);
518 return (HRESULT
)(INT_PTR
)CreateSolidBrush (clr
);
524 for (iElapsed
= 0; iElapsed
< cElapsed
; ++iElapsed
)
526 if (aElapsed
[ iElapsed
].hElapsed
== NULL
)
528 if ( (aElapsed
[ iElapsed
].idHours
== LOWORD(wp
)) ||
529 (aElapsed
[ iElapsed
].idMinutes
== LOWORD(wp
)) ||
530 (aElapsed
[ iElapsed
].idSeconds
== LOWORD(wp
)) )
532 if (HIWORD(wp
) == SPN_UPDATE
)
534 Elapsed_Edit_OnUpdate (&aElapsed
[ iElapsed
], GetDlgItem (hDlg
, LOWORD(wp
)), (DWORD
)lp
);
543 return CallWindowProc ((WNDPROC
)oldProc
, hDlg
, msg
, wp
, lp
);
545 return DefWindowProc (hDlg
, msg
, wp
, lp
);
549 HRESULT CALLBACK
ElapsedEditProc (HWND hEdit
, UINT msg
, WPARAM wp
, LPARAM lp
)
551 ElapsedInfo
*pei
= NULL
;
553 EnterCriticalSection (&csElapsed
);
555 for (size_t iElapsed
= 0; !pei
&& iElapsed
< cElapsed
; ++iElapsed
)
557 if ( (aElapsed
[ iElapsed
].hHours
== hEdit
) ||
558 (aElapsed
[ iElapsed
].hMinutes
== hEdit
) ||
559 (aElapsed
[ iElapsed
].hSeconds
== hEdit
) )
561 pei
= &aElapsed
[ iElapsed
];
565 LeaveCriticalSection (&csElapsed
);
572 Elapsed_Edit_OnSetFocus (pei
, hEdit
);
577 PVOID oldProc
= Subclass_FindNextHook (hEdit
, ElapsedEditProc
);
579 return CallWindowProc ((WNDPROC
)oldProc
, hEdit
, msg
, wp
, lp
);
581 return DefWindowProc (hEdit
, msg
, wp
, lp
);
585 void Elapsed_Edit_OnSetFocus (ElapsedInfo
*pei
, HWND hEdit
)
587 pei
->fCanCallBack
--;
590 GetRectInParent (pei
->hElapsed
, &rSpinner
);
591 rSpinner
.left
= rSpinner
.right
;
592 rSpinner
.right
= rSpinner
.left
+ GetSystemMetrics (SM_CXVSCROLL
);
593 rSpinner
.bottom
-= 2; // just like Win95 does
598 Elapsed_Edit_GetSpinnerRange (pei
, hEdit
, &dwMin
, &dwPos
, &dwMax
);
600 CreateSpinner (hEdit
, 10, FALSE
, dwMin
, dwPos
, dwMax
, &rSpinner
);
602 DestroyWindow (pei
->hSpinner
);
604 if (hEdit
== pei
->hHours
)
605 SP_SetFormat (hEdit
, TEXT("%lu"));
607 SP_SetFormat (hEdit
, TEXT("%02lu"));
609 pei
->hSpinner
= SP_GetSpinner (hEdit
);
610 pei
->hSpinnerBuddy
= hEdit
;
612 SendMessage (hEdit
, EM_SETSEL
, (WPARAM
)0, (LPARAM
)-1); // select all
614 pei
->fCanCallBack
++;
618 void Elapsed_Edit_GetSpinnerRange (ElapsedInfo
*pei
, HWND hEdit
, DWORD
*pdwMin
, DWORD
*pdwNow
, DWORD
*pdwMax
)
620 if (hEdit
== pei
->hHours
)
622 *pdwMin
= pei
->timeMin
.wHour
+ pei
->timeMin
.wDay
* 24;
623 *pdwNow
= pei
->timeNow
.wHour
+ pei
->timeNow
.wDay
* 24;
624 *pdwMax
= pei
->timeMax
.wHour
+ pei
->timeMax
.wDay
* 24;
626 else if (hEdit
== pei
->hMinutes
)
628 if ( (pei
->timeNow
.wDay
== pei
->timeMin
.wDay
) &&
629 (pei
->timeNow
.wHour
== pei
->timeMin
.wHour
) )
630 *pdwMin
= pei
->timeMin
.wMinute
;
634 *pdwNow
= pei
->timeNow
.wMinute
;
636 if ( (pei
->timeNow
.wDay
== pei
->timeMax
.wDay
) &&
637 (pei
->timeNow
.wHour
== pei
->timeMax
.wHour
) )
638 *pdwMax
= pei
->timeMax
.wMinute
;
642 else if (hEdit
== pei
->hSeconds
)
644 if ( (pei
->timeNow
.wDay
== pei
->timeMin
.wDay
) &&
645 (pei
->timeNow
.wHour
== pei
->timeMin
.wHour
) &&
646 (pei
->timeNow
.wMinute
== pei
->timeMin
.wMinute
) )
647 *pdwMin
= pei
->timeMin
.wSecond
;
651 *pdwNow
= pei
->timeNow
.wSecond
;
653 if ( (pei
->timeNow
.wDay
== pei
->timeMax
.wDay
) &&
654 (pei
->timeNow
.wHour
== pei
->timeMax
.wHour
) &&
655 (pei
->timeNow
.wMinute
== pei
->timeMax
.wMinute
) )
656 *pdwMax
= pei
->timeMax
.wSecond
;
663 void Elapsed_Edit_OnUpdate (ElapsedInfo
*pei
, HWND hEdit
, DWORD dwNew
)
669 Elapsed_Edit_GetSpinnerRange (pei
, hEdit
, &dwMin
, &dwNow
, &dwMax
);
671 dwNow
= limit( dwMin
, dwNew
, dwMax
);
673 if (hEdit
== pei
->hHours
)
675 pei
->timeNow
.wDay
= (WORD
)dwNow
/ 24;
676 pei
->timeNow
.wHour
= (WORD
)dwNow
% 24;
677 Elapsed_Edit_OnEnforceRange (pei
, pei
->hMinutes
);
678 Elapsed_Edit_OnEnforceRange (pei
, pei
->hSeconds
);
680 else if (hEdit
== pei
->hMinutes
)
682 pei
->timeNow
.wMinute
= (WORD
)dwNow
;
683 Elapsed_Edit_OnEnforceRange (pei
, pei
->hSeconds
);
685 else if (hEdit
== pei
->hSeconds
)
687 pei
->timeNow
.wSecond
= (WORD
)dwNow
;
690 SYSTEMTIME st
= pei
->timeNow
;
691 Elapsed_SendCallback (pei
, ELN_UPDATE
, (LPARAM
)&st
);
695 void Elapsed_Edit_OnEnforceRange (ElapsedInfo
*pei
, HWND hEdit
)
700 Elapsed_Edit_GetSpinnerRange (pei
, hEdit
, &dwMin
, &dwNow
, &dwMax
);
702 if (!inlimit( dwMin
, dwNow
, dwMax
))
704 dwNow
= limit( dwMin
, dwNow
, dwMax
);
706 if (hEdit
== pei
->hHours
)
708 pei
->timeNow
.wDay
= (WORD
)dwNow
/ 24;
709 pei
->timeNow
.wHour
= (WORD
)dwNow
% 24;
711 else if (hEdit
== pei
->hMinutes
)
713 pei
->timeNow
.wMinute
= (WORD
)dwNow
;
715 else if (hEdit
== pei
->hSeconds
)
717 pei
->timeNow
.wSecond
= (WORD
)dwNow
;
720 if (pei
->hSpinnerBuddy
== hEdit
)
721 SP_SetRange (hEdit
, dwMin
, dwMax
);
722 Elapsed_Edit_SetText (pei
, hEdit
);
724 else if (pei
->hSpinnerBuddy
== hEdit
)
726 SP_SetRange (hEdit
, dwMin
, dwMax
);
731 void Elapsed_Edit_SetText (ElapsedInfo
*pei
, HWND hEdit
)
736 Elapsed_Edit_GetSpinnerRange (pei
, hEdit
, &dwMin
, &dwNow
, &dwMax
);
738 if (pei
->hSpinnerBuddy
== hEdit
)
740 SP_SetPos (hEdit
, dwNow
);
744 TCHAR szText
[ cchRESOURCE
];
746 if (hEdit
== pei
->hHours
)
747 wsprintf (szText
, TEXT("%lu"), dwNow
);
749 wsprintf (szText
, TEXT("%02lu"), dwNow
);
751 SetWindowText (hEdit
, szText
);