Announcement

Collapse
No announcement yet.

%STN_CLICKED or %STN_DBLCLK(label)

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

  • %STN_CLICKED or %STN_DBLCLK(label)

    Can you only check for one of these two messages?
    Code:
    IF CB.CTLMSG = %STN_DBLCLK  THEN
        MSGBOX FORMAT$(%STN_DBLCLK), %MB_TASKMODAL
    ELSEIF CB.CTLMSG = %STN_CLICKED THEN
        MSGBOX FORMAT$(%STN_CLICKED), %MB_TASKMODAL
    END IF
    This code always responds to the %STN_CLICKED.
    Is it at all possible to get it to respond to whichever the user does? Click or doubleclick.
    Rod
    I want not 'not', not Knot, not Knott, not Nott, not knot, not naught, not nought, but aught.

  • #2
    Wish I'd seen this thread first. It might have something to do with WHY PB used %BN_CLICKED vs %STN_CLICKED in help for CONTROL ADD Label.
    Dale

    Comment


    • #3
      Something like this perhaps?

      Code:
          Case %WM_COMMAND
            IF CbCtlMsg = %STN_DBLCLK  Then
                KillTimer CbHndl, 1
                Dialog Set Text CbHndl, "DBLCLK: " + FORMAT$(%STN_DBLCLK)
                Sleep 100 : Dialog Set Text CbHndl, ""
            ELSEIF CbCtlMsg = %STN_CLICKED Then
                SetTimer CbHndl, 1, GetDoubleClickTime, 0
            END IF
       
          Case %WM_TIMER
            KillTimer CbHndl, 1 
            Dialog Set Text CbHndl, "CLICKED: " + FORMAT$(%STN_CLICKED)
            Sleep 100 : Dialog Set Text CbHndl, ""
      Rgds, Dave

      Comment


      • #4
        I'll give that a workout tonight, thank you.
        Rod
        I want not 'not', not Knot, not Knott, not Nott, not knot, not naught, not nought, but aught.

        Comment


        • #5
          Dave, I pasted your code suggestion into some sample code. It works fine. However I'm not understanding the concept of Timer.

          There's a '<< remark with the relevant SDK lines from the help file and
          '<<<<<<<<<<<<<<<<<< Creates it here in ID_Label? Why?
          is what I'm not getting. Could you explain it for me? Also why KILL it? Thanks.

          (I posted the whole example in case newbies and any other dummies (like me) want to follow along.)
          '
          Code:
          'PBWIN 9.00 - WinApi 05/2008 - XP Pro SP3
          #Dim All 
          #Compile Exe  
          #Include "WIN32API.INC"
          '
          Global hdlg As Dword                
           
          %Id_Exit_Btn = 1000
          %Id_Sample_Textbox = 1001
          %Id_Show_Result_Btn = 1002
          %Id_Label = 1003
          ' 
          Macro Common_Locals 'Macro easier than retyping and maintains coding consistency
            Global Dlg_hght, Dlg_Wd As Long 'Global in case want to use in Controls
            Local Row, col, hght, wd, Longest,ctr, ln, ln1, i As Long
            Local  l, s As String
          End Macro  
          '
          CallBack Function Dialog_Processor              
            Common_Locals
            Select Case CbMsg     'This is TO determine the message TYPE 
               '
               Case %WM_TIMER
                KillTimer CbHndl, 1 '<< destroys the specified timer. (Win32 PR)
                Dialog Set Text CbHndl, "CLICKED: " + Format$(%STN_CLICKED)
                Sleep 1000 : Dialog Set Text CbHndl, ""
               '
               Case %WM_COMMAND  'This processes command messages
                 Select Case CbCtl
                   Case %Id_Label
                      If CbCtlMsg = %STN_DBLCLK  Then
                          KillTimer CbHndl, 1  '<< destroys the specified timer. (Win32 PR)
                          Dialog Set Text CbHndl, "DBLCLK: " + Format$(%STN_DBLCLK)
                          Sleep 1000 : Dialog Set Text CbHndl, ""
                      ElseIf CbCtlMsg = %STN_CLICKED Then
                          SetTimer _    '<< creates a timer with the specified time-out value. 
                                  CbHndl, _ '<< Creates it here in ID_Label? Why?
                                   1,      _
                                   GetDoubleClickTime, 0 '<<retrieves the current double-click time for the mouse. 
                      End If
           
           
                   Case %Id_Show_Result_Btn 
                      Control Get Text CbHndl, %Id_Sample_Textbox To l$
                        ? l$, , FuncName$
                   Case %Id_Exit_Btn
                     Select Case CbCtlMsg        
                        Case 0
                          Dialog End CbHndl
                     End Select
                 End Select
            End Select
          End Function
          '
          Function PBMain
            Common_Locals
            Dlg_hght = 400
            Dlg_Wd = 400
            Dialog New Pixels, hdlg, "Demo", , , Dlg_Wd, Dlg_Hght, %WS_SYSMENU To hdlg 'centered
           
            Row = 10
            col = 10
            Wd = 40
            Hght = 12
            Control Add Label, hdlg, %Id_Label, " Name & Address ", Col, Row, Wd, Hght,  %SS_Notify
           
            s$ = "Brown, Kevin" & $CrLf & _
                 "123 PBWin Avenue" & $CrLf & _
                 "PowerBasic, FL 12345"
           
            Col = Col + Wd + 10 'just past label 
            Hght = 15 * 10 'Plenty room for 10 lines of text
            Wd = Dlg_Wd - 40 - 30 'minus the label and leave a little
            Control Add TextBox, hdlg, %Id_Sample_Textbox, s$, Col, Row, Wd, Hght, %ES_WantReturn Or %ES_MultiLine
           
             hght = 25   
             Wd = Dlg_Wd - 20
             Col = 10 'center
           
             Row = Dlg_hght - (Hght * 2) - 4 'Just off bottom
               Control Add Button, hdlg, %Id_Show_Result_Btn, "Show Textbox Results", col, row, Wd, Hght
           
             Row = Dlg_hght - Hght - 2 'Just off bottom
               Control Add Button, hdlg, %Id_Exit_Btn, "Abandon Ship", col, row, Wd, Hght
           
               Dialog Show Modal hDlg   Call Dialog_Processor
          End Function
          '
          =============================================
          "The covers of this book are too far apart."
          Ambrose Bierce (1842-1914)
          =============================================
          Last edited by Gösta H. Lovgren-2; 30 Oct 2008, 09:52 PM.
          It's a pretty day. I hope you enjoy it.

          Gösta

          JWAM: (Quit Smoking): http://www.SwedesDock.com/smoking
          LDN - A Miracle Drug: http://www.SwedesDock.com/LDN/

          Comment


          • #6
            Hi Gösta,

            The problem is that the label always responds to the first click (and a STN_CLICKED notification is generated) even when that click is actually part of a double-click by the user. A double-click actually causes two notifications so how do we ignore the first when it's appropriate to do so?

            What I was suggesting is starting a timer to delay the response to the first click in case another is 'just coming'.

            So.
            1. Start the timer on the first click.

            2. If not killed by a second click (ie STN_DBLCLK notification) the timer fires after a suitable wait and we can respond to the single-click event.
            (GetDoubleClickTime = the maximum number of milliseconds that may occur between the first and second click of a double-click - a system parameter that defaults to about 500ms. It can be changed by the operator adjusting the Mouse Properties in the control panel).

            3. If the timer does fire, kill it so we can start over (at t-zero as it were) the next time a click is announced.

            4. If a double-click event does occur, kill the timer (started by the first click, but not yet fired) and respond to the double-click event.

            - Something like that anyway
            Rgds, Dave

            Comment


            • #7
              Thank you Gosta for testing that and posting the code. It saved me some time, and it is delightful to see it work.

              Nice work Dave.

              Hope Dave's explanation answered all for you Gosta.
              Rod
              I want not 'not', not Knot, not Knott, not Nott, not knot, not naught, not nought, but aught.

              Comment


              • #8
                For double mouse clicks, Windows sends more than one message. It's been ages since I wrote the test code, but I believe that before Windows sends the DBLCLICK message, it will send the normal clicked messages. I presume that this is because, upon the first click notification from the mouse driver, Windows might not yet realize that it is a double click, and therefore sends the normal click message, and after realizing it is a double click message, it then sends a double click message. This is only a theory of mine, though.

                Comment


                • #9
                  It seems that the second click of the double is completely discarded, else the single click event would repeat or the double click event would happen in that case, IMO. It seems that the message is sent on a WM_LBUTTONDOWN
                  kind of thingy.

                  But I got to wondering, what if a person wanted to test for all four possible messages in the same select/case block? Without Dave's %WM_TIMER all I get is the %STN_CLICKED response, but my code may be suspect.

                  More thinking is in order on my part.
                  Rod
                  I want not 'not', not Knot, not Knott, not Nott, not knot, not naught, not nought, but aught.

                  Comment


                  • #10
                    Rod,

                    If you replace your original MsgBox's with 'Dialog Set Text's' you'll see that indeed both messages are generated on a double-click. The STN_CLICKED MsgBox interupts the double-click.

                    To get all the mouse messages you'll probably have to subclass the label?
                    Rgds, Dave

                    Comment


                    • #11
                      To see all four 'STN_xxx' messages..
                      Code:
                      #Compile Exe
                      #Dim All
                      #Include "WIN32API.INC"
                       
                      %BTN_Test      = 102
                      %LBL_LABEL1    = 101
                      '------------------/
                       
                      CallBack Function DlgProc()
                        Select Case As Long CbMsg
                          Case %WM_INITDIALOG
                          Case %WM_COMMAND
                            If CbCtl = %LBL_LABEL1 Then
                              If CbCtlMsg = %STN_ENABLE Then
                                  Dialog Set Text CbHndl, ""
                                  Dialog Set Text CbHndl, "LBL Enabled"
                              End If
                              If CbCtlMsg = %STN_DISABLE Then
                                  Dialog Set Text CbHndl, ""
                                  Dialog Set Text CbHndl, "LBL Disabled"
                              End If
                              If CbCtlMsg = %STN_DBLCLK  Then
                                  KillTimer CbHndl, 1
                                  Dialog Set Text CbHndl, "" : Sleep 100
                                  Dialog Set Text CbHndl, "DBLCLK: " + Format$(%STN_DBLCLK)
                              ElseIf CbCtlMsg = %STN_CLICKED Then
                                  SetTimer CbHndl, 1, GetDoubleClickTime, 0                     ' Comment out for test
                                  'Dialog Set Text CbHndl, "" : Sleep 100                       ' Remove comment for test
                                  'Dialog Set Text CbHndl, "CLICKED: " + Format$(%STN_DBLCLK)   ' Remove comment for test
                              End If
                            End If 
                            If CbCtl = %BTN_TEST Then
                             Local BtnDown As Long
                              If CbCtlMsg = %BN_CLICKED Then
                                Control Get Check CbHndl, %BTN_Test To BtnDown
                                If BtnDown  Then
                                    Control Disable CbHndl, %LBL_Label1
                                Else 
                                    Control Enable CbHndl, %LBL_Label1
                                End If 
                              End If
                            End If
                       
                          Case %WM_TIMER
                            KillTimer CbHndl, 1
                            Dialog Set Text CbHndl, "" : Sleep 100
                            Dialog Set Text CbHndl, "CLICKED: " + Format$(%STN_CLICKED)
                       
                          Case %WM_SYSCOMMAND
                            If (CbWParam And &HFFF0) = %SC_CLOSE Then
                              Dialog End CbHndl
                            End If
                       
                        End Select
                      End Function
                      '------------------/DlgProc
                       
                      Function PBMain()
                       Local hDlg  As Dword
                       
                        Dialog New 0, "Test", , , 200, 120, %WS_CAPTION Or %WS_SYSMENU, To hDlg
                        Control Add Label,  hDlg, %LBL_LABEL1, "Click Me !!", 50, 25, 120, 20, %SS_NOTIFY
                        Control Add Button,  hDlg, %BTN_Test, "En/Dis-able", 75, 60, 50, 15, %BS_PUSHLIKE Or %BS_AUTOCHECKBOX
                       
                        Dialog Show Modal hDlg, Call DlgProc
                       
                      End Function
                      '------------------/PbMain
                      Rgds, Dave

                      Comment


                      • #12
                        Your right Dave, so it's back to the drawing board. I shoulda oughta read a little more in the SDK.
                        Rod
                        I want not 'not', not Knot, not Knott, not Nott, not knot, not naught, not nought, but aught.

                        Comment


                        • #13
                          A double-click actually causes two notifications so how do we ignore the first when it's appropriate to do so
                          "They" say you should design so that a double-click does two things.. one on click, one on the second click, if that second click occurs.

                          So the answer is, you don't put yourself in a situation where it is appropriate to ignore the first click.

                          But I would think just ignoring the (single) click would do it. I know that works for me with listview controls... the first click simply selects the 'row of interest' which is the default behavior provided by windows, the second click - if it happens - does something.

                          Never tried it with label controls, though; although they can report clicks, they cannot receive the keyboard focus, so the "select on first click" thing does not apply.



                          MCM
                          Michael Mattias
                          Tal Systems (retired)
                          Port Washington WI USA
                          [email protected]
                          http://www.talsystems.com

                          Comment


                          • #14
                            with label controls, though; although they can report clicks, they cannot receive the keyboard focus
                            Not quite true - see this discussion. http://www.powerbasic.com/support/pb...ad.php?t=36894
                            Rgds, Dave

                            Comment


                            • #15
                              Micheal, that "it does one thing on first click, another on second" is the issue I was not aware of, with them being messages I just assumed that each could be handled separately.
                              It is easier now to think of it(the doubleclick) as a double message, because even if you are only going to use one of the messages, the other is there.
                              So I do things the opposite of my original plan, in the end, it'll look like I planned it this way.
                              Rod
                              I want not 'not', not Knot, not Knott, not Nott, not knot, not naught, not nought, but aught.

                              Comment


                              • #16
                                Dave, thanks for the explanation. If I understand correctly, effectively setting the timer "suspends" new msgs to the Callback FOR THAT ID (%Id_Label in this case) for the duration of GetDoubleClickTime (50 ms or whatever the OpSys has it set for). Other msgs already in the queue FOR THAT ID (%Id_Label in this case) will get processed. and since DoubleClick is the next msg after SingleClick, it gets processed.

                                IOW we tell the Callback to wait a beat to check for a DoubleClick JIC.

                                IOW (again) The %Wm_Timer becomes the Single_Click for our purposes here. {???}

                                Here's the revised code that led me to those conclusions.
                                Code:
                                     Case %WM_COMMAND  'This processes command messages
                                       Select Case CbCtl
                                         Case %Id_Label      
                                '>>> if msg = Double Click then kill the Timer set up on the first click         
                                            If CbCtlMsg = %Stn_Dblclk  Then
                                               KillTimer CbHndl, 1  '<< stop the timer se by the first click
                                                Dialog Set Text CbHndl, "Double Clicked in Name" 
                                                Sleep 1000 : Dialog Set Text CbHndl, "" 'show for a second then erase
                                            End If
                                '>>> Since we don't know yet at this point if single click or a double click, we sort of give
                                '>>> the Callback time to check for a double click.            
                                            If CbCtlMsg = %Stn_Clicked Then 
                                                SetTimer _    '<< creates a timer with the specified time-out value. 
                                                        CbHndl, _ 
                                                         1,      _
                                                         GetDoubleClickTime, 0 '<<retrieves an sets the current double-click time for the mouse. 
                                            End If
                                 
                                         '
                                         Case %Id_Show_Result_Btn 
                                            Control Get Text CbHndl, %Id_Sample_Textbox To l$
                                              ? l$, , FuncName$
                                         Case %Id_Exit_Btn
                                           Select Case CbCtlMsg        
                                              Case 0
                                                Dialog End CbHndl
                                           End Select
                                       End Select
                                     '                                                   
                                     Case %WM_TIMER
                                '>>> Since the Timer was set above we know it must have been a single click because
                                '>>> Timer is still active. Had there been a DoubleClick received msg before the %WM_Timer msg
                                '>>> was received, the Timer would have been killed in the DoubleClick response above.    
                                      KillTimer CbHndl, 1 '<< destroys the specified timer. (Win32 PR)
                                      Dialog Set Text CbHndl, "Single CLICKED: Timer Killed "
                                      Sleep 1000 : Dialog Set Text CbHndl, "" 'show for a second then erase
                                ======================================================
                                "I am become death,
                                shatterer of worlds."
                                Robert J. Oppenheimer (1904-1967)
                                (citing from the Bhagavad Gita,
                                after witnessing the world's first nuclear explosion)
                                ======================================================
                                Last edited by Gösta H. Lovgren-2; 31 Oct 2008, 09:29 PM.
                                It's a pretty day. I hope you enjoy it.

                                Gösta

                                JWAM: (Quit Smoking): http://www.SwedesDock.com/smoking
                                LDN - A Miracle Drug: http://www.SwedesDock.com/LDN/

                                Comment


                                • #17
                                  IOW (again) The %Wm_Timer becomes the Single_Click for our purposes here. {???}
                                  Yes. And I see no reason why a person couldn't create a SELECT CASE CB.CTL block to handle different IDs under the %WM_TIMER.(With some careful coding)
                                  Rod
                                  I want not 'not', not Knot, not Knott, not Nott, not knot, not naught, not nought, but aught.

                                  Comment


                                  • #18
                                    IOW (again) The %Wm_Timer becomes the Single_Click for our purposes here. {???}
                                    Yes the processing of the single-click event has been delayed and shifted out of the WM_COMMAND case block. Fun eh!
                                    Rgds, Dave

                                    Comment


                                    • #19
                                      Have you ever had to "double click again" even though you were sure you had double-clicked, but then decided you must have only single-clicked? Or cursed a designer for creating a hard-to-use screen?

                                      I sure have.

                                      And now you want to throw in a timer to further 'un-enhance' the 'user experience?'

                                      This really sounds like a screen screaming for a separate BUTTON to do the "double click" thing, and then you won't care if the user clicked on the label on not.

                                      That, or a non-optimal choice of controls. Insufficient information available to make suggestion.

                                      MCM
                                      Michael Mattias
                                      Tal Systems (retired)
                                      Port Washington WI USA
                                      [email protected]
                                      http://www.talsystems.com

                                      Comment


                                      • #20
                                        Gösta,
                                        In case your going further with this:
                                        I have re-learned something after posting this statement:
                                        And I see no reason why a person couldn't create a SELECT CASE CB.CTL block to handle different IDs under the %WM_TIMER.
                                        Once you're under the %WM_TIMER the CB.CTL returns the timer's ID, ergo you'll have to carry the CTL from the %WM_COMMAND if you're going to handle multiple ID's with the timer. You can possibly do something for the single click prior to setting the timer.
                                        Rod
                                        I want not 'not', not Knot, not Knott, not Nott, not knot, not naught, not nought, but aught.

                                        Comment

                                        Working...
                                        X