Laymanball Posted October 3, 2011 Posted October 3, 2011 (edited) Use for write many script code. and create file script. expandcollapse popup#include <ButtonConstants.au3> #include <EditConstants.au3> #include <GUIConstantsEx.au3> #include <StaticConstants.au3> #include <WindowsConstants.au3> GUICreate("Editor Create File", 420, 260, -1, -1) GUICtrlCreateLabel("Script Editor", 130, 16, 94, 17) $Edit1 = GUICtrlCreateEdit("", 16, 40, 300, 200) GUICtrlSetData(-1, _SampleScript()) $Button1 = GUICtrlCreateButton("Script in", 330, 40, 75, 25, $WS_GROUP) $Button2 = GUICtrlCreateButton("Clear", 330, 101, 75, 25, $WS_GROUP) $Button3 = GUICtrlCreateButton("Create", 330, 157, 75, 25, $WS_GROUP) $Button4 = GUICtrlCreateButton("Exit", 330, 215, 75, 25, $WS_GROUP) GUISetState(@SW_SHOW) While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $Button1 $tFile = FileOpenDialog("Choose a file", @DesktopDir & "\", "Text Script (*.txt;*.au3)", 1 + 4) If $tFile Then If GUICtrlRead($Edit1)<>"" Then GUICtrlSetData($Edit1, "") $sFile = FileOpen($tFile, 0) $fRead = FileRead($sFile) GUICtrlSetData($Edit1, $fRead) EndIf Case $Button2 If GUICtrlRead($Edit1)<>"" Then GUICtrlSetData($Edit1, "") Case $Button3 Local $Scriptname = InputBox("Build", "Enter:Scriptname", "Hello.au3", "", 200, 100, 415, 305) If($Edit1="")And($Scriptname="")Then Exit Local $aret = _FileAppend(GUICtrlRead($Edit1), $Scriptname) If $aret = 1 Then MsgBox(64, "", "Create file successful") GUIDelete() Exit EndIf Case $Button4 GUIDelete() ExitLoop EndSwitch WEnd Func _SampleScript() Dim $Array[12] $Array[0] = 'Dim $btn' $Array[1] = 'Do' $Array[2] = ' $btn = MsgBox(35, "Sample", "Hello World!", 0, 0)' ;Table script array. $Array[3] = ' Switch $btn' $Array[4] = ' Case 6' $Array[5] = ' MsgBox(0, "", "You clicked..YES")' $Array[6] = ' Case 7' $Array[7] = ' MsgBox(0, "", "You clicked..NO")' $Array[8] = ' Case 2' $Array[9] = ' MsgBox(0, "", "You clicked..CANCEL to ExitApp")' $Array[10] = ' EndSwitch' $Array[11] = 'Until $btn = 2' $string = "" FOR $element IN $Array $string = $string & $element & @CRLF NEXT Return $string EndFunc ;=========FileAppend Library Include========= Func _FileAppend($sText, $sFilename) Local $Ret = FileWrite($sFilename, $sText) If($Ret=0)Then Return SetError(1, 0, 0) Return $Ret EndFunc ;==>FileAppend. Edited October 3, 2011 by Laymanball My Sample Script Download: VistaDesktopIconsChangerForXp.au3 (Com,Doc and Bin only) http://www.4shared.com/rar/NMHYL5Igba/VistaDesktopIconsChangerForXp_.html VistaDesktopIconsChangerForXp.exe (Resources) http://www.4shared.com/rar/nzs7Mb1gba/VistaDesktopIconsChangerForXp_.html
Laymanball Posted October 3, 2011 Author Posted October 3, 2011 (edited) Modify. Add Script AppendSetTextControl() Library Function. Use for Script in expandcollapse popup#include <ButtonConstants.au3> #include <EditConstants.au3> #include <GUIConstantsEx.au3> #include <StaticConstants.au3> #include <WindowsConstants.au3> GUICreate("Editor Create File", 420, 260, -1, -1) GUICtrlCreateLabel("Script Editor", 130, 16, 94, 17) $Edit1 = GUICtrlCreateEdit("", 16, 40, 300, 200) GUICtrlSetData(-1, _SampleScript()) $Button1 = GUICtrlCreateButton("Script in", 330, 40, 75, 25, $WS_GROUP) $Button2 = GUICtrlCreateButton("Clear", 330, 101, 75, 25, $WS_GROUP) $Button3 = GUICtrlCreateButton("Create", 330, 157, 75, 25, $WS_GROUP) $Button4 = GUICtrlCreateButton("Exit", 330, 215, 75, 25, $WS_GROUP) GUISetState(@SW_SHOW) While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $Button1 $tFilename = FileOpenDialog("Choose a file", @DesktopDir & "\", "Text Script (*.txt;*.au3)", 1 + 4) If $tFilename Then If GUICtrlRead($Edit1)<>"" Then GUICtrlSetData($Edit1, "") _AppendSetTextControl($tFilename, $Edit1) EndIf Case $Button2 If GUICtrlRead($Edit1)<>"" Then GUICtrlSetData($Edit1, "") Case $Button3 Local $Scriptname = InputBox("Build", "Enter:Scriptname", "Hello.au3", "", 200, 100, 415, 305) If($Edit1="")And($Scriptname="")Then Exit Local $aret = _FileAppend(GUICtrlRead($Edit1), $Scriptname) If $aret = 1 Then MsgBox(64, "", "Create file successful") GUIDelete() Exit EndIf Case $Button4 GUIDelete() ExitLoop EndSwitch WEnd Func _SampleScript() Dim $Array[12] $Array[0] = 'Dim $btn' $Array[1] = 'Do' $Array[2] = ' $btn = MsgBox(35, "Sample", "Hello World!", 0, 0)' ;Table script array. $Array[3] = ' Switch $btn' $Array[4] = ' Case 6' $Array[5] = ' MsgBox(0, "", "You clicked..YES")' $Array[6] = ' Case 7' $Array[7] = ' MsgBox(0, "", "You clicked..NO")' $Array[8] = ' Case 2' $Array[9] = ' MsgBox(0, "", "You clicked..CANCEL to ExitApp")' $Array[10] = ' EndSwitch' $Array[11] = 'Until $btn = 2' $string = "" FOR $element IN $Array $string = $string & $element & @CRLF NEXT Return $string EndFunc ;=========FileAppend Library Include========= Func _FileAppend($sText, $sFilename) Local $Ret = FileWrite($sFilename, $sText) If($Ret=0)Then Return SetError(1, 0, 0) Return $Ret EndFunc ;==>FileAppend. ;======AppendSetTextControl Library Include======= Func _AppendSetTextControl($hFilename, $hControlID) Local $sFile = FileOpen($hFilename, 0) Local $fRead = FileRead($sFile) GUICtrlSetData($hControlID, $fRead) If(@error=-1)Or(Not $fRead)Then Return SetError(1, 0, 0) Return 0 EndFunc ;==>AppendSetTextControl. Edited October 3, 2011 by Laymanball My Sample Script Download: VistaDesktopIconsChangerForXp.au3 (Com,Doc and Bin only) http://www.4shared.com/rar/NMHYL5Igba/VistaDesktopIconsChangerForXp_.html VistaDesktopIconsChangerForXp.exe (Resources) http://www.4shared.com/rar/nzs7Mb1gba/VistaDesktopIconsChangerForXp_.html
Laymanball Posted October 4, 2011 Author Posted October 4, 2011 (edited) Using script 2 library function on other edit. ;=========FileAppend Library Include========= Func _FileAppend($sText, $sFilename) Local $Ret = FileWrite($sFilename, $sText) If($Ret=0)Then Return SetError(1, 0, 0) Return $Ret EndFunc ;==>FileAppend. ;======AppendSetTextControl Library Include======= Global $hFilename, $hControlID Func _AppendSetTextControl($hFilename, $hControlID) Local $sFile = FileOpen($hFilename, 0) Local $fRead = FileRead($sFile) Local $Handle = WinGetHandle("[Active]") ControlSetText($Handle, "", $hControlID, $fRead) If(@error=-1)Or(Not $fRead)Then Return SetError(1, 0, 0) Return 0 EndFunc ;==>AppendSetTextControl. ;============================================= ;############################################# ;==============Script Sample================== $hFilename = 'OldText.txt' ;OperateVar $hControlID = 'Edit1' ;"-------" If Not FileExists($hFilename)Then _FileAppend("Hello World!", "OldText.txt") ;OldFileExists Checked. Run(@SystemDir&"\Notepad.exe") ;open notepad WinWait("[Class:Notepad]") ;wait until window show. _AppendSetTextControl($hFilename, $hControlID) ;show text on the notepad. $tText = ControlGetText("[Active]", "", $hControlID) ;get text in edit to show. _FileAppend($tText, "NewText.txt") ;save text to new filename. Edited October 4, 2011 by Laymanball My Sample Script Download: VistaDesktopIconsChangerForXp.au3 (Com,Doc and Bin only) http://www.4shared.com/rar/NMHYL5Igba/VistaDesktopIconsChangerForXp_.html VistaDesktopIconsChangerForXp.exe (Resources) http://www.4shared.com/rar/nzs7Mb1gba/VistaDesktopIconsChangerForXp_.html
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now