Jump to content
Sign in to follow this  
Topher

Help double clicking on a button

Recommended Posts

Topher

I have an array of buttons for which I wish to know if a double click has occurred on one and which one it is.

$msg = GUIGetMsg()
For $a = 1 To 20
   For $b = 1 To 5
      If $msg = $LetterButtonArray[$a][$b] Then
         $Letter = Asc(GUICtrlRead($LetterButtonArray[$a][$b])) - 64
         $AlphaState[$Letter] += 1
      EndIf
   Next
Next
[/code


            
                


    Edited  by Topher
    
    

            
        

        
            
                
                    

        
        
            
                
                    
                
            
            
            
        
    


                
            
            
                
                    
                    
                    
                
                
                    
                
            
        

        
            




  
  
    [left][hr]$mood = "whimsy"
$mode = "confused"
$randomChaos = True
Do
Something()
Until $Tired
[/left][left]Reflex (Arcade game)[/left][left]IX (Board game)[/left][left]The Word Game (Word game)[/left][left]Plastic Sliding Squares Puzzle (Puzzle)[/left]

Share this post


Link to post
Share on other sites
zorphnog

You need to look at GUIRegisterMsg and the BN_DBLCLK notification. Here's an example:

#include <GUIConstantsEx.au3>
#include <ButtonConstants.au3>
#include <WindowsConstants.au3>

$hGui = GUICreate("Button Test", 200, 50)
$hButton = GUICtrlCreateButton("Double Click Me", 10, 10, -1, -1, BitOR($BS_NOTIFY, $BS_OWNERDRAW))
GUIRegisterMsg($WM_COMMAND, "_WM_COMMAND")
GUISetState()

While 1
    $Msg = GUIGetMsg()
    If $Msg = $GUI_EVENT_CLOSE Then Exit
WEnd

Func _WM_COMMAND($hWnd, $Msg, $wParam, $lParam)
    Local $nNotifyCode = BitShift($wParam, 16)
    Local $nID = BitAND($wParam, 0x0000FFFF)
    Local $hCtrl = $lParam

    If $nNotifyCode = $BN_DBLCLK And $nID = $hButton Then
        MsgBox(4096, "Test", "Double Clicked!!", 10)
        Return 0
    EndIf

    Return $GUI_RUNDEFMSG
EndFunc
Edited by zorphnog

Share this post


Link to post
Share on other sites
Topher

Thank you

Working on adapting it to multiple buttons now. I think I see how.


[left][hr]
$mood = "whimsy"
$mode = "confused"
$randomChaos = True
Do
Something()
Until $Tired
[/left][left]Reflex (Arcade game)[/left][left]IX (Board game)[/left][left]The Word Game (Word game)[/left][left]Plastic Sliding Squares Puzzle (Puzzle)[/left]

Share this post


Link to post
Share on other sites
Topher

Just thought I'd close out this thread with the finished product:

Func _WM_COMMAND($hWnd, $Msg, $wParam, $lParam)
    Local $nNotifyCode = BitShift($wParam, 16)
    Local $nID = BitAND($wParam, 0x0000FFFF)
    Local $hCtrl = $lParam
Local $Letter
    If $nNotifyCode = $BN_DBLCLK Then
  For $a = 1 To 26
   If $nID = $Alphabet[$a] Then
    $AlphaState[$a] += 1
    If $AlphaState[$a] > 2 Then $AlphaState[$a] = 0
    SetAlphaColor($a, $Alphabet[$a])
    $ShowLetters = True
    Return $GUI_RUNDEFMSG
   EndIf
  Next
  For $a = 1 To 20
   For $b = 1 To 5
    If $nID = $LetterButtonArray[$a][$b] Then
     $Letter = Asc(GUICtrlRead($LetterButtonArray[$a][$b])) - 64
     $AlphaState[$Letter] += 1
     If $AlphaState[$Letter] = 3 Then $AlphaState[$Letter] = 0
     SetAlphaColor($Letter, $Alphabet[$Letter])
     $ShowLetters = True
     Return $GUI_RUNDEFMSG
    EndIf
   Next
  Next
    EndIf
    Return $GUI_RUNDEFMSG
EndFunc

Works like a charm.

Thank you very much for pointing me in the right direction and for your excellent example. I learned a lot.


[left][hr]
$mood = "whimsy"
$mode = "confused"
$randomChaos = True
Do
Something()
Until $Tired
[/left][left]Reflex (Arcade game)[/left][left]IX (Board game)[/left][left]The Word Game (Word game)[/left][left]Plastic Sliding Squares Puzzle (Puzzle)[/left]

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×