Announcement

Collapse
No announcement yet.

Detect a left mouse down on a label

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

  • Detect a left mouse down on a label

    I know the %SS_NOTIFY style should be used on a label to detect a click. But I can't seem to detect it. I've also tried the subclass text box way, which does not work at all except on text boxes. I know I've done it before with a label, but can't find my example.
    Barry
    Barry

  • #2
    Set the SS_NOTIFY style and detect the STN_CLICKED notification through the WM_COMMAND message.

    Comment


    • #3
      Here's a sample
      Test all four 'STN_xxxx' 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_COMMAND
            If CbCtl = %LBL_LABEL1 Then
              If CbCtlMsg = %STN_ENABLE Then
                  Dialog Set Text CbHndl, ""
                  Dialog Set Text CbHndl, "LBL Enabled: " + Format$(%STN_ENABLE)
              End If
              If CbCtlMsg = %STN_DISABLE Then
                  Dialog Set Text CbHndl, ""
                  Dialog Set Text CbHndl, "LBL Disabled: " + Format$(%STN_DISABLE)
              End If
              If CbCtlMsg = %STN_DBLCLK  Then
                  Dialog Set Text CbHndl, "DBLCLK: " + Format$(%STN_DBLCLK)
              ElseIf CbCtlMsg = %STN_CLICKED Then
                  Dialog Set Text CbHndl, "CLICKED: " + Format$(%STN_CLICKED)
              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_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


      • #4
        Dave,
        Thanks. that works but not for what I want. I want to send a message to a checkbox to set or unset the check. Since that is a toggle, I should be able to do that just the same way to set or unset. I use
        Code:
        control send cb.hndl, %chk_ThisCheckbox,%BM_CLICK,0,0
        or %BN_CLICKED. but neither fire it off.
        Barry

        Comment


        • #5
          To programmatically set the check status of a checkbox you want to use the BM_SETCHECK message, not BM_CLICK.

          (Since this is DDT forum, doesn't DDT have a "CHECKBOX SET CHECKED" statement of some kind?)
          Michael Mattias
          Tal Systems Inc. (retired)
          Racine WI USA
          [email protected]
          http://www.talsystems.com

          Comment


          • #6
            Yes, and I am using that. control set check hndl, %id, minID, Max ID
            Barry

            Comment


            • #7
              PB Forms put another %IDC_ldb_ThisLabel in code way infront of where I was testing. It works now.
              Barry

              Comment


              • #8
                Just for reference.
                Code:
                #IF 0
                ' Set State of a checkbox
                CONTROL SET CHECK hDlg, id&, checkstate&        ' Retrieve with CONTROL GET CHECK hDlg, id& TO lResult&
                ' Set state of an Option Control
                CONTROL SET OPTION hDlg, id&, minid&, maxid&    ' Retrieve with CONTROL GET CHECK hDlg, id& TO lResult&
                #ENDIF
                 
                #Compile Exe
                #Dim All
                #Include "WIN32API.INC"
                 
                %IdCancel    =   2
                %IDD_DIALOG1 = 100
                %LBL_LABEL1  = 101
                %LBL_LABEL2  = 102
                %LBL_LABEL3  = 103
                %IDC_Option1 = 111
                %IDC_Option2 = 112
                %IDC_Check1  = 121
                '------------------/
                 
                CallBack Function DlgProc()
                 Local lRes As Long
                  Select Case As Long CB.Msg
                    Case %WM_InitDialog
                      CONTROL SET OPTION CbHndl, %IDC_Option1, %IDC_Option1, %IDC_Option2
                 
                    Case %WM_Command
                      Select Case As Long CB.Ctl
                        Case %LBL_LABEL1
                          If CbCtlMsg = %STN_Clicked Then
                            CONTROL GET CHECK CbHndl, %IDC_Option1 TO lRes
                            If lRes = 0 Then CONTROL SET OPTION CbHndl, %IDC_Option1, %IDC_Option1, %IDC_Option2
                            Control Set Focus CbHndl, %IDC_Option1
                          End If
                        Case %IDC_Option1
                 
                        Case %LBL_LABEL2
                          If CbCtlMsg = %STN_Clicked Then
                            CONTROL GET CHECK CbHndl, %IDC_Option2 TO lRes
                            If lRes = 0 Then CONTROL SET OPTION CbHndl, %IDC_Option2, %IDC_Option1, %IDC_Option2
                            Control Set Focus CbHndl, %IDC_Option2    ' or use %WM_NEXTDLGCTL ?
                          End If
                        Case %IDC_Option2
                 
                        Case %LBL_LABEL3
                          If CbCtlMsg = %STN_Clicked Then
                            CONTROL GET CHECK CbHndl, %IDC_Check1 TO lRes
                            CONTROL SET CHECK CbHndl, %IDC_Check1, lRes Xor 1
                            Control Set Focus CbHndl, %IDC_Check1
                          End If
                        Case %IDC_Check1
                 
                        Case %IdCancel
                          Dialog End CbHndl, 0
                      End Select
                  End Select
                End Function
                '------------------/DlgProc
                 
                Function PBMain()
                 Local hDlg  As Dword
                   Dialog New 0, "Test", 167, 193, 200, 120, %WS_Caption Or %WS_SysMenu To hDlg
                    Control Add Label,    hDlg, %LBL_LABEL1, "Click Me !!", 20, 10, 65, 10, %SS_Notify
                    Control Add Label,    hDlg, %LBL_LABEL2, "Click Me !!", 20, 35, 65, 10, %SS_Notify
                    Control Add Option,   hDlg, %IDC_Option1, "Option1", 20, 20, 100, 10, %WS_Group' Or %WS_TabStop
                    Control Add Option,   hDlg, %IDC_Option2, "Option2", 20, 45, 100, 10, '%WS_TabStop
                    Control Add Label,    hDlg, %LBL_LABEL3, "Click Me !!", 20, 60, 65, 10, %SS_Notify Or %WS_Group
                    Control Add CheckBox, hDlg, %IDC_Check1, "CheckBox1", 20, 75, 100, 10
                    Control Add Button,   hDlg, %IdCancel, "Escape", 130, 95, 50, 15
                 
                  Dialog Show Modal hDlg, Call DlgProc
                 
                End Function
                '------------------/PbMain
                Rgds, Dave

                Comment


                • #9
                  Dave, I did get it working, thanks.
                  Barry

                  Comment

                  Working...
                  X