Jump to content

Teach me how to add a function my buttons


Recommended Posts

#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
Opt("GUIOnEventMode", 1)
Opt("GUIResizeMode", $GUI_DOCKAUTO+$GUI_DOCKRIGHT+$GUI_DOCKBOTTOM)
Opt("GUIResizeMode", $GUI_DOCKAUTO+$GUI_DOCKRIGHT+$GUI_DOCKBOTTOM)
Opt("GUIResizeMode", $GUI_DOCKAUTO+$GUI_DOCKRIGHT+$GUI_DOCKBOTTOM)
Opt("GUIResizeMode", $GUI_DOCKAUTO+$GUI_DOCKRIGHT+$GUI_DOCKBOTTOM)
Opt("GUIResizeMode", $GUI_DOCKAUTO+$GUI_DOCKRIGHT+$GUI_DOCKBOTTOM)
Opt("GUIResizeMode", $GUI_DOCKAUTO+$GUI_DOCKRIGHT+$GUI_DOCKBOTTOM)
#Region ### START Koda GUI section ### Form=C:\Users\Wombat\StormCopper Work\stormcopper search engine.kxf
$Form1_1 = GUICreate("Trumpf500 Search Engin", 312, 153, 803, 723, BitOR($WS_POPUP,$DS_SETFOREGROUND))
GUISetOnEvent($GUI_EVENT_CLOSE, "Form1_1Close")
GUISetOnEvent($GUI_EVENT_MINIMIZE, "Form1_1Minimize")
GUISetOnEvent($GUI_EVENT_MAXIMIZE, "Form1_1Maximize")
GUISetOnEvent($GUI_EVENT_RESTORE, "Form1_1Restore")
$Label1 = GUICtrlCreateLabel("Trumpf500 Search Engine", 8, 8, 213, 24)
GUICtrlSetFont(-1, 12, 800, 0, "MS Sans Serif")
GUICtrlSetColor(-1, 0x3399FF)
GUICtrlSetOnEvent(-1, "Label1Click")
$Input1 = GUICtrlCreateInput("Program Number", 8, 40, 209, 21)
GUICtrlSetOnEvent(-1, "Input1Change")
GUICtrlCreateButton("", 32, 72, 161, 57, $BS_ICON)
GUICtrlSetImage(-1, "C:\Users\Wombat\Pictures\search.ico", -1)
GUICtrlSetOnEvent(-1, "Button2Click")
$Button1 = GUICtrlCreateButton("Close", 248, 8, 59, 25)
GUICtrlSetOnEvent(-1, "Button2Click")
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###
While 1
Sleep(100)
WEnd
Func Button2Click()
EndFunc
Func Form1_1Close()
EndFunc
Func Form1_1Maximize()
EndFunc
Func Form1_1Minimize()
EndFunc
Func Form1_1Restore()
EndFunc
Func Input1Change()
EndFunc
Func Label1Click()
EndFunc

I've written this script, hoping to create a small search program for my computer at work. Well, I haven't a clue on how to make the close window close the window/program... can someone show me how?

Just look at us.
Everything is backwards; everything is upside down. Doctors destroy health. Lawyers destroy justice. Universities destroy knowledge. Governments destroy freedom. The major media destroy information and religions destroy spirituality. ~ Michael Ellner


The internet is our one and only hope at a truly free world, do not let them take it from us...

Link to comment
Share on other sites

Func Button2Click()
GUIDelete()
EndFunc ;==>Button2Click

Func Form1_1Close()
GUIDelete()
EndFunc ;==>Form1_1Close
Put the code inside [autoit*]...[/autoit*] (w/o the asterisks)tags to represent in a color highlighted box

Orelse assign them to the same function

$Button1 = GUICtrlCreateButton("Close", 248, 8, 59, 25)
GUICtrlSetOnEvent(-1, "Form1_1Close")
GUISetState(@SW_SHOW)

Well a GUIGetMsg() is more better(personal choice), KODA uses GUICtrlSetOnEvent though.

Regards :)

Edited by PhoenixXL

My code:

PredictText: Predict Text of an Edit Control Like Scite. Remote Gmail: Execute your Scripts through Gmail. StringRegExp:Share and learn RegExp.

Run As System: A command line wrapper around PSEXEC.exe to execute your apps scripts as System (LSA). Database: An easier approach for _SQ_LITE beginners.

MathsEx: A UDF for Fractions and LCM, GCF/HCF. FloatingText: An UDF for make your text floating. Clipboard Extendor: A clipboard monitoring tool. 

Custom ScrollBar: Scroll Bar made with GDI+, user can use bitmaps instead. RestrictEdit_SRE: Restrict text in an Edit Control through a Regular Expression.

Link to comment
Share on other sites

I've written this script, hoping to create a small search program for my computer at work. Well, I haven't a clue on how to make the close window close the window/program... can someone show me how?

Many of the help topics in the help file have working examples ... in your case the GUICreate also has an example of closing the window --> exits program.
Link to comment
Share on other sites

KODA uses GUICtrlSetOnEvent though.

I thought it gives us choice between the two. :huggles:

----------------------------------------

:bye: Hey there, was I helpful?

----------------------------------------

My Current OS: Win8 PRO (64-bit); Current AutoIt Version: v3.3.8.1

Link to comment
Share on other sites

I thought it gives us choice between the two. :huggles:

Maybe I haven't yet used those tools much before commenting, SORRY for that :( Edited by PhoenixXL

My code:

PredictText: Predict Text of an Edit Control Like Scite. Remote Gmail: Execute your Scripts through Gmail. StringRegExp:Share and learn RegExp.

Run As System: A command line wrapper around PSEXEC.exe to execute your apps scripts as System (LSA). Database: An easier approach for _SQ_LITE beginners.

MathsEx: A UDF for Fractions and LCM, GCF/HCF. FloatingText: An UDF for make your text floating. Clipboard Extendor: A clipboard monitoring tool. 

Custom ScrollBar: Scroll Bar made with GDI+, user can use bitmaps instead. RestrictEdit_SRE: Restrict text in an Edit Control through a Regular Expression.

Link to comment
Share on other sites

Don't use GUIDelete unless you also plan on exiting the script at that point (Exit command), otherwise the script has no way to be closed correctly.

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

Thank you for all the examples and the great advice.

I know the help file is VERY extensive. I had looked through it and couldn't find an answer, so I decided to ask whilst I continued searching.

I' loving autoit btw. Much easier than sitting in notepad or notepad++ even and trying to write vbscript and hoping other machines can run my scripts.

Just look at us.
Everything is backwards; everything is upside down. Doctors destroy health. Lawyers destroy justice. Universities destroy knowledge. Governments destroy freedom. The major media destroy information and religions destroy spirituality. ~ Michael Ellner


The internet is our one and only hope at a truly free world, do not let them take it from us...

Link to comment
Share on other sites

Don't use GUIDelete unless you also plan on exiting the script at that point (Exit command), otherwise the script has no way to be closed correctly.

Then what would be the proper "Close" command to use?

Just look at us.
Everything is backwards; everything is upside down. Doctors destroy health. Lawyers destroy justice. Universities destroy knowledge. Governments destroy freedom. The major media destroy information and religions destroy spirituality. ~ Michael Ellner


The internet is our one and only hope at a truly free world, do not let them take it from us...

Link to comment
Share on other sites

Exit

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

Wombat,

BrewmanNH is advising caution when using GUIDelete, that's all. Don't delete your last GUI unless you are exiting the script. It is perfectly valid to create and delete subordinate gui's.

kylomas

edit: completely missed the point

Edited by kylomas

Forum Rules         Procedure for posting code

"I like pigs.  Dogs look up to us.  Cats look down on us.  Pigs treat us as equals."

- Sir Winston Churchill

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...