Thursday, July 30, 2009

Visual C++ Experts helppppp!!!!?

I made a small program (for fun). One of my main objectives here is that when mouse pointer is not moving for 5 seconds, the mouse pointer will disappear and reappear again if mouse is moved by the user...





How to determine / check if mouse pointer is moving or not?


(please do not write the entire code for this... I only want the piece of code that is responsible for analyzing the movement of the mouse... and for the rest, I know how to handle it...)





I use ShowCursor to hide my mouse pointer...





--- MFC or not, as long as it is Visual C++ code, is accepted.





I promise to give credits if and only if I am satisfied with the answer....


Thanks and God Bless...

Visual C++ Experts helppppp!!!!?
Bravo for not wanting to see the code....you are one of the rare kids that request this that is for sure...anyway, i will grant your wish and have you recall this VC win32 api:





GetCursorPos(...);





So you have a number of choices but here is one of them to solve your problem:





You'd want to store the current position of the cursor which is done after 5 secs of it not moving ...obviously in your code you are using a timer and if the cursor position hasn't moved for 5 secs it turns off the cursor via ShowCursor....it is then that you store the position of the cursor....





Now for the cursor movement events that come in (recal that windows triggers events for when the mouse moves) you can then verify the x/y position vs what you stored...and if it changed then you can display the mouse cursor again and start your original 5sec timer (assuming it was disabled when it blanked it -- to be efficient).





Btw, you prolly already are doing this, but as a friendly reminder you can always create your own timer event that windows will keep track of and initiate the WM_TIMER message on your behalf every xx secs (in this case: 5 secs) for you...this would be the most eifficient way for a timer to be made in your code since it will be using less resources.


No comments:

Post a Comment