Opening a Window with Win32 on Windows

References

Build with:

gcc main.c
int64_t Timeus () { static int64_t ticks_per_microsecond; if (ticks_per_microsecond == 0) { LARGE_INTEGER frequency; QueryPerformanceFrequency (&frequency); ticks_per_microsecond = frequency.QuadPart / 1000000ll; } LARGE_INTEGER ticks; QueryPerformanceCounter (&ticks); return ticks.QuadPart / ticks_per_microsecond; }

QueryPerformanceCounter gives us access to a high resolution, fixed-rate timer. It is guaranteed to be supported on any Windows version starting with XP. The tick-rate of the counter is arbitrary, determined by Windows at boot, and does not change. We have to retrieve that tick-rate once, with QueryPerformanceFrequency. This tick-rate is in ticks per second, so we convert to ticks per microsecond, then use the resulting value whenever we retrieve the counter to convert it from ticks to microseconds.