Sign in to follow this  
Followers 0
lordlol

need help with a gui with a image-button..

6 posts in this topic

Hello :D

Im new to autoit programming.

i want to build a prog,which starts when i click on a image-button:

$button1 = GUICtrlCreateButton ("1", 0,0,40,40,$BS_ICON)
guictrlsetimage(-1,"pat.ico")

-- Exemble.

well i want to create ~5 buttons with images.

i hope some1 can give me the code for starting a func when an icon is pressed.

Regards Lordlol

Share this post


Link to post
Share on other sites



Quick example

#include <GUIConstants.au3>
; == GUI generated with Koda ==);
$Form1 = GUICreate("AForm1", 622, 441, 192, 125)
$Button1 = GUICtrlCreateButton("(Not allowed)", 96, 40, 81, 57, $BS_ICON)
GUICtrlSetImage($Button1, "D:\AutoIT\icon1.ico")
GUISetState(@SW_SHOW)
While 1
    $msg = GuiGetMsg()
    Select
    Case $msg = $GUI_EVENT_CLOSE
        ExitLoop
        Case $msg = $Button1
            Run('Notepad.exe')   ; Will Run/Open Notepad
    Case Else
    ;;;;;;;
    EndSelect
WEnd


Get Beta versions Here Get latest SciTE editor Here AutoIt 1-2-3 by Valuater - A great starting point.

Time you enjoyed wasting is not wasted time ......T.S. Elliot
Suspense is worse than disappointment................Robert Burns
God help the man who won't help himself, because no-one else will...........My Grandmother

Share this post


Link to post
Share on other sites

thx,and if i got 5 buttons?

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

thx,and if i got 5 buttons?

Just a little added onto the code that BigDod wrote:

#include <GUIConstants.au3>
; == GUI generated with Koda ==);
$Form1 = GUICreate("AForm1", 622, 441, 192, 125)
$Button1 = GUICtrlCreateButton("(Not allowed)", 96, 40, 81, 57, $BS_ICON)
GUICtrlSetImage($Button1, "D:\AutoIT\icon1.ico")
GUISetState(@SW_SHOW)
While 1
    $msg = GuiGetMsg()
    Select
    Case $msg = $GUI_EVENT_CLOSE
        ExitLoop
        Case $msg = $Button1
            Run('Notepad.exe') ; Will Run/Open Notepad
        Case $msg = $Button2
          ; Actions here
        Case $msg = $Button3
          ; Actions here
        Case $msg = $Button4
          ; Actions here
        Case $msg = $Button5
          ; etc etc
    Case Else
  ;;;;;;;
    EndSelect
WEnd

Just make sure to define/create the other buttons :D

Edited by Somniis

Share this post


Link to post
Share on other sites

yes,it works but..

i got errors if i use script like:

#include <GUIConstants.au3>

GUICreate("Test",240,180)
#include <GUIConstants.au3>
$Button1 = GUICtrlCreateButton("", 10, 10, 40, 40, $BS_ICON)
GUICtrlSetImage($Button1, "test.ico")
$msg1 = Guictrlcreatelabel("lalala",50,30)
GUISetState(@SW_SHOW)
While 1
    $msg = GuiGetMsg()
    Select
    Case $msg = $GUI_EVENT_CLOSE
        ExitLoop
        Case $msg = $Button1
        Global $Paused 
HotKeySet("{up}", "Start") 
HotKeySet("{down}", "Terminate") 

While 1 
Sleep(100) 
WEnd 

Func Start() 
$Paused = NOT $Paused 
While $Paused 
MouseClick("Left") 
WEnd 
EndFunc 

Func Terminate() 
Exit 0 
EndFunc 

        
    Case Else
    ;;;;;;;
    EndSelect
WEnd

Error:

""While" statement has no matching "Wend" statement"

How to fix it?

Ty in advance,

Lordlol

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

Error:

""While" statement has no matching "Wend" statement"

How to fix it?

Ty in advance,

Lordlol

#include <GUIConstants.au3>

GUICreate("Test",240,180)
$Button1 = GUICtrlCreateButton("", 10, 10, 40, 40, $BS_ICON)
GUICtrlSetImage($Button1, "test.ico")
$msg1 = Guictrlcreatelabel("lalala",50,30)
GUISetState(@SW_SHOW)

HotKeySet("{up}", "Start") 
HotKeySet("{down}", "Terminate") 
Global $Paused 

While 1
    $msg = GuiGetMsg()
    Select
    Case $msg = $GUI_EVENT_CLOSE
        ExitLoop
    Case Else
 ;;;;;;;
    EndSelect
WEnd

Func Start() 
    $Paused = NOT $Paused 
    While $Paused 
        MouseClick("Left") 
    WEnd 
EndFunc 

Func Terminate() 
    Exit 0 
EndFunc

Instead of putting the functions in the While statement, put them at the end of the code. Also, put the variables and HotKeySet()s before the While loop. :D The above runs fine for me without any errors.

EDIT: If you still get errors, make sure you have the latest version of AutoIT. :wacko:

Edited by Somniis

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