Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Button down increment

Button down increment

Scheduled Pinned Locked Moved C / C++ / MFC
tutorialquestionlounge
7 Posts 5 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • O Offline
    O Offline
    Oliver123
    wrote on last edited by
    #1

    I want to create a button that will force an acton to continue as long as the button is "down." For example, I want to increment a displayed field by 1 as long as the button is down. I can increment each time the button is clicked, but can't hold it down and get multiple increments. What's the general approach to this? Thanks.

    J M M J 4 Replies Last reply
    0
    • O Oliver123

      I want to create a button that will force an acton to continue as long as the button is "down." For example, I want to increment a displayed field by 1 as long as the button is down. I can increment each time the button is clicked, but can't hold it down and get multiple increments. What's the general approach to this? Thanks.

      J Offline
      J Offline
      jk chan
      wrote on last edited by
      #2

      You can start some timers on on mouse down event ,and in the timers you can do what ever you want.. and kill the timer on mouseup. it may work

      If u can Dream... U can do it

      1 Reply Last reply
      0
      • O Oliver123

        I want to create a button that will force an acton to continue as long as the button is "down." For example, I want to increment a displayed field by 1 as long as the button is down. I can increment each time the button is clicked, but can't hold it down and get multiple increments. What's the general approach to this? Thanks.

        M Offline
        M Offline
        Mark Salsbery
        wrote on last edited by
        #3

        One way would be to respond to the WM_LBUTTONDOWN message for the button control and go into a modal loop until the button is released:

        On WM_LBUTTONDOWN...

        ::SetCapture(hwnd);

        MSG Msg;
        memset(&Msg,0,sizeof(MSG));
        while (Msg.message != WM_LBUTTONUP &&
        (Msg.message != WM_MOUSEMOVE ||
        (Msg.wParam & MK_LBUTTON)))
        {
        if (::PeekMessage(&Msg,0,0,0,PM_REMOVE))
        {
        ::TranslateMessage(&Msg);
        ::DispatchMessage(&Msg);
        }

        // Increment displayed field
        // Call ::InvalidateRect(hWnd, NULL, bErase) on displayed field control
        // Call ::UpdateWindow(hWnd) on displayed field control
        }

        ::ReleaseCapture();

        A better method would be to do it like the up-down control (spin button) does:

        // (pseudocode)

        On WM_LBUTTONDOWN
        Capture the mouse (::SetCapture())
        Create a timer for the desired interval of increments (::SetTimer())
        On WM_TIMER
        Increment displayed field
        Call ::InvalidateRect(hWnd, NULL, bErase) on displayed field control
        Call ::UpdateWindow(hWnd) on displayed field control
        On WM_LBUTTONUP
        Kill the timer (::KillTimer())
        Release the mouse (::ReleaseCapture())

        -- modified at 21:40 Monday 25th June, 2007

        "Go that way, really fast. If something gets in your way, turn."

        1 Reply Last reply
        0
        • O Oliver123

          I want to create a button that will force an acton to continue as long as the button is "down." For example, I want to increment a displayed field by 1 as long as the button is down. I can increment each time the button is clicked, but can't hold it down and get multiple increments. What's the general approach to this? Thanks.

          M Offline
          M Offline
          Michael Dunn
          wrote on last edited by
          #4

          Check out CBitmapButton in WTL, that class has this feature (it's called "autofire"), so you could take the code from there.

          --Mike-- Visual C++ MVP :cool: LINKS~! Ericahist | PimpFish | CP SearchBar v3.0 | C++ Forum FAQ Dunder-Mifflin, this is Pam.

          M 2 Replies Last reply
          0
          • M Michael Dunn

            Check out CBitmapButton in WTL, that class has this feature (it's called "autofire"), so you could take the code from there.

            --Mike-- Visual C++ MVP :cool: LINKS~! Ericahist | PimpFish | CP SearchBar v3.0 | C++ Forum FAQ Dunder-Mifflin, this is Pam.

            M Offline
            M Offline
            Mark Salsbery
            wrote on last edited by
            #5

            Cool! I have a dumb question....is WTL for XP+ or are lower OSs supported? Thanks! Mark

            "Go that way, really fast. If something gets in your way, turn."

            1 Reply Last reply
            0
            • M Michael Dunn

              Check out CBitmapButton in WTL, that class has this feature (it's called "autofire"), so you could take the code from there.

              --Mike-- Visual C++ MVP :cool: LINKS~! Ericahist | PimpFish | CP SearchBar v3.0 | C++ Forum FAQ Dunder-Mifflin, this is Pam.

              M Offline
              M Offline
              Mark Salsbery
              wrote on last edited by
              #6

              I can read :rolleyes: Supported Operating Systems: Windows 2000; Windows Server 2003; Windows Vista; Windows XP

              "Go that way, really fast. If something gets in your way, turn."

              1 Reply Last reply
              0
              • O Oliver123

                I want to create a button that will force an acton to continue as long as the button is "down." For example, I want to increment a displayed field by 1 as long as the button is down. I can increment each time the button is clicked, but can't hold it down and get multiple increments. What's the general approach to this? Thanks.

                J Offline
                J Offline
                John R Shaw
                wrote on last edited by
                #7

                It has been a while, but essentially you just need to start a timer that calls a timer message handler of you choice. The timer handler keeps doing the increment until you release the button. When you release the button, then you need to release the timer. This is very similar as to how one selects lines in a text editor (or web page), that is a timer is used to make the window scroll when you mover the mouse cursor near the edge of the window when selecting text.

                INTP "Program testing can be used to show the presence of bugs, but never to show their absence."Edsger Dijkstra

                1 Reply Last reply
                0
                Reply
                • Reply as topic
                Log in to reply
                • Oldest to Newest
                • Newest to Oldest
                • Most Votes


                • Login

                • Don't have an account? Register

                • Login or register to search.
                • First post
                  Last post
                0
                • Categories
                • Recent
                • Tags
                • Popular
                • World
                • Users
                • Groups