Sign in to follow this  
Followers 0

Image review tool

3 posts in this topic

#1 ·  Posted (edited)

Hi there..

I want to work on a image review tool. The basic idea of this tool is to review some GUI applications (developed in any language) and give comments to the developer with reference to the part of the GUI, I am making comment on. The final report with comments needs to be in MS Excel.

My idea is first run the application under review and get the GUI. Then using AutoIT place a transperant layer over it (could be on whole of the desktop size also) then mark a rectangle with a cross mouse icon on interested area, get the image of that area from the GUI beneath the transparent layer. After that get a text box or something where I can put down my comment about the croped area. Finally save those comments and croped images in excel file.

My questions are:

1. Is it possible to get a transparent layer over the GUI using Autoit?

2. Where to find some examples to start with?

3. How do I get the marked image from the desktop?

Thanks in advance

Edited by BlackEvil

Share this post

Link to post
Share on other sites


Something I had in my Snippets folder: ;)

#include <GuiConstantsEx.au3>
#include <WindowsConstants.au3>
#Include <ScreenCapture.au3>
#Include <Misc.au3>

Global $iX1, $iY1, $iX2, $iY2, $aPos, $sMsg, $sBMP_Path

; Create GUI
$hMain_GUI = GUICreate("Select Rectangle", 240, 50)

$hRect_Button   = GUICtrlCreateButton("Mark Area",  10, 10, 80, 30)
$hCancel_Button = GUICtrlCreateButton("Cancel",    150, 10, 80, 30)


While 1

    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE, $hCancel_Button
            FileDelete(@ScriptDir & "Rect.bmp")
        Case $hRect_Button
            GUISetState(@SW_HIDE, $hMain_GUI)
            ; Capture selected area
            $sBMP_Path = @ScriptDir & "Rect.bmp"
            _ScreenCapture_Capture($sBMP_Path, $iX1, $iY1, $iX2, $iY2, False)
            GUISetState(@SW_SHOW, $hMain_GUI)
            ; Display image
            $hBitmap_GUI = GUICreate("Selected Rectangle", $iX2 - $iX1 + 1, $iY2 - $iY1 + 1, 100, 100)
            $hPic = GUICtrlCreatePic(@ScriptDir & "Rect.bmp", 0, 0, $iX2 - $iX1 + 1, $iY2 - $iY1 + 1)



; -------------

Func Mark_Rect()

    Local $aMouse_Pos, $hMask, $hMaster_Mask, $iTemp
    Local $UserDLL = DllOpen("user32.dll")

    ; Create transparent GUI with Cross cursor
    $hCross_GUI = GUICreate("Test", @DesktopWidth, @DesktopHeight - 20, 0, 0, $WS_POPUP, $WS_EX_TOPMOST)
    WinSetTrans($hCross_GUI, "", 8)
    GUISetState(@SW_SHOW, $hCross_GUI)
    GUISetCursor(3, 1, $hCross_GUI)

    Global $hRectangle_GUI = GUICreate("", @DesktopWidth, @DesktopHeight, 0, 0, $WS_POPUP, $WS_EX_TOOLWINDOW + $WS_EX_TOPMOST)

    ; Wait until mouse button pressed
    While Not _IsPressed("01", $UserDLL)

    ; Get first mouse position
    $aMouse_Pos = MouseGetPos()
    $iX1 = $aMouse_Pos[0]
    $iY1 = $aMouse_Pos[1]

    ; Draw rectangle while mouse button pressed
    While _IsPressed("01", $UserDLL)

        $aMouse_Pos = MouseGetPos()

        $hMaster_Mask = _WinAPI_CreateRectRgn(0, 0, 0, 0)
        $hMask = _WinAPI_CreateRectRgn($iX1,  $aMouse_Pos[1], $aMouse_Pos[0],  $aMouse_Pos[1] + 1) ; Bottom of rectangle
        _WinAPI_CombineRgn($hMaster_Mask, $hMask, $hMaster_Mask, 2)
        $hMask = _WinAPI_CreateRectRgn($iX1, $iY1, $iX1 + 1, $aMouse_Pos[1]) ; Left of rectangle
        _WinAPI_CombineRgn($hMaster_Mask, $hMask, $hMaster_Mask, 2)
        $hMask = _WinAPI_CreateRectRgn($iX1 + 1, $iY1 + 1, $aMouse_Pos[0], $iY1) ; Top of rectangle
        _WinAPI_CombineRgn($hMaster_Mask, $hMask, $hMaster_Mask, 2)
        $hMask = _WinAPI_CreateRectRgn($aMouse_Pos[0], $iY1, $aMouse_Pos[0] + 1,  $aMouse_Pos[1]) ; Right of rectangle
        _WinAPI_CombineRgn($hMaster_Mask, $hMask, $hMaster_Mask, 2)
        ; Set overall region
        _WinAPI_SetWindowRgn($hRectangle_GUI, $hMaster_Mask)

        If WinGetState($hRectangle_GUI) < 15 Then GUISetState()


    ; Get second mouse position
    $iX2 = $aMouse_Pos[0]
    $iY2 = $aMouse_Pos[1]

    ; Set in correct order if required
    If $iX2 < $iX1 Then
        $iTemp = $iX1
        $iX1 = $iX2
        $iX2 = $iTemp
    If $iY2 < $iY1 Then
        $iTemp = $iY1
        $iY1 = $iY2
        $iY2 = $iTemp


EndFunc   ;==>Mark_Rect

Feel free to use any of it if it helps. :)


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:


ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

Share this post

Link to post
Share on other sites

Wow .. that's pretty fast! :)

Thank you M23! ;)

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

  • Similar Content

    • timmy2
      Trying to display text with a transparent BG atop a Veeblefetzer
      By timmy2
      The following demo script, drawn largely from examples by @UEZ, lets me display colored text over a transparent background using my choice of font, type size, etc.  It is a single function (out of many) in the project I'm scripting, but it is crucial to my goal of displaying messages in an interesting way (IMHO).  
      (For the purpose of this forum post it displays a single string variable; my actual project script reads a number of  possible messages from a text file into an array and then chooses the messages to be displayed based on stuff that happens in the course of someone using my program.)
      Note that I am seeking help only to overcome my inability to figure out how to display this text atop a PNG graphic, and make the result a draggable object.
      #cs Display a message one character at a time with the goal of adding a PNG graphic overlay #ce ;~ #AutoIt3Wrapper_Au3Check_Parameters=-d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6 #include <GDIPlus.au3> #include <GUIConstantsEx.au3> #include <GUIConstants.au3> Global $sMessage Global $iString = 0 Global $aInfo Global Const $SC_DRAGMOVE = 0xF012 HotKeySet("{Esc}","Close") ; in my actual script I read in a file containing all the text to be displayed Global $sText = _ "Lorem ipsum dolor sit amet, consectetur" & @CRLF & _ "elit, sed do eiusmod tempor incididunt ut" & @CRLF & _ @CRLF & _ "Et dolore magna aliqua. Ut enim ad minim," & @CRLF & _ "quis nostrud exercitation ullamco laboris nisi" & @CRLF & _ "aliquip ex ea commodo consequat." & @CRLF & _ @CRLF & _ "Duis aute irure dolor in reprehenderit in" & @CRLF & _ "voluptate velit esse cillum dolore eu fugiat" & @CRLF & _ "nulla pariatur." & @CRLF ; Create GUI Global $hGUI = GUICreate("", 450, 340, -1, -1, $WS_POPUP, BitOR($WS_EX_LAYERED, $WS_EX_TOPMOST)) GUISetBkColor(0xFF000000) ; will change background color, which UEZ doesn't use in his example, but then he doesn't want a BG GUISetState(@SW_SHOW) ; Draw a string _GDIPlus_Startup() Global $hBrush = _GDIPlus_BrushCreateSolid(0xFF99ff33) Global $hFormat = _GDIPlus_StringFormatCreate() Global $hFamily = _GDIPlus_FontFamilyCreate("VT323") Global $hFont = _GDIPlus_FontCreate($hFamily, 14, 0) Global $tLayout = _GDIPlus_RectFCreate(20, 20, 0, 0) Global $hGraphic = _GDIPlus_GraphicsCreateFromHWND($hGUI) Global $hBitmap = _GDIPlus_BitmapCreateFromScan0(420, 300) Global $hBuffer = _GDIPlus_ImageGetGraphicsContext($hBitmap) _GDIPlus_GraphicsSetTextRenderingHint($hBuffer, 4) _GDIPlus_GraphicsSetSmoothingMode($hBuffer, 4) GUIRegisterMsg($WM_LBUTTONDOWN, "_WM_LBUTTONDOWN") For $iString = 1 to StringLen($sText) $sMessage = StringLeft($sText,$iString) $aInfo = _GDIPlus_GraphicsMeasureString($hGraphic, $sMessage, $hFont, $tLayout, $hFormat) _GDIPlus_GraphicsClear($hBuffer, 0x000000) _GDIPlus_GraphicsDrawStringEx($hBuffer, $sMessage, $hFont, $aInfo[0], $hFormat, $hBrush) $hHBitmap = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hBitmap) _WinAPI_BitmapDisplayTransparentInGUI($hHBitmap, $hGUI) _WinAPI_DeleteObject($hHBitmap) Next Do Until GUIGetMsg() = $GUI_EVENT_CLOSE Close() ; Clean up resources (my best guess at what needs closing/shutting down) Func Close() _GDIPlus_FontDispose($hFont) _GDIPlus_FontFamilyDispose($hFamily) _GDIPlus_StringFormatDispose($hFormat) _GDIPlus_BrushDispose($hBrush) _GDIPlus_GraphicsDispose($hGraphic) _GDIPlus_ImageDispose($hBitmap) _GDIPlus_Shutdown() Exit EndFunc ;==>Close Func _WinAPI_BitmapDisplayTransparentInGUI(ByRef $hHBitmap, ByRef $hGUI, $iOpacity = 0xFF, $bReleaseGDI = True) If Not BitAND(GUIGetStyle($hGUI)[1], $WS_EX_LAYERED) = $WS_EX_LAYERED Then Return SetError(1, 0, 0) Local $tDim = DllStructCreate($tagBITMAP) If Not _WinAPI_GetObject($hHBitmap, DllStructGetSize($tDim), DllStructGetPtr($tDim)) Then Return SetError(2, 0, 0) Local $tSize = DllStructCreate($tagSIZE), $tSource = DllStructCreate($tagPOINT), $tBlend = DllStructCreate($tagBLENDFUNCTION) Local Const $hScrDC = _WinAPI_GetDC(0), $hMemDC = _WinAPI_CreateCompatibleDC($hScrDC), $hOld = _WinAPI_SelectObject($hMemDC, $hHBitmap) $tSize.X = $tDim.bmWidth $tSize.Y = $tDim.bmHeight $tBlend.Alpha = $iOpacity $tBlend.Format = 1 _WinAPI_UpdateLayeredWindow($hGUI, $hScrDC, 0, DllStructGetPtr($tSize), $hMemDC, DllStructGetPtr($tSource), 0, DllStructGetPtr($tBlend), $ULW_ALPHA) _WinAPI_ReleaseDC(0, $hScrDC) _WinAPI_SelectObject($hMemDC, $hOld) _WinAPI_DeleteDC($hMemDC) If $bReleaseGDI Then _WinAPI_DeleteObject($hHBitmap) Return True EndFunc Func _WM_LBUTTONDOWN($hWnd, $iMsg, $wParam, $lParam) Switch $hWnd Case $hGUI _SendMessage($hWnd, $WM_SYSCOMMAND, $SC_DRAGMOVE, 0) EndSwitch EndFunc ;==>_WM_LBUTTONDOWN  
      The above script lets me push the text out to the screen, but I want to display the text atop a PNG graphic, which is an imagined piece of hand-held test equipment that I'll refer to here as the Veeblefetzer.
      Here's a half-size animated gif of the desired result.

      Note that initially I used a different script to stream the text out atop a built-in black background rectangle.  I figured I would place the Veeblefetzer graphic above the text -- with the center "display area" of the Veeblefetzer cut out (transparent).  
      Then UEZ's example script came along. The benefit of using text that has a transparent BG, and placing it in a layer above the Veeblefetzer, is this lets me include reflections in the Veeblefetzer's display.
      Now to the challenges I'm ill-equipped to figure out.  
      The function I use to display the Veeblefetzer is below. It, too, is drawn from some of examples by @UEZ.
      There are actually two functions below, one I use to display the PNG graphic, and one that can be used to fade the graphic in or out.  I include it here only because it might be applicable to my ancillary goal of needing to clear the text on the handheld display before streaming the next message onto the Veeblefetzer's display.  I realize that the fade in/out function is for graphic objects, so it may not be applicable to text. 
      ; Display the image at center unless otherwise specified. If Fader will not be used then $iAlpha's default of 0xFF is good. ; If Fader will be used then start with $iAlpha equal to zero. Option to make this image "Always on top" is also available. Func DisplayImage($sFile, $iPosX = -1, $iPosY = -1, $iAlpha = 0xFF, $bTopmost = True) Local Const $hBmp_Background = _GDIPlus_BitmapCreateFromFile($sFile) ;load the image If @error Then Return SetError(1, 0, 0) ;image cannot be loaded Local Const $iW = _GDIPlus_ImageGetWidth($hBmp_Background), $iH = _GDIPlus_ImageGetHeight($hBmp_Background) ;get the dimension of the background image Local Const $hGUI = GUICreate("", $iW, $iH, $iPosX, $iPosY, $WS_POPUP, BitOR($WS_EX_LAYERED, $WS_EX_TOPMOST * $bTopmost, $WS_EX_TOOLWINDOW)) ;create GUI with appropriate styles and extented style (borderless transparent GUI) GUICtrlCreateLabel("", 0, 0, $iW, $iH, Default, $GUI_WS_EX_PARENTDRAG) ;create a hidden label for GUI dragging GUISetState(@SW_SHOW, $hGUI) ;show GUI Local Const $hBitmap = _GDIPlus_BitmapCreateFromScan0($iW, $iH) ;define an empty bitmap where all the gfx stuff will copied to Local Const $hGfx = _GDIPlus_ImageGetGraphicsContext($hBitmap) ;get the context to the bitmap to be able to copy / draw to the bitmap _GDIPlus_GraphicsDrawImageRect($hGfx, $hBmp_Background, 0, 0, $iW, $iH) ;draw background image to the empty bitmap ;display GDI+ with transparency on desktop Local Const $hHBitmap = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hBitmap) ;convert GDI+ image to GDI to display it on the screen using GDI functions Local Const $hScrDC = _WinAPI_GetDC($hGUI) ;get the device context (dc) handle of the GUI Local Const $hMemDC = _WinAPI_CreateCompatibleDC($hScrDC) ;create a compatible dc handle Local Const $hOld = _WinAPI_SelectObject($hMemDC, $hHBitmap) ;selects the GDI bitmap object into the specified device context Local Const $tSize = DllStructCreate($tagSIZE) ;create a $tagSIZE struct (x = width, y = height) DllStructSetData($tSize, "X", $iW) ;set data for width DllStructSetData($tSize, "Y", $iH) ;set data for height Local $tSource = DllStructCreate($tagPOINT) ;create a $tagPOINT struct (x = x position, y = y position) Local $tBlend = DllStructCreate($tagBLENDFUNCTION) ;create $tagBLENDFUNCTION struct -> see help file for more info DllStructSetData($tBlend, "Alpha", $iAlpha) ;set the alpha channel of the GUI -> 255 = opaque, 0 = transparent DllStructSetData($tBlend, "Format", 1) ;set the format to 1 -> bitmap has alpha channels DllCall("user32.dll", "bool", "UpdateLayeredWindow", "hwnd", $hGUI, "handle", $hScrDC, "ptr", 0, "struct*", $tSize, "handle", $hMemDC, "struct*", $tSource, "dword", 0, "struct*", $tBlend, "dword", $ULW_ALPHA) ;display bitmap on screen ;release resources otherwise memory will filled up (memory leak) _GDIPlus_GraphicsDispose($hGfx) _GDIPlus_BitmapDispose($hBitmap) Local $aResource[7] = [$hGUI, _ ;GUI handle $hScrDC, _ ;device context (dc) handle of the GUI (GDI) $hHBitmap, _ ;GDI bitmap handle of the displayed image $hMemDC, _ ;compatible dc handle from $hScrDC $tBlend, _ ;tBlend struct (source blend oper., flags, alpha value, format) -> see help file for description $tSize, _ ;tSize struct (width and height of the window / image) $tSource] ;tSource struct for x / y position of the GUI Return $aResource ;returns the handles to release it later or to use it for fading effects EndFunc ;==>DisplayImage ; This function releases the resources of a specific image and closes it Func ReleaseResources(ByRef $aResource) If Not IsArray($aResource) Then Return SetError(1, 0, 0) If UBound($aResource) <> 7 Then Return SetError(2, 0, 0) _WinAPI_ReleaseDC($aResource[0], $aResource[1]) _WinAPI_DeleteDC($aResource[3]) _WinAPI_DeleteObject($aResource[2]) GUIDelete($aResource[0]) EndFunc ;==>ReleaseResources ; To fade in an image leave $bIn at default (True); to fade out specify False. ; There are also options to set the ending transparency level (0 transparent, 255 opaque), speed and delay. ; If you change the speed or delay be sure to specify $bIn and $iTrans, otherwise you'll wonder why the fade-in or out isn't what you hoped for. ; The default values are specified in the function below. Func _Fader($res1, $bIn = True, $iTrans = 255, $speed = 3, $delay = 10 ) If Not IsArray($res1) Then Return SetError(1, 0, 0) If UBound($res1) <> 7 Then Return SetError(2, 0, 0) Switch $bIn Case True For $a = 0 To $iTrans Step $speed DllStructSetData($res1[4], "Alpha", $a) DllCall("user32.dll", "bool", "UpdateLayeredWindow", "hwnd", $res1[0], "handle", $res1[1], "ptr", 0, "struct*", $res1[5], "handle", $res1[3], "struct*", $res1[6], "dword", 0, "struct*", $res1[4], "dword", $ULW_ALPHA) ;display bitmap on screen Sleep($delay) Next Case Else For $a = $iTrans To 0 Step -$speed DllStructSetData($res1[4], "Alpha", $a) DllCall("user32.dll", "bool", "UpdateLayeredWindow", "hwnd", $res1[0], "handle", $res1[1], "ptr", 0, "struct*", $res1[5], "handle", $res1[3], "struct*", $res1[6], "dword", 0, "struct*", $res1[4], "dword", $ULW_ALPHA) ;display bitmap on screen Sleep($delay) Next EndSwitch EndFunc ;==>_FadeIn  
      Is anyone willing to step in and show me how to use the text display function along with the PNG display function, so that the resulting Veeblefetzer will be a single draggable object on screen?
      I'm equally baffled about how to properly clear off one message before displaying the next.
      The reason?   I have only the most rudimentary grasp of the commands within -- or the relationships between -- what seem like three distinct sections common to each of UEZ's scripts:
      Initialization (which defines a number of attributes, some of which are obvious to me, for text in this case)
      _GDIPlus_Startup() Global $hBrush = _GDIPlus_BrushCreateSolid(0xFF99ff33) Global $hFormat = _GDIPlus_StringFormatCreate() Global $hFamily = _GDIPlus_FontFamilyCreate("VT323") Global $hFont = _GDIPlus_FontCreate($hFamily, 14, 0) Global $tLayout = _GDIPlus_RectFCreate(20, 20, 0, 0) Global $hGraphic = _GDIPlus_GraphicsCreateFromHWND($hGUI) Global $hBitmap = _GDIPlus_BitmapCreateFromScan0(420, 300) Global $hBuffer = _GDIPlus_ImageGetGraphicsContext($hBitmap) _GDIPlus_GraphicsSetTextRenderingHint($hBuffer, 4) _GDIPlus_GraphicsSetSmoothingMode($hBuffer, 4)  
      Delivery... (apparently what's needed to display the text)
      $aInfo = _GDIPlus_GraphicsMeasureString($hGraphic, $sMessage, $hFont, $tLayout, $hFormat) _GDIPlus_GraphicsClear($hBuffer, 0x000000) _GDIPlus_GraphicsDrawStringEx($hBuffer, $sMessage, $hFont, $aInfo[0], $hFormat, $hBrush) $hHBitmap = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hBitmap) _WinAPI_BitmapDisplayTransparentInGUI($hHBitmap, $hGUI) _WinAPI_DeleteObject($hHBitmap) Even at my primitive level of understanding I have figured out that you can reuse the above "delivery" section to display other strings before proceeding to the next section.
      Cleanup... (apparently needed to release resources, which to me is like closing a previously opened file: it's part of the process so I'll do it):
      _GDIPlus_FontDispose($hFont) _GDIPlus_FontFamilyDispose($hFamily) _GDIPlus_StringFormatDispose($hFormat) _GDIPlus_BrushDispose($hBrush) _GDIPlus_GraphicsDispose($hGraphic) _GDIPlus_ImageDispose($hBitmap) _GDIPlus_Shutdown()  
      (You're getting an inside look at a monkey brain at work here!)
      UEZ's script to display the PNG graphic follows a similar pattern. What I cannot figure out is how to merge the two scripts, while avoiding redundancy and conflicts. To clear the text between messages must I release any resources, and if so: which ones? AND, how do I group the PNG graphic with the text so the resulting "object" can be moved around on the screen?
    • czardas
      Row Sum (Σ) Formula Validation
      By czardas
      Much work still needs to be done on my current project, but design concepts often benefit more from early criticism. Although there may be nothing particularly innovative about this project, user experience is everything. I would like you to look at the behaviour of the controls on this GUI. Unless you type something really awful, it allows you to finish typing the formula before testing the input. When typing into an edit control, pressing the enter key activates the okay button.
      The program itself, mainly consists of a listview control, which you can't see - just imagine it looks like a stone age version of Excel with a nice paint job, but no bells or whistles. What Row Sum (Σ) is intended to do is loop through all the rows, calculate a sum and print the output in a newly created column. The user is prompted to type a formula into the following GUI. Please try to figure it out, and break it any way you can.
      #include <GUIConstants.au3> #include <GuiEdit.au3> #include <Misc.au3> Global $g_iAvailableCols = 24 ; arbitary dev variable [column count will eventually be read from a listview control] ; missing several thousand lines of code... Formula() ; caution about including columns containing empty fields in the formula ; empty fields are treated as zero ; with addition and subtraction there is never any problem ; multiplication by an empty field (or by zero) returns zero ; division by an empty field (or by zero) returns an empty field [unless - see exception] ; use of the power operator is limited to rows in which all referenced fields contain numbers ; imaginary roots of negative numbers return an empty field [unless - see exception] ; exception: infinity (or an imaginary number) to the power of zero returns a meaningless number Func FormulaSyntax() MsgBox(BitOR(64, 8192), "Row Sum (" & ChrW(0x03A3) & ") : Syntax To Use", _ ; $MB_ICONINFORMATION, $MB_TASKMODAL " mathematical operators :" & @TAB & "+ - * / ^" & @CRLF & _ " column numbers :" & @TAB & @TAB & "c1, c2, c3 etc..." & @CRLF & _ " decimal digits :" & @TAB & @TAB & "0 to 9 and ." & @CRLF & _ " parenthesis :" & @TAB & @TAB & "( )" & @CRLF & _ " minus sign :" & @TAB & @TAB & "-1, -c2, -(c3) etc..." & @CRLF & _ " example :" & @TAB & @TAB & @TAB & "c1 +c2 -c3") EndFunc ;==> FormulaSyntax Func Formula() ; ($hParent, $idListView, $hListView) ; [missing parent window] Local $sTitle = "Row Sum (" & ChrW(0x03A3) & ")", _ $iStyle = BitOR($WS_CAPTION, $WS_POPUP, $WS_SYSMENU), _ $iExStyle = BitOR($WS_EX_MDICHILD, $WS_EX_TOOLWINDOW, $WS_EX_TOPMOST) Local $hChild = GUICreate($sTitle, 334 +25, 105 +1, Default + 100, Default + 100); , $iStyle, $iExStyle, $hParent) Local $hLabel = GUICtrlCreateLabel("Formula :", 8, 8, 55, 18) GUICtrlSetFont(-1, 10) Local $hSyntax = GUICtrlCreateButton("???", 72, 7, 40, 20) Local $hLabel = GUICtrlCreateLabel("Header :", 127, 8, 49, 18) GUICtrlSetFont(-1, 10) Local $hHeader = GUICtrlCreateInput("", 182, 7, 170, 20) GUICtrlSetFont(-1, 10) Local $hInput = GUICtrlCreateInput("", 7, 33, 320 +25, 40, BitOR($WS_TABSTOP, $ES_MULTILINE)) GUICtrlSetFont(-1, 10) Local $hCheckBox = GUICtrlCreateCheckbox(" Round to", 7, 79, 75, 20) GUICtrlSetFont(-1, 10) Local $hPlaces = GUICtrlCreateInput("2", 86, 79 +1, 20, 20, BitOR($WS_TABSTOP, $ES_CENTER, $ES_NUMBER)) GUICtrlCreateLabel("decimal places", 114 -2, 79 +2, 92, 18) GUICtrlSetFont(-1, 10) Local $hCancel = GUICtrlCreateButton("Cancel", 210, 79 +1, 66, 20) Local $hOkay = GUICtrlCreateButton("OK", 285, 79 +1, 66, 20) GUISetState(@SW_SHOW) Local $sInput = "", $aArray, $iError = 0, $iCols = $g_iAvailableCols ; $iCols = _GUICtrlListView_GetColumnCount($hListView), _ ; >>> CHANGE THIS LATER ;$iRows = _GUICtrlListView_GetItemCount($hListView), $aColOrder = _GUICtrlListView_GetColumnOrderArray($hListView) Local $vTemp, $msg2, $iPlaces = '2' While 1 $msg2 = GUIGetMsg() If $msg2 = $hCancel Or $msg2 = $GUI_EVENT_CLOSE Then ExitLoop If $msg2 = $hSyntax Then FormulaSyntax() ContinueLoop EndIf $vTemp = GUICtrlRead($hPlaces) If $vTemp <> $iPlaces Then If $vTemp > 14 Then GUICtrlSetData($hPlaces, 14) $iPlaces = 14 _GUICtrlEdit_SetSel($hPlaces, 0, -1) ElseIf Not $vTemp Then GUICtrlSetData($hPlaces ,'0') $iPlaces = '0' _GUICtrlEdit_SetSel($hPlaces, 0, -1) EndIf EndIf If BitAND(GUICtrlRead($hCheckBox), $GUI_CHECKED) == $GUI_CHECKED _ And BitAND(GUICtrlGetState($hPlaces), $GUI_DISABLE) == $GUI_DISABLE Then GUICtrlSetState($hPlaces, $GUI_ENABLE) ElseIf BitAND(GUICtrlRead($hCheckBox), $GUI_CHECKED) <> $GUI_CHECKED _ And BitAND(GUICtrlGetState($hPlaces), $GUI_ENABLE) == $GUI_ENABLE Then GUICtrlSetState($hPlaces, $GUI_DISABLE) EndIf $sFormula = GUICtrlRead($hInput) If $sFormula <> $sInput Then If StringRegExp($sFormula, '[^ ]') Then ; spaces between components are ignored If Not ValidSyntax($sFormula, $iCols) Then If @extended < 5 Then If $iError = 0 Then GUICtrlSetBkColor($hInput, 0xFFA090) $iError = 1 ElseIf $iError Then GUICtrlSetBkColor($hInput, 0xFFFFFF) $iError = 0 EndIf ElseIf $iError Then GUICtrlSetBkColor($hInput, 0xFFFFFF) $iError = 0 EndIf ElseIf $iError Then GUICtrlSetBkColor($hInput, 0xFFFFFF) $iError = 0 EndIf $sInput = $sFormula EndIf ; BitAND(WinGetState($hChild), $WIN_STATE_ACTIVE) = 8 If $msg2 = $hOkay Or (_IsPressed("0D") And BitAND(WinGetState($hChild), 8) = 8 And (ControlGetFocus($hChild) = "Edit2" Or ControlGetFocus($hChild) = "Edit1")) Then $sFormula = GUICtrlRead($hInput) ; If StringRegExp($sFormula, '[^ ]') And ValidSyntax($sFormula, $iCols) Then ; missing formula execution code MsgBox(0, "VALID SYNTAX", "Well done, your formula can safely be executed, but" & @CRLF & "can't find parent window.") ExitLoop Else Switch @extended Case 1 $vTemp = "The formula contains illegal characters." Case 2 $vTemp = "No such column exists." Case 3 $vTemp = "The formula contains a syntax error." Case 4 $vTemp = "The formula is missing opening parenthesis." Case 5 $vTemp = "The formula is unterminated" case 6 $vTemp = "The formula is missing closing parenthesis." EndSwitch MsgBox(262160, "uh-uh!", StringRegExp($sFormula, '[^ ]') ? $vTemp : "Please enter a formula.") While _IsPressed("0D") Sleep(50) WEnd ;$iError = 1 EndIf EndIf WEnd GUIDelete($hChild) EndFunc ; formula Func ValidSyntax($sFormula, $iMax) ; [currently requires external check that string <> ""] ; quick test for accepted characters If StringRegExp($sFormula, '(?i)[^c \d\.\+\-\*/\^\(\)]') Then Return SetExtended(1, False) ; illegal characters If StringRegExp($sFormula, '(?i)\.\D|c[0\D]|\d\s+[\.\d]') Then Return SetExtended(3, False) ; syntax $sFormula = StringStripWS($sFormula, 8) ; strip all spaces ; split to separate formula components Local $aFormula = StringRegExp($sFormula, '(?i)\-?c\d+|\-?c|\-?\d*\.\d*|\-?\d+|\-\(|[\+\-\*/\^\(\)]|.+', 3), _ ; create array [ADDED] ==> |.+ $iLast, $sTest, $sExpect = '(?i)\-?\(|\-?c\d+|\-?c|\-?\d*\.\d*|\-?\d+|\-', _ ; valid first component $iBracket = 0, $bSyntax = False, $bNoSuch = False, $bTermination = False ; error tracking variables For $i = 0 To UBound($aFormula) -1 If Not StringRegExp($aFormula[$i], $sExpect) Then ; unexpected code sequence $bSyntax = True ExitLoop EndIf If StringRegExp($aFormula[$i], '(?i)\-?c\d+') Then ; column number $sTest = StringRegExpReplace($aFormula[$i], '(?i)[\-c]+', '') If $sTest > $iMax Or $sTest == 0 Then ; no such column exists $bNoSuch = True ExitLoop EndIf $sExpect = '[\+\-\*/\^\)]' ; operators / closing brackets ElseIf StringRegExp($aFormula[$i], '\-?\d*\.\d*') Then ; decimal If $aFormula[$i] == '.' Or $aFormula[$i] == '-.' Then If $i = UBound($aFormula) -1 Then $bTermination = True ExitLoop EndIf $bSyntax = True ; badly formated decimal ExitLoop EndIf $sExpect = '[\+\-\*/\^\)]' ; as above ElseIf StringRegExp($aFormula[$i], '\-?\d+') Then ; integer $sExpect = '[\+\-\*/\^\)]' ElseIf StringRegExp($aFormula[$i], '\A[\+\-\*/\^]\z') Then ; operator $iLast = UBound($aFormula) -1 If $i = $iLast Or ($i = $iLast -1 And $aFormula[$iLast] == '-') Then $bTermination = True ExitLoop EndIf $sExpect = '(?i)\-?\(|\-?c\d+|\-?c|\-?\d*\.\d*|\-?\d+' ElseIf $aFormula[$i] == '(' Or $aFormula[$i] == '-(' Then ; opening bracket $iBracket += 1 $sExpect = '(?i)\-?\(|\-?c\d+|\-?c|\-?\d*\.\d*|\-?\d+|\-' ElseIf $aFormula[$i] == ')' Then ; closing bracket $iBracket -= 1 $sExpect = '[\+\-\*/\^\)]' ElseIf $aFormula[$i] = 'c' Or $aFormula[$i] = '-c' Then ; unterminated column number If $i = UBound($aFormula) -1 Then $bTermination = True Else $bSyntax = True ExitLoop EndIf Else ; unexpected exception [this should never happen] $bSyntax = True ExitLoop EndIf If $iBracket < 0 Then ExitLoop ; closing (unopened) parenthesis error ; [formula looks okay so far] Next ; better to be a bit wordy [for clarity] If $bNoSuch Then Return SetExtended(2, False) ; no such column exists If $bSyntax Then Return SetExtended(3, False) ; syntax error If $iBracket < 0 Then Return SetExtended(4, False) ; missing opening parenthesis If $bTermination Then Return SetExtended(5, False) ; formula may not terminate with operator or c If $iBracket > 0 Then Return SetExtended(6, False) ; missing closing parenthesis ; ConsoleWrite('valid' & @LF) Return True ; formula is correct EndFunc ;==> ValidSyntax  
    • david1337
      add/remove from txt file inside GUI
      By david1337
      Hey guys
      I need help to get further with this script
      Test.txt contains lines like this:
      I have managed to view the content of a txt file in the left side of a GUI like this:
      #Include <File.au3> #include <GUIConstants.au3> Global $file = FileRead("Test.txt") GUICreate("", 800, 800, 192, 124) $control = GUICtrlCreateEdit($file, 0, 0, 400, 800, $ES_AUTOVSCROLL + $WS_VSCROLL + $ES_READONLY) GUICtrlSetFont(-1, 14, 400, 0, "@Arial Unicode MS") GUICtrlSetBkColor(-1, 0xFFFFFF) GUICtrlSetState($control, $GUI_FOCUS) ;Makes sure that text is not highlighted by default GUISetState(@SW_SHOW) While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit EndSwitch WEnd  
      Okay so is it possible to make each line become a clickable item?
      Say I want to delete Line2, then I highlight it and click a "remove" button.
      Also an "add" button would be needed to add new lines
      On Case $GUI_EVENT_CLOSE the changes should be saved to Test.txt (Or with a save button)
      Is this possible?
      I hope you can help me :-)

    • Morthawt
      Utilising existing GUI code in koda.
      By Morthawt
      I have a program I made long ago for something but I never saved the koda file so it would make it a complete pain for me to visually tweak anything because as far as I am aware, I would have to design an entirely new GUI.
      Would it be possible for you guys at AutoIt to add functionality to Koda so that you can take an existing GUI section, with while loop and cases and all and then koda would literally build it ready for tweaking and where existing things still exist and have been tweaked, it would tweak such details and keep all the existing case information and added formatting things that were manually tweaked etc?
      This would be really amazing and I feel that other people would benefit from it. I can't be the only person who makes a GUI, doesn't save it and then has no problems making minor tweaks in-code but struggles like hell to go rearranging things perfectly. That is where using a GUI (koda) to make and arrange a GUI you are making, makes everything easy and pleasure to deal with.
      A friend gives me his code and wants help. The GUI is just a mess, but trying to do all the alignment and positioning all by digits in code would be a pain. I cannot just hallucinate where everything is based on pixel locations and sizes. So I would take the entire GUI chunk of code, all the form/controls/formatting functions/while loop/switch/case in it's entirety and paste it into an area of Koda and press a button. Koda would then build the GUI on the screen, placing all the controls and formatting them with the instructions that may have been added and keeps the case information as-is. Then when you make your alterations in Koda, you go to export it and it makes an entirely new export that re-makes (from scratch as if you had made this GUI from scratch) all the code for controls, size, placement etc and then also adds all the existing case code back as part of the code you then send (or manually copy/paste as I do) to Scite editor.
      Is there any chance this could be implemented? I think this could help a lot of people with their own scripts and others'.
    • Miliardsto
      Buttons and labels in tabs
      By Miliardsto
      Hello I got problem with my form cause i got some buttons, labels, inputs and now i want organize this in tabs.
      There is a problem, when i put new tab this tab is on bottom and this is above my buttons or button is show on whole form , not only in one tab.
      How to deal with it