Jump to content

Recommended Posts

Here is my latest project,

It is a simple code editor that supports all text formats.

It will execute batch directly and will also execute maths.

It also has the simple feature of shellexecute (POINTLESS!)

1 error I found was that I dont know how to tell if the script* has been saved so it has to ask the user

I need to know that for executing batch where the file (if saved/opened) is executed using 'Run($location)'

GOTO bottom for latest version

Edit*:----the script made in the program. not the code for the program.

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
GUICreate("Script", 600, 400)
GUISetState(@SW_SHOW)
HotKeySet("{F5}", "execute1")
HotKeySet("{F4}", "shellexecute1")
HotKeySet("{F3}", "Executebatch1")
GUICtrlCreateLabel("F3 Execute Batch, F4 ShellExecute, F5 Execute Math", 10, 10)
$edit = GUICtrlCreateEdit("", 4, 54, 594, 343)
$save = GUICtrlCreateButton("Save", 74, 30, 70, 20)
$new = GUICtrlCreateButton("New", 144, 30, 70, 20)
$stop = GUICtrlCreateButton("Exit", 4, 30, 70, 20)
$open = GUICtrlCreateButton("Open", 214, 30, 70, 20)
$help = GUICtrlCreateButton("Info", 284, 30, 70, 20)
$progress = GUICtrlCreateProgress(370, 29, 220, 22)
Func execute1()
$executeans = Execute(GUICtrlRead($edit))
MsgBox("", "", $executeans)
EndFunc   ;==>execute1
Func shellexecute1()
ShellExecute(GUICtrlRead($edit))
EndFunc   ;==>shellexecute1
Func Executebatch1()
$saveyn = MsgBox(4, "", "Have you saved?")
If $saveyn = 6 Then
  Run($location)
Else
  MsgBox(48, "Warning", "Save before executing batch!")
EndIf
EndFunc   ;==>Executebatch1
While 1
$msg = GUIGetMsg()
If $msg = $GUI_EVENT_CLOSE Then ExitLoop
Select
  Case $msg = $help
   MsgBox(64, "Editor", "By James B")
  Case $msg = $open
   $openfile = FileOpenDialog("open", "", "Text documents (*.bat;*.txt;*.vbs;)")
   $netopen = FileOpen($openfile)
   $read_file = FileRead($netopen)
   GUICtrlSetData($progress, 100)
   Sleep(300)
   GUICtrlSetData($edit, $read_file)
   Sleep(300)
   GUICtrlSetData($progress, 0)
  Case $msg = $new
   GUICtrlSetData($edit, "")
  Case $msg = $stop
   ExitLoop
  Case $msg = $save
   $ynsave = MsgBox(1, "Editor", "Save?")
   If $ynsave = 1 Then
    $location = FileSaveDialog("Save", @MyDocumentsDir, "Text documents (*.bat;*.txt;*.vbs;)", 2)
    GUICtrlSetData($progress, 100)
    Sleep(300)
    $exists = FileExists($location)
    If $exists = 1 Then
     FileDelete($location)
    EndIf
    FileWrite($location, GUICtrlRead($edit))
    Sleep(300)
    GUICtrlSetData($progress, 0)
   EndIf
EndSelect
WEnd
FileClose($openfile)
FileClose($location)

Please report errors but do not edit!

Edited by Scriptmaster

shutdown(1)

Link to post
Share on other sites

I dont know how to tell if the script has been saved

Maybe you mean you don't know if the script has been changed.

Search the forums for examples of $EN_CHANGE. You can set a flag to indicate a change was made every time the EN_CHANGE notification fires, and reset the flag whenever the script is saved.

Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.
Link to post
Share on other sites

You mean could you find out if a variable is declared, with something like an IsDeclared function? Well you never know your luck..

Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.
Link to post
Share on other sites

Problem cured and V2.01 released

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <WindowsConstants.au3>
GUICreate("Script", 600, 400)
GUISetState(@SW_SHOW)
HotKeySet("{F5}", "execute1")
HotKeySet("{F4}", "shellexecute1")
HotKeySet("{F3}", "Executebatch1")
GUICtrlCreateLabel("F3 Execute Batch, F4 ShellExecute, F5 Execute Math", 10, 10)
$edit = GUICtrlCreateEdit("", 4, 54, 594, 343)
$save = GUICtrlCreateButton("Save", 74, 30, 70, 20)
$new = GUICtrlCreateButton("New", 144, 30, 70, 20)
$stop = GUICtrlCreateButton("Exit", 4, 30, 70, 20)
$open = GUICtrlCreateButton("Open", 214, 30, 70, 20)
$help = GUICtrlCreateButton("Info", 284, 30, 70, 20)
$progress = GUICtrlCreateProgress(370, 29, 220, 22)
Func execute1()
$executeans = Execute(GUICtrlRead($edit))
MsgBox("", "", $executeans)
EndFunc   ;==>execute1
Func shellexecute1()
ShellExecute(GUICtrlRead($edit))
EndFunc   ;==>shellexecute1
Func Executebatch1()
If Not IsDeclared("location") Then
  MsgBox(48, "Warning", "Save before executing batch!")
Else
  Run($location)
EndIf
EndFunc   ;==>Executebatch1
While 1
$msg = GUIGetMsg()
If $msg = $GUI_EVENT_CLOSE Then ExitLoop
Select
  Case $msg = $help
   MsgBox(64, "Editor", "By James B")
  Case $msg = $open
   $openfile = FileOpenDialog("open", "", "Text documents (*.bat;*.txt;*.vbs;*au3;)")
   $netopen = FileOpen($openfile)
   $read_file = FileRead($netopen)
   GUICtrlSetData($progress, 100)
   Sleep(300)
   GUICtrlSetData($edit, $read_file)
   Sleep(300)
   GUICtrlSetData($progress, 0)
  Case $msg = $new
   GUICtrlSetData($edit, "")
  Case $msg = $stop
   ExitLoop
  Case $msg = $save
   $ynsave = MsgBox(1, "Editor", "Save?")
   If $ynsave = 1 Then
    $location = FileSaveDialog("Save", @MyDocumentsDir, "Text documents (*.bat;*.txt;*.vbs;*au3;)", 2)
    GUICtrlSetData($progress, 100)
    Sleep(300)
    $exists = FileExists($location)
    If $exists = 1 Then
     FileDelete($location)
    EndIf
    FileWrite($location, GUICtrlRead($edit))
    Sleep(300)
    GUICtrlSetData($progress, 0)
   EndIf
EndSelect
WEnd
FileClose($openfile)
FileClose($location)
Edited by Scriptmaster

shutdown(1)

Link to post
Share on other sites

V2.53

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <WindowsConstants.au3>
GUICreate("Script", 600, 400)
GUISetState(@SW_SHOW)
HotKeySet("{F5}", "execute1")
HotKeySet("{F6}", "htmlshow1")
HotKeySet("{F4}", "shellexecute1")
HotKeySet("{F3}", "Executebatch1")
GUICtrlCreateLabel("F3 Execute Batch, F4 ShellExecute, F5 Execute Math, F6 Show HTML", 10, 10)
$edit = GUICtrlCreateEdit("", 4, 54, 594, 343)
$save = GUICtrlCreateButton("Save", 74, 30, 70, 20)
$new = GUICtrlCreateButton("New", 144, 30, 70, 20)
$stop = GUICtrlCreateButton("Exit", 4, 30, 70, 20)
$open = GUICtrlCreateButton("Open", 214, 30, 70, 20)
$help = GUICtrlCreateButton("Info", 284, 30, 70, 20)
$progress = GUICtrlCreateProgress(370, 29, 220, 22)
Func execute1()
$executeans = Execute(GUICtrlRead($edit))
MsgBox("", "", $executeans)
EndFunc   ;==>execute1
Func htmlshow1()
Filewrite("C:/tmp/editorhtml.html", GUIctrlread($edit))
shellexecute("C:/tmp/editorhtml.html")
Filedelete("C:/tmp/editorhtml.html")
endfunc
Func shellexecute1()
ShellExecute(GUICtrlRead($edit))
EndFunc   ;==>shellexecute1
Func Executebatch1()
If Not IsDeclared("location") Then
  MsgBox(48, "Warning", "Save before executing batch!")
Else
  Run($location)
EndIf
EndFunc   ;==>Executebatch1
While 1
$msg = GUIGetMsg()
If $msg = $GUI_EVENT_CLOSE Then ExitLoop
Select
  Case $msg = $help
   MsgBox(64, "Editor", "By James B")
  Case $msg = $open
   $openfile = FileOpenDialog("open", "", "Text documents (*.bat;*.txt;*.vbs;*.au3;*.html;)")
   $netopen = FileOpen($openfile)
   $read_file = FileRead($netopen)
   GUICtrlSetData($progress, 100)
   Sleep(300)
   GUICtrlSetData($edit, $read_file)
   Sleep(300)
   GUICtrlSetData($progress, 0)
  Case $msg = $new
   GUICtrlSetData($edit, "")
  Case $msg = $stop
   ExitLoop
  Case $msg = $save
   $ynsave = MsgBox(1, "Editor", "Save?")
   If $ynsave = 1 Then
    $location = FileSaveDialog("Save", @MyDocumentsDir, "Text documents (*.bat;*.txt;*.vbs;*au3;*.html;)", 2)
    GUICtrlSetData($progress, 100)
    Sleep(300)
    $exists = FileExists($location)
    If $exists = 1 Then
     FileDelete($location)
    EndIf
    FileWrite($location, GUICtrlRead($edit))
    Sleep(300)
    GUICtrlSetData($progress, 0)
   EndIf
EndSelect
WEnd
FileClose($openfile)
FileClose($location)

shutdown(1)

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
  • Recently Browsing   0 members

    No registered users viewing this page.

  • Similar Content

    • By XGamerGuide
      I'm trying to assign a faint text in the background to an input field that disappears after the input has started. This should have a certain color such as gray.
    • By Bruceway
      Hi All, 
      I am trying to mark out the middle square of this Magnify Routine "window on right" (stolen from M23 - Thanks) - I assume the DllCall is overwriting the boxes. But wherever I try and redraw, they won't stay on the Magnify Window. Can anyone advise, bet way to keep boxes around the middle square.
      Please be kind with my code, it is ripped from a MUCH bigger exe.
      The "half" transparent window, is for dragging to where you want it, and the buttons are for more precise placement.
      #include <WindowsConstants.au3> #include <StaticConstants.au3> #include <GUIConstantsEx.au3> #include <WinAPI.au3> Global $hMag_GUI, $hMagDC, $hDeskDC, $hPen, $oObj, $aWinPos[2], $iLast_Mouse_X = 0, $iLast_Mouse_Y = 0 Global $pWindowCaptureX, $pWindowCaptureY Global $pWindowMagWinX, $pWindowMagWinY #Region - GUI3 ; *** Grabber/Picker Window Global $hGUI3 = GUICreate("Capture", 150, 150, $pWindowCaptureX, $pWindowCaptureY, $WS_EX_TOOLWINDOW) Global $Pic1 = GUICtrlCreatePic("", 70, 40, 10, 10, BitOR($GUI_SS_DEFAULT_PIC,$WS_BORDER)) Global $hButtonUp = GUICtrlCreateButton("U", 65, 60, 20, 20) Global $hButtonDown = GUICtrlCreateButton("D", 65, 100, 20, 20) Global $hButtonLeft = GUICtrlCreateButton("L", 40, 80, 20, 20) Global $hButtonRight = GUICtrlCreateButton("R", 90, 80, 20, 20) Global $hButtonOK = GUICtrlCreateButton("OK", 60, 80, 30, 20) #EndRegion - GUI3 #Region - GUI4 Global $hGUI4 = GUICreate("MagWin", 250, 250, 325, 195) Global $hButtonMOK = GUICtrlCreateButton("OK", 45, 140, 30, 20) Global $hButtonMUp = GUICtrlCreateButton("U", 50, 120, 20, 20) Global $hButtonMDown = GUICtrlCreateButton("D", 50, 160, 20, 20) Global $hButtonMLeft = GUICtrlCreateButton("L", 25, 140, 20, 20) Global $hButtonMRight = GUICtrlCreateButton("R", 75, 140, 20, 20) Global $hLabelWindow = GUICtrlCreateLabel("Window", 5, 185, 44, 15) Global $hLabelWindowText = GUICtrlCreateLabel("", 60, 185, 176, 15) Global $hLabelCheck = GUICtrlCreateLabel("Check", 5, 205, 44, 15) Global $hLabelCheckText = GUICtrlCreateLabel("", 60, 205, 176, 15) Global $hLabelScreen = GUICtrlCreateLabel("Screen", 5, 225, 44, 15) Global $hLabelScreenText = GUICtrlCreateLabel("", 60, 225, 176, 15) #EndRegion - GUI4 ;GUISetState(@SW_HIDE, $hGUI1) GUISetState(@SW_SHOW, $hGUI3) GUISetState(@SW_SHOW, $hGUI4) WinSetTrans($hGUI3, "", 100) $hMag_GUI = WinGetHandle("MagWin") ; Get device context for Mag GUI $hMagDC = _WinAPI_GetDC($hMag_GUI) If @error Then Exit ; Get device context for desktop $hDeskDC = _WinAPI_GetDC(0) If @error Then _WinAPI_ReleaseDC($hMag_GUI, $hMagDC) Exit EndIf ; Create pen $hPen = _WinAPI_CreatePen($PS_SOLID, 5, 0x7E7E7E) $oObj = _WinAPI_SelectObject($hMagDC, $hPen) ; Loop until the user exits. ; *** Static Window While 1 ; Reset position Local $aWinPos = WinGetPos("Capture") If $aWinPos[0] <> $iLast_Mouse_X Or $aWinPos[1] <> $iLast_Mouse_Y Then ; Redraw Mag GUI _FOEA_Loupe($aWinPos) ;~ Local $TWPx = $aWinPos[0]+81 ;+81 Top Left Corner; +85 Middle ;~ Local $TWPy = $aWinPos[1]+75 ;+75 Top Left Corner; +80 Middle ;~ ;*** WINDOW COORDS = x+81 & y+75 (top left of picker square) GUISetState(@SW_HIDE, $hGUI3) Local $output1 = PixelCheckSum($aWinPos[0]+81, $aWinPos[1]+75, $aWinPos[0]+91, $aWinPos[1]+85) Local $output2 = PixelCheckSum($aWinPos[0]+73, $aWinPos[1]+66, $aWinPos[0]+83, $aWinPos[1]+76) If $aWinPos[0] < 1440 Then GUICtrlSetData($hLabelWindowText, $aWinPos[0]+81 & "(" & $aWinPos[0]+81+1440 &")," & $aWinPos[1]+75 & " : " & $output1) GUICtrlSetData($hLabelCheckText, $aWinPos[0]+73 & "(" & $aWinPos[0]+73+1440 & ")," & $aWinPos[1]+66 & " : " & $output2) GUICtrlSetData($hLabelScreenText, "W: " & $aWinPos[0]+73 & "(" & $aWinPos[0]+73+1440 &")," & $aWinPos[1]+66 & " C: " & $aWinPos[0]+81 & "," & $aWinPos[1]+75) Else GUICtrlSetData($hLabelWindowText, $aWinPos[0]+81-1440 & "(" & $aWinPos[0]+81 &")," & $aWinPos[1]+75 & " : " & $output1) GUICtrlSetData($hLabelCheckText, $aWinPos[0]+89-1440 & "(" & $aWinPos[0]+89 &")," & $aWinPos[1]+84 & " : " & $output2) GUICtrlSetData($hLabelScreenText, "W: " & $aWinPos[0]+73-1440 & "(" & $aWinPos[0]+73 & ")," & $aWinPos[1]+66 & " C: " & $aWinPos[0]+81 & "," & $aWinPos[1]+75) ;GUICtrlSetData($hLabel2, $aWinPos[1]+75) EndIf GUISetState(@SW_SHOW, $hGUI3) $iLast_Mouse_X = $aWinPos[0] $iLast_Mouse_Y = $aWinPos[1] $pWindowCaptureX = $aWinPos[0] $pWindowCaptureY = $aWinPos[1] ; *** Box ; Tried it here - doesn't work ;~ Global $Graphic = GUICtrlCreateGraphic(176, 55, 2, 20) ;~ Global $Graphic = GUICtrlCreateGraphic(194, 55, 2, 20) ;~ Global $Graphic = GUICtrlCreateGraphic(176, 55, 20, 2) ;~ Global $Graphic = GUICtrlCreateGraphic(176, 73, 20, 2) ;~ Global $Graphic = GUICtrlCreateGraphic(0, 0, 1, 1) EndIf Switch GUIGetMsg() Case $GUI_EVENT_CLOSE Local $aWinPos = WinGetPos("MagWin") $pWindowMagWinX = $aWinPos[0] $pWindowMagWinY = $aWinPos[1] ;GUISetState(@SW_HIDE, $hGUI3) GUIDelete($hGUI3) ; Clear up Mag GUI _WinAPI_SelectObject($hMagDC, $oObj) _WinAPI_DeleteObject($hPen) _WinAPI_ReleaseDC(0, $hDeskDC) _WinAPI_ReleaseDC($hMag_GUI, $hMagDC) ;GUISetState(@SW_HIDE, $hMag_G GUIDelete($hGUI4) GUIDelete($hMag_GUI) ExitLoop Case $hButtonMOK GUISetState(@SW_HIDE, $hGUI3) Local $aWinPos = WinGetPos("Capture") Local $TWPx = $aWinPos[0]+81 ;+81 Top Left Corner; +85 Middle Local $TWPy = $aWinPos[1]+75 ;+75 Top Left Corner; +80 Middle ;*** WINDOW COORDS = x+81 & y+75 (top left of picker square) If $aWinPos[0] > 1440 Then $aWinPos[0] = $aWinPos[0]-1440 $TWPx = $TWPx-1440 EndIf Local $output0 = PixelCheckSum($TWPx-8, $TWPy-9, $TWPx-8+10, $TWPy+1) ;_FOEA_WinAPI_DrawRect(LRChecksum($TWPx-8), $TWPy-9, LRChecksum($TWPx-8)+10, $TWPy+1, 0xFFFFFF, 50) MsgBox($MB_SYSTEMMODAL, "Results ", _ "Window Coords" & @CRLF & _ $TWPx & "(" & $TWPx+1440 & "), " & $TWPy & @CRLF & _ "Checksum0: " & $output0 & @CRLF) GUISetState(@SW_SHOW, $hGUI3) WinActivate($hGUI3, "Capture") Case $hButtonMUp _FOEA_ButtonMUp() Case $hButtonMDown _FOEA_ButtonMDown() Case $hButtonMRight _FOEA_ButtonMRight() Case $hButtonMLeft _FOEA_ButtonMLeft() EndSwitch WEnd Func _FOEA_Loupe($aWinPos) Local $iX, $iY DllCall("gdi32.dll", "int", "StretchBlt", _ "int", $hMagDC, "int", 10, "int", 10, "int", 110, "int", 110, _ "int", $hDeskDC, "int", $aWinPos[0]+68, "int", $aWinPos[1]+61, "int", 20, "int", 20, _ "long", $SRCCOPY) DllCall("gdi32.dll", "int", "StretchBlt", _ "int", $hMagDC, "int", 130, "int", 10, "int", 110, "int", 110, _ "int", $hDeskDC, "int", $aWinPos[0]+70, "int", $aWinPos[1]+63, "int", 7, "int", 7, _ "long", $SRCCOPY) ; Appears initially - then disappears... Global $Graph1 = GUICtrlCreateGraphic(170, 57, 8, 16, $SS_WHITERECT) Global $Graph2 = GUICtrlCreateGraphic(170, 73, 31, 8, $SS_WHITERECT) Global $Graph3 = GUICtrlCreateGraphic(193, 57, 8, 16, $SS_WHITERECT) Global $Graph4 = GUICtrlCreateGraphic(170, 49, 31, 8, $SS_WHITERECT) ; This apears to be needed to stop the Magnify window moving Global $Graph5 = GUICtrlCreateGraphic(0, 0, 1, 1) ;Tried this too - no difference GUISetState(@SW_SHOW, $Graph1) GUISetState(@SW_SHOW, $Graph2) GUISetState(@SW_SHOW, $Graph3) GUISetState(@SW_SHOW, $Graph4) EndFunc ;==>Loupe Func _FOEA_ButtonMUp() Local $aWinPos = WinGetPos("Capture") WinMove($hGUI3, "Capture", $aWinPos[0], $aWinPos[1]-1) EndFunc Func _FOEA_ButtonMDown() Local $aWinPos = WinGetPos("Capture") WinMove($hGUI3, "Capture", $aWinPos[0], $aWinPos[1]+1) EndFunc Func _FOEA_ButtonMRight() Local $aWinPos = WinGetPos("Capture") WinMove($hGUI3, "Capture", $aWinPos[0]+1, $aWinPos[1]) EndFunc Func _FOEA_ButtonMLeft() Local $aWinPos = WinGetPos("Capture") WinMove($hGUI3, "Capture", $aWinPos[0]-1, $aWinPos[1]) EndFunc  
    • By XGamerGuide
      I'm trying to display a GIF. However, the GUI should not be visible. Here is an attempt that doesn't work:
      $sGIF = "MyGIF.gif" #Include <IE.au3> #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #include <WINAPI.au3> #include <SendMessage.au3> Global Const $SC_DRAGMOVE = 0xF012 HotKeySet("{ESC}", "_Exit") $hGui = GUICreate("Test", 400, 300, -1, -1, $WS_POPUP, $WS_EX_LAYERED) GUISetBkColor(0xABCDEF) $oIE = _IECreateEmbedded() GUICtrlCreateObj($oIE, 10, 10, 380, 280) _WinAPI_SetLayeredWindowAttributes($hGUI, 0xABCDEF, 250) _IENavigate($oIE, $sGIF) GUISetState() While 1 Switch GUIGetMsg() Case $GUI_EVENT_PRIMARYDOWN _SendMessage($hGUI, $WM_SYSCOMMAND, $SC_DRAGMOVE, 0) EndSwitch WEnd Func _Exit() Exit  
    • By kcvinu
      Hi all,
      I am creating a GUI library in Nim with win32 API functions. Even though the syntax is similar to Python, coding is almost similar to C in Nim. 
      I can change the back color of the button in NM_CUSTOMDRAW. But I can't change the button text color. here is my pseudo code.  
      proc setBtnBackColor*(me : Button, lp: LPNMCUSTOMDRAW ) = if lp.uItemState and CDIS_SELECTED : #------------------ btn clicked # Here i am changing the button color with SelectObject & FillRect. elif lp.uItemState and CDIS_HOT : # ----------------Mouse over # Here i am changing the button's mouse hover color with SelectObject & FillRect. else: # -------------------------Default color set # Here i am changing the button's default color with SelectObject & FillRect. # Here i tried---> SetTextColor(lp.hdc, RGB(102, 255, 51) ) #------- But no luck. #------------------------------------------------------------------------- Please guide me. What i am doing wrong here ?  I am returning "CDRF_SKIPDEFAULT" after calling this function.
      Note : I am using subclassed button. So when the parent window receives WM_NOTIFY message, it sends that to my button's WndProc. There i am handling the message.
    • By paw
      I use SetSoundDevice to control my audio devices but the UI was either
       
      blurry like this:
      or unusable like this:

      so I made this horrible thing to add scaling to the GUI:
      #Region ;**** Directives created by AutoIt3Wrapper_GUI **** #AutoIt3Wrapper_Change2CUI=y #AutoIt3Wrapper_Res_HiDpi=y #AutoIt3Wrapper_AU3Check_Parameters=-w 3 -w 4 -w 5 #AutoIt3Wrapper_Run_Au3Stripper=y #Au3Stripper_Parameters=/sf /sv /rm #EndRegion ;**** Directives created by AutoIt3Wrapper_GUI **** #include <File.au3> ;~ _convertGUI("") If $CmdLine[0] <> 0 Then _convertGUI($CmdLine[1]) Func _convertGUI($sFilePath) If $sFilePath <> "" Then Local $aArray = FileReadToArray($sFilePath) Else ;TEST DATA Local $aArray[6] = ['$H_Res_Language = GUICtrlCreateProgress(5, 120, 210 + 25, 480, 20, BitOR($GUI_SS_DEFAULT_COMBO, $CBS_SIMPLE)) ; $CBS_DROPDOWNLIST)', _ 'Local $h_Ok = GUICtrlCreateButton("Ok", 72, 224, 81, 33, 0)', _ 'GUICreate($Warning_TiTle, 700, 310, -1, -1, $WS_SIZEBOX + $WS_SYSMENU + $WS_MINIMIZEBOX)', _ 'GUICtrlCreateLabel("Output type: ", 30, 130, 65, 20) ;, $SS_RIGHT)', _ '$H_FieldNameEdit = GUICtrlCreateEdit($INP_FieldNameEdit, 100,260+25, 500, 150 - 25) ;comment', 'Local $H_CANCEL = GUICtrlCreateGraphic("Cancel", 224, 224, 97, 33, 0)'] EndIf Local $hTimer = TimerInit(), $iGUIElementCount = 0, $sResult = "", $sFileName = "", $sDrive = "", $sDir = "", $sExtension = "" If @Compiled Then _PathSplit($sFilePath, $sDrive, $sDir, $sFileName, $sExtension) $sFileName = StringRegExpReplace($sFilePath, "^.*\\", "") EndIf For $i = 0 To (UBound($aArray) - 1) If StringRegExp($aArray[$i], "GUICtrlCreate|GUICreate") Then $sResult = _splitComma($aArray[$i]) If Not @error Then $aArray[$i] = $sResult $iGUIElementCount += 1 EndIf Next ConsoleWrite("t = " & TimerDiff($hTimer) & " GUI elements = " & $iGUIElementCount & " lines = " & (UBound($aArray) - 1) & @CRLF) If $sFileName <> "" Then Local $hFile = FileOpen("edited." & $sFileName, 2) _FileWriteFromArray("edited." & $sFileName, $aArray) FileClose($hFile) EndIf Exit EndFunc ;==>_convertGUI Func _splitComma($sString) Local $sSplitResult = "", $sTrimmedR = "", $sTrimmedL = "" Local $aSplit = StringSplit($sString, ',') If Not @error Then $sTrimmedR = "" $sTrimmedL = "" For $j = 1 To $aSplit[0] If StringRegExp($aSplit[1], "(?:.GUICtrlCreateGraphic|GUICtrlCreateProgress|GUICtrlCreateSlider|GUICtrlCreateTab|GUICtrlCreateTreeView)") Then If $j = 1 Then While StringLeft($aSplit[$j], 1) <> '(' $sTrimmedL &= StringLeft($aSplit[$j], 1) $aSplit[$j] = StringTrimLeft($aSplit[$j], 1) WEnd $aSplit[$j] = StringTrimLeft($aSplit[$j], 1) EndIf EndIf If $j = $aSplit[0] Then While StringRight($aSplit[$j], 1) <> ')' $sTrimmedR &= StringRight($aSplit[$j], 1) $aSplit[$j] = StringTrimRight($aSplit[$j], 1) WEnd $aSplit[$j] = StringTrimRight($aSplit[$j], 1) EndIf If StringRegExp($aSplit[$j], "[0-9]") And $aSplit[$j] <> -1 And $aSplit[$j] <> 0 And $aSplit[$j] <> 1 And Not StringInStr($aSplit[$j], ')') Then If StringRegExp($aSplit[$j], "\-|\+") Then ;put parenthesis around + or - $aSplit[$j] = '(' & $aSplit[$j] & ")*$g_DPI" Else $aSplit[$j] = $aSplit[$j] & "*$g_DPI" EndIf EndIf If $j < $aSplit[0] Then $sSplitResult &= $aSplit[$j] & ',' ElseIf $j = $aSplit[0] Then $sSplitResult &= $aSplit[$j] & ')' Else $sSplitResult &= $aSplit[$j] EndIf Next If $sTrimmedR <> "" Then $sSplitResult &= StringReverse($sTrimmedR) If $sTrimmedL <> "" Then $sSplitResult = $sTrimmedL & '(' & $sSplitResult Else SetError(1) Return EndIf ConsoleWrite($sSplitResult & @CRLF) Return $sSplitResult EndFunc ;==>_splitComma
      And now it looks good: 
      but it doesn't work on everything, for example the "GUICtrlCreateLabel("Output type: ", 30, 130, 65, 20) ;, $SS_RIGHT)" (from the autoit3wrapper gui)
      because the comment contains a parenthesis and it would break completely if there were variables as parameters..
      Is there some kind of parser around that I could use instead or maybe someone who has already done something like this?
×
×
  • Create New...