Ticking Dialog
A Win32 dialog that displays the system tick count updating as fast as the timer allows — a minimal high-frequency UI refresh example.
The smallest possible "live number on screen" demo. A dialog starts a 1 ms timer in WM_INITDIALOG; each tick calls Update to repaint, and a loop_function (invoked from the app's main loop) writes the current GetTickCount() value into a static control via SetText. It is a useful reference for understanding how fast Windows will actually let you refresh a window - the 1 ms request gets coalesced by the message queue to roughly the display's refresh rate - and for building simple counters, elapsed-time displays, or animation loops.
//---------------------------------------------------------------------------
#include "Headers/Functions.H" //----------------------------------------------------
#include "Dialogs/MainDialog.H"
//---------------------------------------------------------------------------
/////////////////////////////////////////////////////////////////////////////
extern int WINAPI WinMain (HWND hInst, HWND hPrev, LPSTR Cmd, int nCmdShow)
{
hInstance=hInst;
DialogBox(hInstance,MAKEINTRESOURCE(100),0,Clock);
return 0;
}
/////////////////////////////////////////////////////////////////////////////
extern char *loop_function (int i)
{
SetText(clock,str(GetTickCount()));
return "Dialog Title"; //Dialog Title Here
}
extern int Clock (HWND hDlg, int Msg, int wParam, int lParam)
{
for(;;)
{
if(Msg==WM_INITDIALOG)
{
hWnd=hDlg;
SetTimer(hWnd,1,1,NULL);
/* Refresh Delay Here ^ */
//-------------(Dialog Definitions)---------(Start)
clock=GetDlgItem(hDlg,101);
//-------------(Dialog Definitions)----------(End)
CenterWindow(hWnd);
Update(hDlg);
break;
}
if(Msg==WM_TIMER)
{
Update(hDlg);
break;
}
if(Msg==WM_CLOSE)
{
KillTimer(hWnd,1);
EndDialog(hDlg,0);
}
break;
}
return 0;
}
The comment above the timer period marks the one knob that matters: lower it for a faster counter, raise it if the window is eating too much CPU. For sub-millisecond timing use QueryPerformanceCounter instead of GetTickCount, which wraps after about 49 days and only ticks at ~15 ms resolution on older systems.