Simple questions

This is a discussion on Simple questions within the C++ Programming forums, part of the General Programming Boards category; I'm trying to set a timer so that it only checks mouse-clicks after a specified time since the last mouse ...

  1. #1
    Used Registerer jdinger's Avatar
    Join Date
    Feb 2002
    Posts
    1,065

    Question 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
    Last edited by jdinger; 02-25-2002 at 09:39 PM.

  2. #2
    Registered User
    Join Date
    Aug 2001
    Posts
    129
    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.
    kooma - t.h@iki.fi

  3. #3
    It's full of stars adrianxw's Avatar
    Join Date
    Aug 2001
    Posts
    4,831
    >>> 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.
    Wave upon wave of demented avengers march cheerfully out of obscurity unto the dream.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. questions....so many questions about random numbers....
    By face_master in forum C++ Programming
    Replies: 2
    Last Post: 07-30-2009, 09:47 AM
  2. A couple questions
    By Flakster in forum C++ Programming
    Replies: 7
    Last Post: 08-09-2005, 02:22 PM
  3. Few simple questions...
    By Shane in forum C++ Programming
    Replies: 9
    Last Post: 08-06-2005, 03:40 AM
  4. A few simple batch questions
    By sean in forum A Brief History of Cprogramming.com
    Replies: 4
    Last Post: 07-02-2003, 02:35 PM
  5. questions questions questions.....
    By mfc2themax in forum A Brief History of Cprogramming.com
    Replies: 1
    Last Post: 08-14-2001, 08:22 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21