Simple way to make this work

Posts 1–7 of 7 · Page 1 of 1
Simple way to make this work
I would like to know how to make things work in background.. Like , for example , always shows the mouse position in top left while running my other codes.. thanks !
Code:
int _tmain(int argc, _TCHAR* argv[])
{
	
	while (true)
	{
		POINT t1;
		GetCursorPos(&t1);
		std::cout << t1.y << "." << t1.x;
		system("cls");
	
	
	}
	std::cout << "Hello world";
	
	return 0;
}
Only show the mousePos .. not my Hello world
It sounds like you want to create a background thread, but for a beginner, it's too many concepts to cover.
If you switch to C#, you get a GUI and event-driven code...and you'll probably have more fun learning instead of trying to tackle too many things at once -- if you get frustrated with C++, maybe give it a try. Just throwing that out there, anyway..

You could do something like...

Code:
void ClearConsoleAndDrawMenus()
{
system("cls");
//display time, any any other 'header text'
}
and use something like
Code:
void main(...)
{
  while (true)
   {
    ClearConsoleAndDrawMenus(); // clears the console and then re-adds 'header' text
    //do other stuff
   }
 
   //any code after the while's body{} won't run until after the while() loop has been exited. Loop basics.
}
it will achieve what you described, but not exactly what you asked for -- which is more complicated than you realize.
Isnt there a way to do exactly what I want trough class or something like that ..? Even if its complicated I would like to know how so i can try to understand
I tried , still showing the position of the my mouse only .. I just want to run a program normaly but the cursor position will always be shown on top

Code:
void showCursorPos()
{

	while (true)
	{
		POINT t1;
		GetCursorPos(&t1);
		std::cout << t1.y << "." << t1.x;
		system("cls");


	}

}

void HelloWorld()
{
	std::cout << "Hello world";
}

int main()
{
	std::thread first(showCursorPos);
	std::thread second (HelloWorld);
	first.join();
	second.join();

	return 0;
}
Quote Originally Posted by mic44 View Post
I tried , still showing the position of the my mouse only .. I just want to run a program normaly but the cursor position will always be shown on top

Code:
void showCursorPos()
{

	while (true)
	{
		POINT t1;
		GetCursorPos(&t1);
		std::cout << t1.y << "." << t1.x;
		system("cls");


	}

}

void HelloWorld()
{
	std::cout << "Hello world";
}

int main()
{
	std::thread first(showCursorPos);
	std::thread second (HelloWorld);
	first.join();
	second.join();

	return 0;
}
It's only showing the mouse position in the console because you are only printing "Hello world" one time,
and clearing the console after every print.

Code:
int main()
{
	std::thread first(showCursorPos);
	std::thread second(HelloWorld);
	first.join();
	second.join();

	first.detach(); // Add this to make the independent
	second.detach();

	return 0;
}
Why aren't you initializing the point structure?
Code:
POINT t = { 0,0 };
Posts 1–7 of 7 · Page 1 of 1

Post a Reply

Similar Threads

Tags for this Thread

None

Talk with us