Results 1 to 8 of 8

Thread: C++ question

  1. #1
    Super Moderator xBrady's Avatar
    Join Date
    Apr 2004
    Location
    USA
    Posts
    3,687

    C++ question

    I am somewhat new with creating GUIs (specifically working with forms in .NET studio). I have pretty much finished the interface for the program I am making but for some reason I can't figure out how to check the mouse up/down events right. What I am trying to do is have a number increment as long as a specific button is pressed down. I have it so it will increment if the button is clicked but I want to be able to hold the button down and have it continue to increment.
    Thanks
    I have been working on this one problem for an hour now trying lots of crap I found while googling...
    AMD XP 2600+/512MB RAM/120GB hard drive
    Opus 150W/DVD/GPS/7" Lilliput TS/802.11g/Bluetooth
    Installed.


    -GPSSecure- - GPS Tracking
    -AltTabber2.2.2- - Handy touchscreen utility.

  2. #2
    Maximum Bitrate Bitoholic's Avatar
    Join Date
    Apr 2004
    Location
    Port Saint Lucie, FL
    Posts
    682
    Quote Originally Posted by brady
    I am somewhat new with creating GUIs (specifically working with forms in .NET studio). I have pretty much finished the interface for the program I am making but for some reason I can't figure out how to check the mouse up/down events right. What I am trying to do is have a number increment as long as a specific button is pressed down. I have it so it will increment if the button is clicked but I want to be able to hold the button down and have it continue to increment.
    Thanks
    I have been working on this one problem for an hour now trying lots of crap I found while googling...
    Brady,

    You have to capture the MouseDown and MouseUp events. You are probably doing the Click event. You will want to take a time stamp and set a hold flag in MouseDown and start a timer. In that timer compare the timestamp to the current time and once it reaches your threshhold (i.e. 3 Seconds), you can turn the hold flag off. Also when the MouseUp event occurs you can reset the flags and do ther logic you want there...

    Hope this helps

    Take care
    Ben S. Stahlhood II
    Hybrid Mobile
    MMC/Transcend Developer
    --------------------------------------
    http://www.hybrid-mobile.com/
    http://www.cocoamachine.com/
    http://weblogs.asp.net/bstahlhood/

  3. #3
    Super Moderator xBrady's Avatar
    Join Date
    Apr 2004
    Location
    USA
    Posts
    3,687
    Alright, I think I understand most of what to do but the problem I am having is checking for the MouseUp event while in the MouseDown event... Maybe.
    For example what I had in the MouseDown event:
    Code:
    private: System::Void button3_MouseDown(System::Object *  sender, System::Windows::Forms::MouseEventArgs *  e)
    {
    	System::IntPtr
                 ptr(System::Runtime::InteropServices::Marshal::StringToHGlobalAnsi(label5->get_Text()));
                 std::string ret(static_cast<const char *>(static_cast<void *>(ptr)));
                 System::Runtime::InteropServices::Marshal::FreeCoTaskMem(ptr);
                 int i = atoi(ret.c_str ());
    	if(e->Button == MouseButtons::Left)
    	{
    		if (i < 180)
    		{
    			i++;
    			char buffer [33];
    			label5->Text = itoa (i, buffer,10);
    			label5->Refresh();
    		}
    	}
    }
    What I want to happen is rather than have the if statement I would prefer to have a while statement that will execute the code until the MouseUp event occurs. That is the part I don't understand, checking to see if the MouseUp event has occurred while in the MouseDown even.
    Either that or I am going about this the completely wrong way.
    Thanks.
    AMD XP 2600+/512MB RAM/120GB hard drive
    Opus 150W/DVD/GPS/7" Lilliput TS/802.11g/Bluetooth
    Installed.


    -GPSSecure- - GPS Tracking
    -AltTabber2.2.2- - Handy touchscreen utility.

  4. #4
    Maximum Bitrate Bitoholic's Avatar
    Join Date
    Apr 2004
    Location
    Port Saint Lucie, FL
    Posts
    682
    Here is my suggestion:

    Add a "Timer" component to your form. Set the time to whatever you like. If you want the increment to happen every 1 sec, then 1000ms.

    Create a member: bool mouseDown;

    In the mousedown event set the mouseDown = true and turn your timer component on...

    In the Timer tick event check the mouseDown variable and if it is true increment your value;

    In the MouseUp event then set the mouseDown = false and you can even disable the timer object.

    If you still do not understand, let me know.
    Ben S. Stahlhood II
    Hybrid Mobile
    MMC/Transcend Developer
    --------------------------------------
    http://www.hybrid-mobile.com/
    http://www.cocoamachine.com/
    http://weblogs.asp.net/bstahlhood/

  5. #5
    Super Moderator xBrady's Avatar
    Join Date
    Apr 2004
    Location
    USA
    Posts
    3,687
    Thanks, let me try that.
    AMD XP 2600+/512MB RAM/120GB hard drive
    Opus 150W/DVD/GPS/7" Lilliput TS/802.11g/Bluetooth
    Installed.


    -GPSSecure- - GPS Tracking
    -AltTabber2.2.2- - Handy touchscreen utility.

  6. #6
    Maximum Bitrate Bitoholic's Avatar
    Join Date
    Apr 2004
    Location
    Port Saint Lucie, FL
    Posts
    682
    try this:

    Code:
    	private: bool mouseDown;
    
    	private: 
    		
    		System::Void timer_Tick(System::Object^  sender, System::EventArgs^  e)
    		{
    			if (mouseDown) {
    				// increment value here
    			} // if
    		}
    
    		System::Void button1_MouseDown(System::Object^  sender, System::Windows::Forms::MouseEventArgs^  e)
    		{
    			this->mouseDown = true;
    			this->timer->Enabled = true;
    		}
    
    		System::Void button1_MouseUp(System::Object^  sender, System::Windows::Forms::MouseEventArgs^  e)
    		{
    			this->mouseDown = false;
    			this->timer->Enabled = false;
    		}
    Ben S. Stahlhood II
    Hybrid Mobile
    MMC/Transcend Developer
    --------------------------------------
    http://www.hybrid-mobile.com/
    http://www.cocoamachine.com/
    http://weblogs.asp.net/bstahlhood/

  7. #7
    Super Moderator xBrady's Avatar
    Join Date
    Apr 2004
    Location
    USA
    Posts
    3,687
    Quote Originally Posted by HybridEngineer
    try this:
    Actually I got it. Thanks a tooooooooooooonnnnnnnnnnnnnnnnn. You are one rockin monkey.
    AMD XP 2600+/512MB RAM/120GB hard drive
    Opus 150W/DVD/GPS/7" Lilliput TS/802.11g/Bluetooth
    Installed.


    -GPSSecure- - GPS Tracking
    -AltTabber2.2.2- - Handy touchscreen utility.

  8. #8
    Maximum Bitrate Bitoholic's Avatar
    Join Date
    Apr 2004
    Location
    Port Saint Lucie, FL
    Posts
    682
    Quote Originally Posted by brady
    Actually I got it. Thanks a tooooooooooooonnnnnnnnnnnnnnnnn. You are one rockin monkey.
    No problem man... anytime
    Ben S. Stahlhood II
    Hybrid Mobile
    MMC/Transcend Developer
    --------------------------------------
    http://www.hybrid-mobile.com/
    http://www.cocoamachine.com/
    http://weblogs.asp.net/bstahlhood/

Similar Threads

  1. little question ive pondered..
    By John Crowe in forum Newbie
    Replies: 41
    Last Post: 04-06-2005, 04:09 AM
  2. Destinator Software Question
    By jmeche3 in forum GPS
    Replies: 2
    Last Post: 10-27-2004, 10:28 PM
  3. 2 part question (keyboard hacks)
    By chuckctv in forum Input Devices
    Replies: 17
    Last Post: 09-07-2004, 08:24 PM
  4. DVD drive question
    By Pokey in forum Newbie
    Replies: 3
    Last Post: 05-11-2004, 04:26 PM
  5. lcd power question
    By jrbless in forum LCD/Display
    Replies: 1
    Last Post: 04-07-2002, 12:27 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •