Moving in a circle

I'm making this program to mess with people and make them think its a virus.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
#define _WIN32_WINNT 0x0500 //For hiding your console

#include <cstdlib>
#include <iostream>
#include <Windows.h>
#include <WinBase.h>

using namespace std;

void Beeper(), Craze(), TrollM(), HideWin(), WarningM();
HWND hWnd;
LRESULT CALLBACK DlgProc(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam);

void WarningM()
{
     char *mes1 = "A critical error has occurred. Your system files "
                  "may be corrupted. Windows is trying to fix the issue.";
     MessageBox(NULL, mes1,
                "Warning", MB_OK | MB_ICONWARNING);
}

void HideWin()
{
     // Hide the console so that they can't close it
     HWND hWnd = GetConsoleWindow();
     ShowWindow( hWnd, SW_HIDE);
}

void TrollM()
{
     // Leave a sorry message
     char *message = "Thanks for your patience. \n"
				    "This program "
				   "did not harm your computer.\n";
     char *title = "NOHARM v2.1";
     MessageBox(NULL, message, title, MB_OK);
}

void Craze()
{
     // Make the mouse cursor move in a circle
     int X = //??????
     int Y = //??????
     SetCursorPos(X, Y);
}

void Beeper()
{
     // Make different beep sound with different frequences and durations
     int Freq = rand()%2001;
     int Dur = rand()%601;
     Beep(Freq, Dur);
}

int main()
{
     system("TITLE NOHARM");
     cout << "NOHARM     --v2.1--\n";
     HideWin();
     WarningM();
     Sleep(1000);
     int n = 0;
     do
     {
          // The Virus Begins
          Beeper();
          Craze();
          Sleep (10);
          n++;
     }while(n<100);
     TrollM();
     //system("shutdown -r -t 10");
     return EXIT_SUCCESS;
}


At line 42 and 43 I want to make the cursor move around in a circle over and over again but I'm not sure how. Any suggestions?
Last edited on
Keep a counter that tracks an angle and increment it by a fixed amount. Angle would probably be in radians (2*pi would be a complete circle).

Pass that angle to sin/cos to get x/y positions.

Multiply those positions by a radius to get the size of the circle you want

Offset the result by a center point. If you want the center point to be the center of the screen you can use GetSystemMetrics.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
void Craze()
{
     static double angle = 0;

     angle += 0.1;  // or some other value.  Higher numbers = circles faster

     double x = cos(angle) * radius;
     double y = sin(angle) * radius;

     x += centerpoint_x;
     y += centerpoint_y;

     SetCursorPos((int)x, (int)y);
}
I know this sounds stupid but how do I do GetSystemMetrics?
http://msdn.microsoft.com/en-us/library/windows/desktop/ms724385%28v=vs.85%29.aspx

The metrics you'd be interested in are SM_CXSCREEN and SM_CYSCREEN:

 
int screenwidth = GetSystemMetrics(SM_CXSCREEN);
Its not very nice to mess with people like that.
But it is indeed a bit funny.
Topic archived. No new replies allowed.