Overview
Examples
Screenshots
Comparisons
Applications
Download
Documentation
Tutorials
Bazaar
Status & Roadmap
FAQ
Authors & License
Forums
Funding Ultimate++
Search on this site
Search in forums












SourceForge.net Logo
Home » Community » Newbie corner » How to make a point follow the mouse through windows 7
Re: How to make a point follow the mouse through windows 7 [message #36490 is a reply to message #36482] Sat, 02 June 2012 02:29 Go to previous messageGo to previous message
Sender Ghost is currently offline  Sender Ghost
Messages: 301
Registered: November 2008
Senior Member
Hello, Frederic.
mohrphium wrote on Thu, 31 May 2012 13:36

I want to write a small program, that creates a point which follows my mouse all the time. I need this, because I want to stream my desktop to another pc, but it won't show my mouse movements.

I think, there are other methods, but I accomplished this with following source code:
#include <CtrlLib/CtrlLib.h>

using namespace Upp;

class App : public TopWindow {
private:
	Size sz;
	Image img;
public:
	typedef App CLASSNAME;
	App();

	TrayIcon tray;

	virtual void Paint(Draw& w);
	void ChangePos();
	void DoChangePos();
	void TrayMenu(Bar& bar);
};

void App::Paint(Draw& w)
{
	w.DrawImage(sz, img);
}

void App::ChangePos()
{
	static Point prev(0, 0);
	Point p = GetMousePos();

	if (prev != p) {
		SetRectX(p.x - sz.cx, sz.cx);
		SetRectY(p.y - sz.cy, sz.cy);
		prev = p;
	}
}

void App::DoChangePos()
{
	static bool running = false;

	if (!running)
		SetTimeCallback(-10, THISBACK(ChangePos), 1);
	else
		KillTimeCallback(1);

	Show(running = !running);
}

void App::TrayMenu(Bar& bar)
{
	bar.Add(IsShown() ? t_("Hide") : t_("Show"), THISBACK(DoChangePos)).Key(K_CTRL_W);
	bar.Separator();
	bar.Add(t_("Exit"), THISBACK1(Break, (int)IDEXIT)).Key(K_CTRL_Q);
}

App::App()
{
	const String title(t_("Moving image for mouse pointer"));
	Title(title);
	FrameLess().ToolWindow().TopMost();
	NoInitFocus().NoWantFocus();
	sz = Size(5, 5);
	SetMinSize(sz); SetRect(sz);
	// Drawing image for pointer
	ImageDraw iw(sz);
	iw.DrawRect(sz, Black());
	iw.DrawEllipse(sz + 1, White());
	img = iw;

	Image icon = Image::Arrow();
	Icon(icon);
	tray.Icon(icon);
	tray.Tip(title);
	tray.WhenBar = THISBACK(TrayMenu);
	tray.WhenLeftDouble = THISBACK(DoChangePos);

	DoChangePos();
}

GUI_APP_MAIN
{
	App app;
	app.Run();
}

Basically, it creates the frameless tool window with some image, which moves to current mouse position periodically. Also possible to show or hide such window from tray icon.
 
Read Message
Read Message
Read Message
Previous Topic: GLUT
Next Topic: Serious Hex Editor
Goto Forum:
  


Current Time: Sun Aug 24 15:08:20 CEST 2025

Total time taken to generate the page: 0.04768 seconds