-
Simple questions
I'm trying to set a timer so that it only checks mouse-clicks after a specified time since the last mouse click. Here's the relevant code:
long lTriggerTimer;
long lTimerCounter;
I set them each to zero at the start of the program:
lTriggerTimer=0;
lTimerCounter=0;
Then in my message handler in the case of left mouse button down I test to see if lTriggerTimer == 0 and if so do my business and reset the variable:
if (lTriggerTimer==0)
{
Do relevant stuff
lTriggerTimer=1;
}
And in my main program loop I incriment the timer and reset it when necessary:
if (lTrigger==1)
{
lTimerCounter=lTimerCounter+1;
if(lTimerCounter==30)
{
lTriggerTimer=0;
lTimerCounter=0;
}
}
Everything compiles fine, but there is no noticable delay when I click the left mouse button. I've changed the check value in the program loop to 300, 3000 and 30000 with the same result.
Any ideas what I'm doing wrong?
Also (and I apologize if this is a stupid question, but I'm using MS VC++ Learning Edition that I got with a book that doesn't explain everything properly (IMO)), what is the name of and function of the -> operator? As in, rc->left=whatever. Does it just reference a property of an object? If so, why wouldn't you just use: rc.left=whatever?
Sorry for the "newbie" questions, guys. But how do I convert from one variable type to another? In VB we use CInt, CStr, etc., but I'm not sure of the function name/syntax to do this in VC++.
Thanks again.
Jason
-
If I understand you right and you're using that loop to achieve a certain delay for that clickie thing it's a bad choice. The techinique was a decent when there only were computers like 4Mhz... You might get it work, somehow, with some specific machines... but a decent solution could be something like
Code:
const int CLICK_SPEED = 30, BASE_SPEED = 10;
int click_counter = 0;
bool inc = 0;
while(x)
{
if(mouse_click && (inc == 0))
inc = 1;
if(inc != 0)
{
if(mouse_click)
do_relevant_stuff();
click_counter++;
if(click_counter == CLICK_SPEED)
{
click_counter = 0;
inc = 0;
}
}
delay(BASE_SPEED); // If you want this smaller put click_speed bigger
}
Now it's a double click if time between clicks is CLICK_SPEED*BASE_SPEED = 300ms.
-
>>> what is the name
I call it the "arrow". Seems as good as anything.
>>> If so, why wouldn't you just use: rc.left=whatever?
You use that if you have the object. If you have a pointer to the object use rc->left.
A way of solving your timer problem is to use a real timer. When a mouse click comes in, set a flag saying "Ignore clicks", and set a timer for the desired delay. When the timer message comes in, reverse, "Ignore clicks". Each time a mouse click comes in, check to see if "Ignore clicks" is set, if so, discard the message, if not process it.