Announcement

Collapse
No announcement yet.

C++ question

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • 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
    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/

    Comment


    • #3
      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.

      Comment


      • #4
        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/

        Comment


        • #5
          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.

          Comment


          • #6
            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/

            Comment


            • #7
              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.

              Comment


              • #8
                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/

                Comment

                Working...
                X