Jump to content

How to create a click button within a Gui window


djbinh
 Share

Recommended Posts

Hi All,

im really new with Autoit, I want to know how to create a click button within a gui windows

#include <WinAPI.au3>

; #469512

Global Const $COLOR_ACTIVECAPTION = 2

Global Const $COLOR_GRADIENTACTIVECAPTION = 27

Local $aElements[2] = [$COLOR_ACTIVECAPTION, $COLOR_GRADIENTACTIVECAPTION]

; Red and Yellow

Local $aColors[3] = [255, 65535], $aSaveColors[2]

GUICreate("Supagas ", 1000, 800)

$aSaveColors[0] = _WinAPI_GetSysColor($COLOR_ACTIVECAPTION)

$aSaveColors[1] = _WinAPI_GetSysColor($COLOR_GRADIENTACTIVECAPTION)

_WinAPI_SetSysColors($aElements, $aColors)

GUISetState()

While 1

$Msg = GUIGetMsg()

Switch $Msg

Case -3 ; $GUI_EVENT_CLOSE

ExitLoop

EndSwitch

WEnd

_WinAPI_SetSysColors($aElements, $aSaveColors)

Link to comment
Share on other sites

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

$theGUI = GUICreate("formWithButton", 293, 220, 192, 124)
$button1 = GUICtrlCreateButton("A button", 40, 32, 209, 121)
GUISetState(@SW_SHOW)


While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case $GUI_EVENT_CLOSE
Exit
Case $button1
ShellExecute("http://www.autoitscript.com/autoit3/docs/functions/GUICtrlCreateButton.htm")

EndSwitch
WEnd

Link to comment
Share on other sites

Look up GUICtrlCreateButton in the help file and study the example shown in there.

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Link to comment
Share on other sites

Hi Guys

what im trying to do is to make a gui window with Button to action a .exe Error message

( Case $msg = $GUI_EVENT_CLOSE)

(Case $msg = ^ ERROR)

#include <WinAPI.au3>

; #469512

Global Const $COLOR_ACTIVECAPTION = 2

Global Const $COLOR_GRADIENTACTIVECAPTION = 27

Local $aElements[2] = [$COLOR_ACTIVECAPTION, $COLOR_GRADIENTACTIVECAPTION]

; Red and Yellow

Local $aColors[3] = [255, 65535], $aSaveColors[2]

GUICreate("Supagas ", 1000, 800)

$aSaveColors[0] = _WinAPI_GetSysColor($COLOR_ACTIVECAPTION)

$aSaveColors[1] = _WinAPI_GetSysColor($COLOR_GRADIENTACTIVECAPTION)

$button1 = GUICtrlCreateButton("Adobe", 40, 32, 209, 121)

$button2 = GUICtrlCreateButton("Signature Reset", 400, 32, 209, 121)

$button3 = GUICtrlCreateButton("Install Printers", 700, 32, 209, 121)

$button4 = GUICtrlCreateButton("CO2", 40, 241, 209, 121)

_WinAPI_SetSysColors($aElements, $aColors)

GUISetState()

While 1

$msg = GUIGetMsg()

Select

Case $msg = $GUI_EVENT_CLOSE

ExitLoop

Case $msg = $Button_1

Run('notepad.exe') ; Will Run/Open Notepad

EndSelect

WEnd

_WinAPI_SetSysColors($aElements, $aSaveColors)

Link to comment
Share on other sites

Maybe you should reference the post you keep linking to, there's a GUI and a Button in there. Then, open the help file, read what each of the commands do, and learn something. Because copying code and hoping to get it to work for you isn't working for your knowledge level in the language.

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Link to comment
Share on other sites

A little bit of spoonfeeding to get you over that first hump...........

The 1 button works & should show you how to get the others going.

It's a bitch at first. I know being self-taught that the teacher is as stupid as me.

BrewManNHs' advice is the best you can get.... study the help file.

#include <WindowsConstants.au3>;'fixIncludes.au3' decided We needed this one.
#include <GUIConstantsEx.au3>; ditto
#include <WinAPI.au3>


;Global Const $COLOR_ACTIVECAPTION = 2>>>>>>>>>Shown as pre-declared at syntax check (tools from Scite toolbar), so I commented it out. This happens alot if you copy older scripts
;Global Const $COLOR_GRADIENTACTIVECAPTION = 27>>>>>>>>>>>ditto
Local $aElements[2] = [$COLOR_ACTIVECAPTION, $COLOR_GRADIENTACTIVECAPTION]
; Red and Yellow
Local $aColors[3] = [255, 65535], $aSaveColors[2]

GUICreate("Supagas ", 1000, 800)
$aSaveColors[0] = _WinAPI_GetSysColor($COLOR_ACTIVECAPTION)
$aSaveColors[1] = _WinAPI_GetSysColor($COLOR_GRADIENTACTIVECAPTION)


$button1 = GUICtrlCreateButton("Adobe", 40, 32, 209, 121); highlite 'GUICtrlCreateButton' while in Scite & press F1.
;An example is given that gives the necessary '#includes' without needing 'fixIncludes.au3'....but get it anyway. It is very handy for those like us (beginners)
$button2 = GUICtrlCreateButton("Signature Reset", 400, 32, 209, 121)
$button3 = GUICtrlCreateButton("Install Printers", 700, 32, 209, 121)
$button4 = GUICtrlCreateButton("CO2", 40, 241, 209, 121)


_WinAPI_SetSysColors($aElements, $aColors);I can't do anything for you here. Lack of knowledge.

GUISetState()
While 1
$msg = GUIGetMsg()
Select
Case $msg = $GUI_EVENT_CLOSE
ExitLoop
Case $msg = $button1; notice it is no longer $Button_1 (from your scrip). Now it matches the declared variable---$button1
Run('notepad.exe') ; Will Run/Open Notepad

EndSelect

WEnd

_WinAPI_SetSysColors($aElements, $aSaveColors)
Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...