Mingre

[SOLVED] Allow selection just like in snipping tool

6 posts in this topic

#1 ·  Posted (edited)

I'm not quite sure what keywords to search for. What I need is to have the user select an area on the screen just like in snipping tool. Can anyone lead me from here? Thanks.

Edited by Mingre
Added "solved"

Share this post


Link to post
Share on other sites



Mingre,

I have posted this a few times, but another instance will not hurt:

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

Global $hCapture_GUI
; Set distance from edge of Capture_GUI where resizing is possible
Global Const $iMargin = 4
; Set max and min Capture_GUI sizes
Global Const $iGUIMinX = 50, $iGUIMinY = 50, $iGUIMaxX = @DesktopWidth - 100, $iGUIMaxY = @DesktopHeight - 100

_Main()

Func _Main()

    Local $sBMP_Path = @ScriptDir & "\Rect.bmp"

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

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

    GUISetState()

    While 1
        Switch GUIGetMsg()
            Case $GUI_EVENT_CLOSE, $hCancel_Button
                FileDelete($sBMP_Path)
                Exit
            Case $hRect_Button
                GUISetState(@SW_HIDE, $hMain_GUI)
                Local $aCoords = Mark_Rect()
                ; Capture selected area
                _ScreenCapture_Capture($sBMP_Path, $aCoords[0], $aCoords[1], $aCoords[0] + $aCoords[2], $aCoords[1] + $aCoords[3], False)
                GUISetState(@SW_SHOW, $hMain_GUI)
                ; Display image
                Local $hBitmap_GUI = GUICreate("Selected Rectangle", $aCoords[2], $aCoords[3], 100, 100)
                Local $hPic = GUICtrlCreatePic(@ScriptDir & "\Rect.bmp", 0, 0, $aCoords[2], $aCoords[3])
                GUISetState()
        EndSwitch

    WEnd



EndFunc   ;==>_Main

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

Func Mark_Rect()

    ; Create capture GUI
    $hCapture_GUI = GUICreate("Y", 100, 100, -1, -1, $WS_POPUP, BitOR($WS_EX_LAYERED, $WS_EX_TOPMOST))
    GUISetBkColor(0xABCDEF)

    ; Create label for dragging
    Local $cLabel = GUICtrlCreateLabel("", $iMargin * 2, $iMargin * 2, 100 - ($iMargin * 4), 100 - ($iMargin * 4), -1, $GUI_WS_EX_PARENTDRAG)
    GUICtrlSetBkColor(-1, 0xFFFFFF)
    GUICtrlSetResizing(-1, $GUI_DOCKBORDERS)

    ; Create context menu
    Local $cContextMenu = GUICtrlCreateContextMenu($cLabel)
    $cContext_Capture = GUICtrlCreateMenuItem("Capture", $cContextMenu)
    $cContext_Cancel = GUICtrlCreateMenuItem("Cancel", $cContextMenu)

    ; Hide GUI
    _WinAPI_SetLayeredWindowAttributes($hCapture_GUI, 0xABCDEF, 250)


    GUISetState()

    ; Set transparency level
    WinSetTrans($hCapture_GUI, "", 100)

    ; Register message handlers
    GUIRegisterMsg($WM_MOUSEMOVE, "_SetCursor") ; For cursor type change
    GUIRegisterMsg($WM_LBUTTONDOWN, "_WM_LBUTTONDOWN") ; For resize/drag
    GUIRegisterMsg($WM_GETMINMAXINFO, "_WM_GETMINMAXINFO") ; For GUI size limits

    While 1

        Switch GUIGetMsg()
            Case $cContext_Capture
                ; Get GUI position and delete
                $aPos = WinGetPos($hCapture_GUI)
                GUIDelete($hCapture_GUI)
                ; Unregister message handlers
                GUIRegisterMsg($WM_MOUSEMOVE, "")
                GUIRegisterMsg($WM_LBUTTONDOWN, "")
                GUIRegisterMsg($WM_GETMINMAXINFO, "")
                ; Peturn position
                Return $aPos

            Case $cContext_Cancel
                Exit
        EndSwitch

    WEnd



EndFunc   ;==>Mark_Rect



; Set cursor to correct resizing form if mouse is over a border
Func _SetCursor()
    Local $iCursorID

    Switch _Check_Border()
        Case 0
            $iCursorID = 2
        Case 1, 2
            $iCursorID = 13
        Case 3, 6
            $iCursorID = 11
        Case 5, 7
            $iCursorID = 10
        Case 4, 8
            $iCursorID = 12
    EndSwitch

    GUISetCursor($iCursorID, 1)
EndFunc   ;==>_SetCursor



; Check cursor type and resize/drag window as required
Func _WM_LBUTTONDOWN($hWnd, $iMsg, $wParam, $lParam)
    Local $iCursorType = _Check_Border()
    If $iCursorType > 0 Then ; Cursor is set to resizing style so send appropriate resize message
        $iResizeType = 0xF000 + $iCursorType

        _SendMessage($hCapture_GUI, $WM_SYSCOMMAND, $iResizeType, 0)
    EndIf

EndFunc   ;==>_WM_LBUTTONDOWN

; Determines if mouse cursor over a border
Func _Check_Border()
    Local $aCurInfo = GUIGetCursorInfo($hCapture_GUI)
    Local $aWinPos = WinGetPos($hCapture_GUI)
    Local $iSide = 0
    Local $iTopBot = 0
    If $aCurInfo[0] < $iMargin Then $iSide = 1
    If $aCurInfo[0] > $aWinPos[2] - $iMargin Then $iSide = 2
    If $aCurInfo[1] < $iMargin Then $iTopBot = 3
    If $aCurInfo[1] > $aWinPos[3] - $iMargin Then $iTopBot = 6
    Return $iSide + $iTopBot

EndFunc   ;==>_Check_Border

; Set min and max GUI sizes
Func _WM_GETMINMAXINFO($hWnd, $iMsg, $wParam, $lParam)
    $tMinMaxInfo = DllStructCreate("int;int;int;int;int;int;int;int;int;int", $lParam)
    DllStructSetData($tMinMaxInfo, 7, $iGUIMinX)
    DllStructSetData($tMinMaxInfo, 8, $iGUIMinY)
    DllStructSetData($tMinMaxInfo, 9, $iGUIMaxX)
    DllStructSetData($tMinMaxInfo, 10, $iGUIMaxY)
    Return 0
EndFunc   ;==>_WM_GETMINMAXINFO

Drag the blue sides to resize, the white centre to move and right-click inside when ready.

M23


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

Spoiler

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

#3 ·  Posted (edited)

Melba,

Thanks for the quick reply!

I currently employ a similar way of highlighting a particular area (see pasted code below). I wanted something similar to the method of selection used in snipping tool because it's easier for users (which is just me, haha). 

Edit1: I'm thinking of capturing the mouse coordinates the instance the user clicks and releases the mouse but I don't know how to add the visual of an enlarging selection box like when selecting files in a folder.

; http://www.autoitscript.com/forum/topic/24342-form-snap/page__view__findpost__p__170144
#include <GUIConstants.au3>
#include <GDIPlus.au3>
Global Const $SPI_GETWORKAREA = 0x30
Global $hGui_Rect
_DrawRect(100, 100, 100, 100)



$Gui = GUICreate("Snapped window", 100, 100, 100, 100, 0x00040000 + 0x00020000, 0x00000008);, WinGetHandle('Program Manager'))
GUICtrlCreateLabel('', 0, 0, 100, 100, -1, $GUI_WS_EX_PARENTDRAG)
WinSetTrans($Gui, '', 1)
GUISetState()
GUIRegisterMsg(0x0046, "WM_WINDOWPOSCHANGING")


While 1
    $GUIMsg = GUIGetMsg()

    Switch $GUIMsg
        Case $GUI_EVENT_CLOSE
            ExitLoop
    EndSwitch
WEnd

Func WM_WINDOWPOSCHANGING($hWnd, $Msg, $wParam, $lParam)
    Local $stRect = DllStructCreate("int;int;int;int")
    Local $stWinPos = DllStructCreate("uint;uint;int;int;int;int;uint", $lParam)
    DllCall("User32.dll", "int", "SystemParametersInfo", "int", $SPI_GETWORKAREA, "int", 0, "ptr", DllStructGetPtr($stRect), "int", 0)
    Local $iX, $iY, $iW, $iH
    $iX = DllStructGetData($stWinPos, 3)
    $iY = DllStructGetData($stWinPos, 4)
    $iW = DllStructGetData($stWinPos, 5)
    $iH = DllStructGetData($stWinPos, 6)
    GUIDelete($hGui_Rect)
    _DrawRect($iX, $iY, $iW, $iH)
    Return 0
EndFunc   ;==>WM_WINDOWPOSCHANGING



Func _DrawRect($x, $y, $w, $h)
    Local $hBitmap, $hGraphic, $GuiSizeX = @DesktopWidth, $GuiSizeY = @DesktopHeight
    Local $GuiSize = 70, $hWnd, $hDC, $pSize, $tSize, $pSource, $tSource, $pBlend, $tBlend, $hPen
    Local $iOpacity = 255
    Local $sTitle = 'halakahalaka'
    ;If WinGetTitle($hGui_Rect) = $sTitle Then GUIDelete($hGui_Rect)
    $hGui_Rect = GUICreate($sTitle, $GuiSizeX, $GuiSizeY, 0, 0, $WS_POPUP, BitOR($WS_EX_LAYERED, $WS_EX_TOPMOST), WinGetHandle('Program Manager'))
    GUISetState(@SW_SHOWNOACTIVATE)

    _GDIPlus_Startup()
    $hWnd = _WinAPI_GetDC(0)
    $hDC = _WinAPI_CreateCompatibleDC($hWnd)
    $hBitmap = _WinAPI_CreateCompatibleBitmap($hWnd, $GuiSizeX, $GuiSizeY)
    _WinAPI_SelectObject($hDC, $hBitmap)
    $hGraphic = _GDIPlus_GraphicsCreateFromHDC($hDC)

    $hPen = _GDIPlus_PenCreate(0xFFFF0000, 3)

    $tSize = DllStructCreate($tagSIZE)
    $pSize = DllStructGetPtr($tSize)
    DllStructSetData($tSize, "X", $GuiSizeX)
    DllStructSetData($tSize, "Y", $GuiSizeY)
    $tSource = DllStructCreate($tagPOINT)
    $pSource = DllStructGetPtr($tSource)
    $tBlend = DllStructCreate($tagBLENDFUNCTION)
    $pBlend = DllStructGetPtr($tBlend)
    DllStructSetData($tBlend, "Alpha", $iOpacity)
    DllStructSetData($tBlend, "Format", 1)

    _GDIPlus_GraphicsDrawRect($hGraphic, $x, $y, $w, $h, $hPen) ; <-- Graphics to layered wimdow.
    _WinAPI_UpdateLayeredWindow($hGui_Rect, $hWnd, 0, $pSize, $hDC, $pSource, 0, $pBlend, $ULW_ALPHA)

    _GDIPlus_PenDispose($hPen)
    _GDIPlus_GraphicsDispose($hGraphic)
    _WinAPI_ReleaseDC(0, $hWnd)
    _WinAPI_DeleteObject($hBitmap)
    _WinAPI_DeleteDC($hDC)
    _GDIPlus_Shutdown()
EndFunc   ;==>_DrawRect

 

Edited by Mingre
Added something.

Share this post


Link to post
Share on other sites

Mingre,

Perhaps this:

#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)

GUISetState()

While 1

    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE, $hCancel_Button
            FileDelete(@ScriptDir & "\Rect.bmp")
            Exit
        Case $hRect_Button
            GUISetState(@SW_HIDE, $hMain_GUI)
            Mark_Rect()
            ; 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)
            GUISetState()

    EndSwitch



WEnd



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

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)
    GUISetBkColor(0xFF0000)

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



    ; 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)
        _WinAPI_DeleteObject($hMask)
        $hMask = _WinAPI_CreateRectRgn($iX1, $iY1, $iX1 + 1, $aMouse_Pos[1]) ; Left of rectangle
        _WinAPI_CombineRgn($hMaster_Mask, $hMask, $hMaster_Mask, 2)
        _WinAPI_DeleteObject($hMask)
        $hMask = _WinAPI_CreateRectRgn($iX1 + 1, $iY1 + 1, $aMouse_Pos[0], $iY1) ; Top of rectangle
        _WinAPI_CombineRgn($hMaster_Mask, $hMask, $hMaster_Mask, 2)
        _WinAPI_DeleteObject($hMask)
        $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)
        _WinAPI_DeleteObject($hMask)
        ; Set overall region
        _WinAPI_SetWindowRgn($hRectangle_GUI, $hMaster_Mask)

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

    WEnd



    ; 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

    EndIf

    If $iY2 < $iY1 Then
        $iTemp = $iY1
        $iY1 = $iY2
        $iY2 = $iTemp

    EndIf



    GUIDelete($hRectangle_GUI)
    GUIDelete($hCross_GUI)
    DllClose($UserDLL)

EndFunc   ;==>Mark_Rect

Just keep the mouse button down and drag.

M23

2 people like this

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

Spoiler

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

Melba23,

That's exactly what I needed. Thank you so much!

Share this post


Link to post
Share on other sites

Mingre,

Glad I could help.

M23


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

Spoiler

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

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

  • Similar Content

    • david1337
      By david1337
      Hey guys
      I hope that I can get a little help with this one
       
      In this GUI example using GUIListViewEx, I have a list based on items found in test.txt.
      _____________________________________________
      item1
      item2
      item3
      ____________________________________________
      etc....
       
      When an item is selected, and I click the GetInfo button, a message will show the text of that item.
      Is it possible to activate a case like that as soon as the item is selected, so I don't need a button to start the case?
       
      #include <GUIConstantsEx.au3> #include <GUIListViewEx.au3> Global $MainGUI_ManageItemList Global $File = "test.txt" Global $FileToArray = FileReadToArray("test.txt") Call ("MainGUI_ManageItemList") Func MainGUI_ManageItemList() Local $Button1 $MainGUI_ManageItemList = GUICreate("Manage Item List", 800, 400, -1, -1) $cLV = GUICtrlCreateListView("[items]", 10, 10, 400, 775, $LVS_NOCOLUMNHEADER) GUICtrlSetFont(-1, 12, 800, 0, "@Arial Unicode MS") _GUICtrlListView_SetColumnWidth($cLV, 0, 378) $Button1 = GUICtrlCreateButton("Button 1", 425, 10, 80, 30) $RemoveItem = GUICtrlCreateButton("Remove Item", 425, 50, 80, 30) $GetInfo = GUICtrlCreateButton("GetInfo", 425, 120, 80, 30) GUISetState(@SW_SHOW, $MainGUI_ManageItemList) ; Intialise ListView Global $iLV_Index = _GUIListViewEx_Init($cLV) ; Insert lines _GUIListViewEx_Insert($FileToArray, True) ; Register required messages _GUIListViewEx_MsgRegister(True, False, False, False) While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE ExitLoop Case $Button1 MsgBox(0,"","Button 1 is pressed") Case $RemoveItem _GUIListViewEx_Delete() Case $GetInfo $ItemSelected = _GUICtrlListView_GetSelectedIndices($cLV, True) If IsArray($ItemSelected) And $ItemSelected[0] <> 0 Then ;This part makes sure it doesn't crash when no item is selected. $ItemSelectedText = _GUICtrlListView_GetItemText($cLV, $ItemSelected[1]) msgbox (0, "Selected item", $ItemSelectedText) EndIf EndSwitch WEnd EndFunc ;==>Main  
    • SaeidN
      By SaeidN
      Hi,
      I want to tell pixelsearch to search for red color shades in for example 5 different x,y,h,w of the screen. If color red was not found in these 5 area, then do something.
      I wrote this, but it's working only if the first case is not found. Is select a good choice? or it's better to use switch or if or something else?
      ٍEdit: all "do something"s are same function. (search for red color untill in these 5 areas, it couldnot find red color, then if it couldn't find red color, perform that 1 function)
      Thanks
      Select Case 1 $color1 = PixelSearch(67, 614, 77, 617, 0xE62121, 10) If @error Then do something... EndIf Case 2 $color2 = PixelSearch(165, 614, 175, 617, 0xE62121, 10) If @error Then do something... EndIf Case 3 $color3 = PixelSearch(265, 614, 275, 617, 0xE62121, 10) If @error Then do something... EndIf Case 4 $color4 = PixelSearch(365, 614, 375, 617, 0xE62121, 10) If @error Then do something... EndIf Case 5 $color5 = PixelSearch(465, 614, 475, 617, 0xE62121, 10) If @error Then do something... EndIf EndSelect  
    • wzc0014
      By wzc0014
      Hello, 
      I am interested in looking at a chunk of text, selecting the string that is in quotes, and copying it to the clipboard. It will always have quotes at the beginning and end, start with https:// and will always contain .mp3 . But everything else is pretty random. This is an example of a piece of text
      I tried doing something like this but it didn't like the quotes. 
      $sStart = "file: "" $sEnd = ""," $aExtract = _StringBetween($sStart, $sEnd) ClipPut($aExtract)  
      Or is there a better/easier way to do this?
    • FMS
      By FMS
      Hello,

      I've writing this code and I'm a little stuck in what i want to do.
      When I select the combobox I want to get the ini information inside the multiline input field.
      I know that what I'm doing now is wrong but maybe this helps to clearify things in what I want to do.
      Does somebody knows how to do this , or can help me?
       
       
      #include <ButtonConstants.au3> #include <ComboConstants.au3> #include <GUIConstantsEx.au3> #include <TabConstants.au3> #include <File.au3> #include <WindowsConstants.au3> #include <MsgBoxConstants.au3> #include <Array.au3> #include <Date.au3> check_file_exist() $Form1 = GUICreate("Form1", 320, 260, 192, 324);(b,h,,),30 $Tab1 = GUICtrlCreateTab(5, 5, 310, 250) ;(,,b,h) $TabSheet3 = GUICtrlCreateTabItem("Edit") $Label_tab_select = GUICtrlCreateLabel("select", 40, 50, 80, 25) $tab_select = GUICtrlCreateCombo(" tab 1", 40, 70, 80, 25, BitOR($CBS_DROPDOWN,$CBS_AUTOHSCROLL)) GUICtrlSetData(-1, " tab 2") $Label_BtnSelect = GUICtrlCreateLabel("nr", 125, 50, 80, 25) $BtnSelect = GUICtrlCreateCombo(" 1", 125, 70, 60, 25, BitOR($CBS_DROPDOWN,$CBS_AUTOHSCROLL)) GUICtrlSetData(-1, " 2 ") $Label_BtnName = GUICtrlCreateLabel("name", 190, 50, 80, 25) $BtName = GUICtrlCreateInput("", 190, 70, 80, 21) $multiline = GuiCtrlCreateEdit("this text needs to be changed at selection of combobox",15, 105, 290, 110) ;the next line is to clearify things :) ;$multiline = GuiCtrlCreateEdit(IniRead($ini_location_buttons, "btn00" & GUICtrlRead($BtnSelect), "text"),15, 105, 290, 110) $Btn301 = GUICtrlCreateButton("Cancel", 40, 220, 75, 25) $Btn302 = GUICtrlCreateButton("Save", 152, 220, 75, 25) GUICtrlCreateTabItem("") GUISetState(@SW_SHOW) While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $Btn301 Exit Case $Btn302 Exit EndSwitch WEnd Func check_file_exist() If FileExists(@SCRIPTDIR & "\ini.ini") Then Global $ini_location_buttons = @SCRIPTDIR & "\ini.ini" Else If Not _FileCreate(@SCRIPTDIR & "\buttons.ini") Then MsgBox($MB_SYSTEMMODAL, "Error", " Error Creating/Resetting ini. error:" & @error) Else Global $ini_location_buttons = @SCRIPTDIR & "\ini.ini" create_new_ini() EndIf EndIf EndFunc Func create_new_ini() $file = FileOpen($ini_location_buttons, 1) Local $i = 1 local $j = 0 Do if $i = 10 then $j = "" FileWrite($file, "[btn0" & $j & $i & "]"& @CRLF) FileWrite($file, "button_name=Button " & $i & @CRLF) FileWrite($file, "text=lorum ipsum" & $i & @CRLF) $i = $i + 1 Until $i = 3 FileClose($file) EndFunc  
    • OldGuyWalking
      By OldGuyWalking
      Hello All:
      I am reading data from a ListView and based on criteria I want to have the script select certain rows in the ListView.  The script would loop through the ListView data and would select multiple rows out-of-sequence.  At the end, the script would press a button on the form which would remove the selected rows.
      I'd originally had the script read a row and if criteria was met it would click on the button and remove that row.  In some cases there can be thousands of rows in the listview and clicking a button and then moving back to the listview was slow.  Selecting all affected rows and then pressing the button once would speed things up.
      I've tried various functions and GUI UDF's to select a row but each time I ran the script I'd only get 1 row selected when I know there are dozens of records that should be selected.   What I think is happening is that the ControlSend method I was using to move down the rows by sending the ListView a Down key may have been deselecting each selected row as soon as the Down Arrow was sent.
      Everything except for the Selection piece is working.  I've looked through the help files and the forums and could not find information on another way to cycle through the ListView rows.  I've included the code below along with each of the functions or UDF's I tried.
      Could someone let me know if there is another way to move through the Listview rows other than using ControlSend that won't deselect Selected records?  If that's not an option, can someone let me know if there's another way to select rows in a ListView that won't be affected by the Down Arrow key?
      Thank you.
      Bill
      #AutoIt3Wrapper_UseX64=Y #include <MsgBoxConstants.au3> #include <array.au3> #include <GuiListbox.au3> #include <GuiToolbar.au3> #include <GuiListView.au3> HotKeySet("!{Esc}", "Terminate") Opt("MustDeclareVars", 1) ; Must declare variables Opt("WinTitleMatchMode", 2) ; Can match substrings in title Dim $hWnd ; main Title handle Dim $hCntrlLV1 ; List View handle ("SysListView328") Dim $sSubject ; Column 0 Dim $sStatus ; Column 1 Dim $sSize ; Column 2 Dim $sDate ; Column 3 Dim $sPoster ; Column 4 Dim $sGroup ; Column 5 Dim $bDelete = False Dim $iMaxRows ; Total Rows in List View Dim $iMaxCols ; Total Columns in List View Dim $iCurRow ; Current Row being read Dim $iSelected ; Total items Selected Dim $sTitle1 = "Main Title" If WinExists($sTitle1, "") Then $hWnd = WinActivate($sTitle1, "") If @error Then MsgBox(48, $sTitle1, "Could not activate the form.") Terminate EndIf $hCntrlLV1 = ControlGetHandle($hWnd, "", "SysListView328") ControlFocus($hWnd, "", $hCntrlLV1) $iMaxRows = ControlListView($hWnd, "", $hCntrlLV1, "GetItemCount") $iMaxCols = _GUICtrlListView_GetColumnCount($hCntrlLV1) ControlSend($hWnd, "", $hCntrlLV1, "{Home}") $iCurRow = 0 ; Zero based row in listview Do $bDelete = False ; Default ; This reads the data - (tested - no problem). $sSubject = ControlListView($hWnd, "", $hCntrlLV1, "GetText", $iCurRow, 0) $sStatus = ControlListView($hWnd, "", $hCntrlLV1, "GetText", $iCurRow, 1) $sSize = ControlListView($hWnd, "", $hCntrlLV1, "GetText", $iCurRow, 2) $sDate = ControlListView($hWnd, "", $hCntrlLV1, "GetText", $iCurRow, 3) $sPoster = ControlListView($hWnd, "", $hCntrlLV1, "GetText", $iCurRow, 4) $sGroup = ControlListView($hWnd, "", $hCntrlLV1, "GetText", $iCurRow, 5) ; Identifies if a row should be deleted and sets the flag $bDelete to True (tested - no problem). Select Case StringLeft($sStatus, 8) = "Idle/Old" $bDelete = True Case StringInStr($sGroup, "Test1") > 0 $bDelete = True Case StringInStr($sSubject, "Test2") > 0 $bDelete = True EndSelect ; If the row should be deleted, select it in the same way as a Ctrl+Left Mouse Click. ; (tested the following but the "select" didn't stick. See note below regarding ControlSend Down. If $bDelete = True Then ; ;_GUICtrlListView_SetItemSelected($hCntrlLV1,$iCurRow) ; ControlListView($hWnd, "", $hCntrlLV1,"Select", $iCurRow) ;_GUICtrlListView_SetSelectionMark($hCntrlLV1, $iCurRow) $bDelete = False ; Reset the flag EndIf ; Move to the next row and increment the current row counter. (tested - no problem). ; Pressing the down arrow deselects any Selected records. ; Is there another method for moving up or down a listview? ControlSend($hWnd, "", $hCntrlLV1, "{Down}") $iCurRow = $iCurRow + 1 ; Keep going until the end of the List View is reached. Until $iCurRow = $iMaxRows ; Get the number of items "Selected" in the List View. (tested - Both show 1 record selected.) $iSelected = 0 $iSelected = ControlListView($hWnd, "", $hCntrlLV1, "GetSelectedCount") MsgBox(262144, 'Debug line ~' & @ScriptLineNumber, 'Selection:' & @CRLF & '$iSelected' & @CRLF & @CRLF & 'Return:' & @CRLF & $iSelected) ;### Debug MSGBOX $iSelected = 0 $iSelected = _GUICtrlListView_GetSelectedCount($hCntrlLV1) MsgBox(262144, 'Debug line ~' & @ScriptLineNumber, 'Selection:' & @CRLF & '$iSelected' & @CRLF & @CRLF & 'Return:' & @CRLF & $iSelected) ;### Debug MSGBOX If $iSelected > 0 Then ; MouseClick("left",506,70,1) ; This clicks a button to remove records. (tested by clicking button when cycling through each record - no problem) EndIf Else MsgBox(0, "Error", "Form not active.") ; If the program isn't running then error out and quit EndIf Func Terminate() Exit EndFunc ;==>Terminate