Funny C++ Thing,

Hey, I'm new to c++ and this forum, but I was messing around with c++ yesterday and I managed to create this program that will really annoy someone. Any ideas how to improve this?

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
#include "stdafx.h"
#include "Windows.h"
#include <iostream>
#include <ctime>

using namespace std;

//Crazy class,
class Crazy
{

public:
	void crazy();

private:
	//X and Y position variables
	int x_mouse_pos;
	int y_mouse_pos;

};

int main()
{

	//Seeding random number generator,
	srand(static_cast <unsigned int> (time(0)));

	//Crazy object declaration,
	Crazy crazy_object;

	//Calling crazy function,
	crazy_object.crazy();

}

//Crazy function,
void Crazy::crazy()
{

	while (1 == 1)
	{	//Generating x position for mouse,
		x_mouse_pos = (rand() % 1024) + 1;

		//Generating y positon for mouse,
		y_mouse_pos = (rand() % 768) + 1;

		//Moving mouse position,
		SetCursorPos(x_mouse_pos, y_mouse_pos);
	}

}
P.S, the only way to stop the mouse moving is to use task manager.
If you want to improve it make it click as well so it causes havoc.
How would you do that?
I am too beginner to know code, but it might cause too much havoc if coded to be fast clicking.
Last edited on
@ OP: You send mouse clicks with the SendInput() function from the WinAPI: http://msdn.microsoft.com/en-us/library/windows/desktop/ms646310(v=vs.85).aspx

Don't do that though because you don't know what you might be clicking on.

P.S, the only way to stop the mouse moving is to use task manager.

Your application spawns a command prompt window and is only alive for as long as that window is open. When that window has focus the user only has to press "Ctrl+C" to kill the application. EDIT: A potential work around for this is so easy that I'm not going to hand it to you. Look up RAII and tell me how that might be used here.

As for making it more obnoxious? I remember an old VBScript that used to pop-up with a box asking "Are you dumber then toast?" with Yes and No buttons on it. It would then take your mouse pointer and constantly place it over the 'Yes' option. I always thought that was pretty funny.
Last edited on
Topic archived. No new replies allowed.