Announcement

Collapse
No announcement yet.

Hold the mouse button down

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

  • roger hermans
    Guest replied
    Thank you both for the examples.
    Keep up the good work.

    Roger.



    ------------------

    Leave a comment:


  • Troy King
    replied
    Semen, I like your way better than my way . I always seem to miss the obvious.

    ------------------
    Troy King
    [email protected]

    Leave a comment:


  • Semen Matusovski
    replied
    It possible to use a timer.
    For example, when button is pressed, you increment x and - if button isn't released during one second - begin to increment each 1/4 sec.

    Code:
       #Compile Exe
       #Register None
       #Dim All
       #Include "win32api.inc"
       %ID_B = 2
       %ID_L = 3
    
       CallBack Function maincallback
          %Delay0 = 100: %Delay1 = 1000: %Delay2 = 250
          Static x As Long, t As Long
          Dim tt As Long
          Select Case CbMsg
             Case %WM_INITDIALOG: tt = %Delay0
             Case %WM_DESTROY: KillTimer CbHndl, 1
             Case %WM_TIMER
                If (SendMessage(GetDlgItem(CbHndl, %ID_B), %BM_GETSTATE, 0, 0) And %BST_PUSHED) Then
                   Incr x: Control Set Text CbHndl, %ID_L, "X = " & Str$(x): _
                      If t = %Delay0 Then tt = %Delay1 Else tt = %Delay2
                Else
                   tt = %Delay0
                End If
          End Select
          If tt > 0 And tt <> t Then SetTimer CbHndl, 1, tt, ByVal 0: t = tt
       End Function
    
       Function PbMain As Long
          Local hdlg As Long
          Dialog New 0, "Hold down the left mouse button", , , 350, 200, %WS_MAXIMIZE Or %WS_MAXIMIZEBOX Or %WS_MINIMIZEBOX Or %WS_SYSMENU Or %WS_CAPTION To hdlg
          Control Add Button, hdlg, %ID_B, "&Button", 180, 50, 100, 20, %BS_DEFAULT' Or %BS_OWNERDRAW
          Control Add Label, hdlg, %ID_L, "X = ", 180, 80, 125, 20
          Dialog Show Modal hdlg, Call maincallback
       End Function
    ------------------

    Leave a comment:


  • Troy King
    replied
    It's not perfect, but I only spent 5 minutes on it. It resumes a thread to count a global variable on button down and suspends it on button up. There's bound to be LOTS of code needed to make it user-proof, but it does compile and run and gives the basic idea:
    Code:
    #COMPILE EXE
    #INCLUDE "win32api.inc"
     
    DECLARE CALLBACK FUNCTION hDlg_Callback() AS LONG
    GLOBAL hThread AS LONG
    GLOBAL MyNumber AS LONG
    GLOBAL hDlg AS LONG
    GLOBAL SomeLong AS LONG
     
    FUNCTION PBMAIN() AS LONG
        DIALOG NEW %HWND_DESKTOP, "Increment Test", , , 160, 110, %WS_OVERLAPPEDWIN TO hDlg
        CONTROL ADD LABEL, hDlg&, 101, "hold button down", 10, 10, 60, 15, %WS_VISIBLE
        THREAD CREATE IncrementVariable(0) SUSPEND TO hThread
        DIALOG SHOW MODAL hDlg CALL hDlg_Callback()
    END FUNCTION
     
    FUNCTION IncrementVariable(BYVAL SomeArg AS LONG) AS LONG
        DO
            MyNumber = MyNumber + 1
            SLEEP 250 'pause 250 ms
            CONTROL SET TEXT hDlg, 101, STR$(MyNumber)
        LOOP
    END FUNCTION
     
    CALLBACK FUNCTION hDlg_Callback() AS LONG
        SELECT CASE CBMSG
            CASE %WM_LBUTTONDOWN
                THREAD RESUME hThread TO SomeLong
            CASE %WM_LBUTTONUP
                THREAD SUSPEND hThread TO SomeLong
            CASE %WM_DESTROY
                THREAD CLOSE hThread TO SomeLong
        END SELECT
    END FUNCTION
    [This message has been edited by Troy King (edited April 04, 2000).]

    Leave a comment:


  • roger hermans
    Guest replied
    The B on the keybord runs perfect.
    But how to incr the x continue with the left mousebutton down ?.


    #COMPILE EXE
    #REGISTER NONE
    #DIM ALL
    #INCLUDE "win32api.inc"

    %ID_B = 2
    %ID_L = 3
    '===============================================================
    CALLBACK FUNCTION maincallback

    STATIC x AS LONG

    IF CBCTL = %ID_B THEN
    INCR x
    CONTROL SET TEXT CBHNDL, %ID_L, "X = " & STR$(x)
    END IF

    END FUNCTION
    '===============================================================
    FUNCTION PBMAIN AS LONG

    LOCAL hdlg AS LONG

    DIALOG NEW 0, "Hold down the left mouse button", , , 350, 200, %WS_MAXIMIZE OR %WS_MAXIMIZEBOX OR %WS_MINIMIZEBOX OR %WS_SYSMENU OR %WS_CAPTION TO hdlg

    'the B on the keybord runs perfect.
    'but how to incr the x continue with the left mousebutton down ?.

    CONTROL ADD BUTTON, hdlg, %ID_B, "&Button", 180, 50, 100, 20, %BS_DEFAULT
    CONTROL ADD LABEL, hdlg, %ID_L, "X = ", 180, 80, 125, 20

    DIALOG SHOW MODAL hdlg, CALL maincallback

    END FUNCTION
    '===============================================================




    ------------------

    Leave a comment:


  • Scott Turchin
    replied
    Like this I would think:


    Code:
    Callback Function Whatever() as long
    Static i as long
    
    etc etc
    
    Case %WM_MOUSEDOWN 'or whatever the command is
         Incr i
    It will not lose it's value..

    Scott



    ------------------
    Scott
    mailto:[email protected][email protected]</A>

    Leave a comment:


  • roger hermans
    Guest started a topic Hold the mouse button down

    Hold the mouse button down

    After clicking the left mouse button on a button, and hold the button down,
    how can i incr continue a variabele, in a callback function?.

    Are there somewhere related codes?.

    Roger.

    [This message has been edited by roger hermans (edited April 03, 2000).]
Working...
X
😀
🥰
🤢
😎
😡
👍
👎