So the program below will move the mouse cursor in a circle all 360 degrees for 2,5 seconds (after 2,5 seconds, the program exits and the user can use his/her cursor normally).
#include <Windows.h>
#include <math.h>
const double RADIANS_PER_DEGREE = acos(-1.0) / 180.0; // acos(-1.0) = Pi
const int SLEEP_DURATION = 2500 / 360;
int APIENTRY wWinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPWSTR lpCmdLine,
int nCmdShow)
{
const int screenWidth = GetSystemMetrics(SM_CXSCREEN);
const int screenHeight = GetSystemMetrics(SM_CYSCREEN);
const int screenCenterX = screenWidth / 2;
const int screenCenterY = screenHeight / 2;
const int radius = 3 * min(screenWidth / 2, screenHeight / 2) / 4;
int currentDegree = 90;
for (int degree = 0; degree < 360; degree++, currentDegree++) {
const int x = screenCenterX + (int)(radius * cos(currentDegree * RADIANS_PER_DEGREE));
const int y = screenCenterY - (int)(radius * sin(currentDegree * RADIANS_PER_DEGREE));
SetCursorPos(x, y);
Sleep(SLEEP_DURATION);
}
return 0;
}
Critique request
I would like to hear anything that comes to mind.