Sign in to follow this  
Followers 0
Aceguy

[SOLVED] Another way to register Button presses.

4 posts in this topic

#1 ·  Posted (edited)

when i used this on my laptop, the console reports different numbers......

so i concluded that this way is unreliable.................?????

#include<ButtonConstants.au3>
#include<GUIConstantsEx.au3>
Opt("GUIOnEventMode", 1)

$Form1 = GUICreate("Form1", 333, 445, 370, 172)

dim $Pic1[7]
dim $but[7]
$y=0

for $ct = 1 to 6
$Pic1[$ct]= GUICtrlCreatelabel("", 28, 28+$y, 40, 40)
GUICtrlSetBkColor(-1,0x000000)
GUICtrlSetState(-1, $GUI_DISABLE)
$but[$ct] = GUICtrlCreateButton("",32,32+$y,32,32, $BS_ICON)
GUICtrlSetImage (-1,"C:\Users\Ace - PC\Documents\5_audiodev.ico")
GUICtrlSetOnEvent(-1,"pressed")
$y+=42
Next

GUISetState(@SW_SHOW)

While 1
    
    sleep(50)
WEnd

Func pressed()
ConsoleWrite("Pressed"&@lf)
local $iD = @GUI_CtrlId
    for $x=1 to 12 
        if $x= $iD then MsgBox(0,"",$iD,0) 
    Next
EndFunc
Edited by Aceguy

Share this post


Link to post
Share on other sites



This works for me

#include<ButtonConstants.au3>
#include<GUIConstantsEx.au3>
Opt("GUIOnEventMode", 1)

$Form1 = GUICreate("Form1", 333, 445, 370, 172)

Dim $Pic1[7]
Dim $but[7]
$y = 0

For $ct = 1 To 6
    $Pic1[$ct] = GUICtrlCreateLabel("", 28, 28 + $y, 40, 40)
    GUICtrlSetBkColor(-1, 0x000000)
    GUICtrlSetState(-1, $GUI_DISABLE)
    $but[$ct] = GUICtrlCreateButton("", 32, 32 + $y, 32, 32, $BS_ICON)
    ConsoleWrite("Button" & $ct & " ControlID" & $ct & "=" & $but[$ct] & @LF)
    GUICtrlSetImage(-1, "C:\Users\Ace - PC\Documents\5_audiodev.ico")
    GUICtrlSetOnEvent(-1, "pressed")
    $y += 42
Next

GUISetState(@SW_SHOW)

While 1
    Sleep(50)
WEnd

Func pressed()
    Local $iD = @GUI_CtrlId
    For $x = 1 To 6
        If $iD = $but[$x] Then ConsoleWrite("Button" &  $x & " pressed" & @LF)
    Next
EndFunc   ;==>pressed

Share this post


Link to post
Share on other sites

THANKS VM.

This is my idea. so far.

#include<ButtonConstants.au3>
#include<GUIConstantsEx.au3>
Opt("GUIOnEventMode", 1)

$Form1 = GUICreate("Form1", 333, 445, 370, 172)

$buttons=10

dim $Pic1[$buttons+1]
dim $but[$buttons+1]
$set=0
$last=0
$y=0



for $ct = 1 to $buttons
$Pic1[$ct]= GUICtrlCreatelabel("", 4, 4+$y, 40, 40)

GUICtrlSetState(-1, $GUI_DISABLE)
$but[$ct] = GUICtrlCreateButton("",8,8+$y,32,32, $BS_ICON)
GUICtrlSetImage (-1,"C:\Users\Ace - PC\Documents\5_audiodev.ico")
GUICtrlSetOnEvent(-1,"pressed")
$y+=42
Next

GUISetState(@SW_SHOW)

While 1
    sleep(50)
WEnd

Func pressed()

local $iD = @GUI_CtrlId
    for $x=1 to ($buttons)
        
    if $iD= $but[$x] then 
        ConsoleWrite("BLACK iD  -->"&$iD&"   X  --->"&$x&"   Setting   ---> "&(int($iD/2)-1)&@lf) 
        GUICtrlSetBkColor($Pic1[(int($iD/2)-1)],0x000000)
    $set=int($iD/2)-1
    EndIf
    
    if $last<>$set then GUICtrlSetBkColor($Pic1[$last],0xffffff)
    
Next
$last=$set
EndFunc

Share this post


Link to post
Share on other sites

Thats nice :P

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  
Followers 0