Sign in to follow this  
Followers 0
JakeJohnson74

Feeling like I am doing this wrong...

2 posts in this topic

#1 ·  Posted (edited)

Ok, so I feel as though I am programming myself into a corner here. 

The code is a mess currently (but it runs) 

First problem: my _ScreenOffset() is basically being call in line: 189 once. This takes one of my many listviews and establishes its position relative to the client. I then use $aLV_Offset in the message loop on the $GUI_EVENT_MOUSEMOVE in an if statement. 

This was the only way I could figure out how to make an imaginary boundary to capture the listview I was dragging from. (any advice here would be  much appreciated) 

Fixed Second related issue: If the user drags the whole GUI I need to update my $aLV_Offset positions and since its called once at the top - that isn't happening. I need a little nudge on how I would do this? Im thinking about registering WM_MOVE? and if the GUI moves - call my function and refresh its location. Just need a confirmation on that I suppose

Third Issue: I have the drag and drop working on the Listview to the Treeview - but if you look at my Drag and Drop functions (line:379  & 400) you'll see if VERY specific to dragging FROM a list view, TO a treeview. 

This is the biggest hurdle right now as I need dynamic Source and Target code. 

case 1: If source = listview  target = treeview

case 2: if source = treeview  target = listview 

There are 7 list views and 2 tree views. So its very important to me that I target the right listview and the right tree view while dragging and dropping both ways and the two controls don't handle drag and drop the same ways. 

So upon getting a successful drag and drop from the listviews to a treeview, I was happy! Then I thought - hmm, now... the treeview to the list view... CRAP! This is NOT written to handle it at all! 

I have used various examples to get this far. For example there is Treeview / Listview drag and drop code example here, but they are static. the example shows the drag and drop functions hard coded to look at one specific control and move data to another specific control. This is simple - I need something more complex. 

In summary - I would like some advice on best practice as I feel like I am getting into a little longer code here and at this point i feel like I put some time into going the wrong direction! haha. 

 

*Edit - Feel free to dump my include you don't have. LOL I removed the code - but didn't remove the include. DatabaseConnect.au3

#Region Includes
#include <winapi.au3>
#include <WinAPIEx.au3>
#include <GuiToolbar.au3>
#include <GuiImageList.au3>
#include <GUIConstants.au3>
#include <GuiConstantsEx.au3>
#include <WindowsConstants.au3>
#include <GUITab.au3>
#include <GuiTreeView.au3>
#include <Constants.au3>
#include <TabConstants.au3>
#include <WinAPIEx.au3>
#include <DatabaseConnect.au3>
#include <TreeViewConstants.au3>
#include <GuiListView.au3>
#include <ListViewConstants.au3>
#include <Misc.au3>
;todo - clean out includes no longer used / remove large includes i can just replace with Const values... 

#EndRegion

GUIRegisterMsg($WM_NOTIFY, "_WM_NOTIFY")

#Region URL ref
;This is a site I used to trial and error finding the Id's for the Icons I wanted.
;http://diymediahome.org/windows-icons-reference-list-with-details-locations-images/
#EndRegion

#Region Vars
;Only Tested on Win7 64 machine
Local $fIconsLoc1 = "imageres.dll"
Local $fIconsLoc2 = "Resources\Icons\Undo.ico"

Global $aStrings[12]
Local $iNew,$iBrowse,$iEdit,$iDelete,$iSave,$iPrint
Global Enum $e_new =1000, $e_edit, $e_delete, $e_save, $e_print, $e_undo
Global $iItem, $cTreeView1, $cTreeView2,$hDll, $pDll, $hProc
Global $hTab1, $hTab2, $hTab3
Global $hItemHover
Global $aHwndFrom, $aHwndTo
Global $hTvItemHover,$hLvItemHover
Global $Debugmode = True
Global $aLV_Offset,$aForm_Offset,$aWin1,$aWin2


; Icon Index from DLL
$iNew = 2
;$iBrowse = 202
$iEdit = 111
$iDelete = 84
$iSave = 23
$iPrint = 46

$iGuiWidth = 1024
$iGUIHeight = 768
$BkColor = 0xf0f0f0

#EndRegion Vars

;Create Form, Toobar and ImageList
$hGui = GUICreate("EDM and CNC Schedule",$iGuiWidth,$iGUIHeight,-1,-1)
GUISetState()

Global $hToolbar1 = _GUICtrlToolbar_Create($hGui)
$imgs = _GUIImageList_Create(32,32,5) ; change first 2 params to Size the icons accordingly.

#Region Toolbar
;Populate Image List
_GUIImageList_AddIcon($imgs, $fIconsLoc1,$iNew,True)
_GUIImageList_AddIcon($imgs, $fIconsLoc1,$iEdit,True)
_GUIImageList_AddIcon($imgs, $fIconsLoc1,$iDelete,True)
_GUIImageList_AddIcon($imgs, $fIconsLoc1,$iSave,True)
_GUIImageList_AddIcon($imgs, $fIconsLoc1,$iPrint,True)
_GUIImageList_AddIcon($imgs, $fIconsLoc2,0,True)

;Add Text to Buttons in Toolbar
$aStrings[0] = _GUICtrlToolbar_AddString($hToolbar1, "&New")
$aStrings[1] = _GUICtrlToolbar_AddString($hToolbar1, "&Edit")
$aStrings[2] = _GUICtrlToolbar_AddString($hToolbar1, "&Delete")
$aStrings[3] = _GUICtrlToolbar_AddString($hToolbar1, "&Save")
$aStrings[4] = _GUICtrlToolbar_AddString($hToolbar1, "&Print")
$aStrings[5] = _GUICtrlToolbar_AddString($hToolbar1, "&Undo")

;Set Imagelist of Toolbar to my ImageList
$t = _GUICtrlToolbar_SetImageList($hToolbar1, $imgs)

;Add buttons to toolbar
$cBtn_New = _GUICtrlToolbar_AddButton($hToolbar1, $e_new, 0,$aStrings[0])
$cBtn_Edit =_GUICtrlToolbar_AddButton($hToolbar1, $e_edit, 1,$aStrings[1])
$cBtn_Delete =_GUICtrlToolbar_AddButton($hToolbar1, $e_delete, 2,$aStrings[2])
$cBtn_Save =_GUICtrlToolbar_AddButton($hToolbar1, $e_save, 3,$aStrings[3])
$cBtn_Print =_GUICtrlToolbar_AddButton($hToolbar1, $e_print, 4,$aStrings[4])
$cBtn_Undo =_GUICtrlToolbar_AddButton($hToolbar1, $e_undo, 5,$aStrings[5])
GUISetState()

#EndRegion Toolbar


#Region Create Tabs
$hGui1 = GUICreate("",$iGuiWidth-8,$iGUIHeight-65,5,60, $WS_POPUP, $WS_EX_MDICHILD,$hgui)
;~ GUISetBkColor(0x00FF00,$hGui1)
; Create top level Tab Items
$hTab1 = GUICtrlCreateTab(0,1,$iGuiWidth-8,$iGUIHeight-65)
$hTab1_0 = GUICtrlCreateTabItem("EDM Schedule")

;cTreeView 1
$cTreeView1  = GUICtrlCreateTreeView(0, 25, 175, 678, BitOR($TVS_HASBUTTONS,  $TVS_HASLINES, $TVS_LINESATROOT, $TVS_SHOWSELALWAYS), $WS_EX_CLIENTEDGE)
GUICtrlSetState(-1, $GUI_DROPACCEPTED)
;Set TreeView Data
$generalitem = GUICtrlCreateTreeViewItem("16012", $cTreeView1)
GUICtrlSetColor(-1, 0x0000C0)
$displayitem = GUICtrlCreateTreeViewItem("16187", $cTreeView1)
GUICtrlSetColor(-1, 0x0000C0)
GUICtrlCreateTreeViewItem("Stripper", $generalitem)
GUICtrlCreateTreeViewItem("Die Plate", $generalitem)
GUICtrlCreateTreeViewItem("Punch String", $generalitem)
GUICtrlCreateTreeViewItem("Die Insert String", $displayitem)
GUICtrlCreateTreeViewItem("Punch Plate", $displayitem)
GUICtrlSetState($generalitem, BitOR($GUI_EXPAND, $GUI_DEFBUTTON)) ; Expand the "General"-item and paint in bold
GUICtrlSetState($displayitem, BitOR($GUI_EXPAND, $GUI_DEFBUTTON)) ; Expand the "Display"-item and paint in bold


;~ GUISetState()
$hTab1_1 = GUICtrlCreateTabItem("CNC Schedule ")


;cTreeView 2
$cTreeView2  = GUICtrlCreateTreeView(0, 25, 175, 678, BitOR($TVS_HASBUTTONS,  $TVS_HASLINES, $TVS_LINESATROOT, $TVS_SHOWSELALWAYS),$WS_EX_CLIENTEDGE)
GUICtrlSetState(-1, $GUI_DROPACCEPTED)
$generalitem = GUICtrlCreateTreeViewItem("15874", $cTreeView2)
GUICtrlSetColor(-1, 0x0000C0)
$displayitem = GUICtrlCreateTreeViewItem("16183", $cTreeView2)
GUICtrlSetColor(-1, 0x0000C0)
GUICtrlCreateTreeViewItem("Punch Plate", $generalitem)
GUICtrlCreateTreeViewItem("Die Plate", $generalitem)
GUICtrlCreateTreeViewItem("Stripper", $generalitem)
GUICtrlCreateTreeViewItem("Die Shoe", $displayitem)
GUICtrlCreateTreeViewItem("Punch Holder", $displayitem)
GUICtrlSetState($generalitem, BitOR($GUI_EXPAND, $GUI_DEFBUTTON)) ; Expand the "General"-item and paint in bold
GUICtrlSetState($displayitem, BitOR($GUI_EXPAND, $GUI_DEFBUTTON)) ; Expand the "Display"-item and paint in bold.

GUICtrlCreateTabItem("")

GUISetState()

;Create Inner GUI to hold the listviews for first tab
$hGuiInner1 = GUICreate("",  834,679, 182,28, $WS_POPUP,$WS_EX_MDICHILD, $hgui1)
$hLabelMask1 = GUICtrlCreateLabel("",89 ,0, 760, 21, BitOR($SS_NOTIFY, $SS_CENTER))
GUICtrlsetBkColor ($hLabelMask1,0xffffff )
$hTab2 = GUICtrlCreateTab(0,0,834,679)
$hTab2_0 = GUICtrlCreateTabItem("Fryer ")
$ListView5 = GUICtrlCreateListView("col1|col2|col3",  0, 20, 833, 658)
$ListView5_0 = GUICtrlCreateListViewItem("Item1", $ListView5)
$ListView5_1 = GUICtrlCreateListViewItem("Item2", $ListView5)
$ListView5_2 = GUICtrlCreateListViewItem("Item3", $ListView5)
$ListView5_3 = GUICtrlCreateListViewItem("Item4", $ListView5)
$hTab2_1 = GUICtrlCreateTabItem("Micron")
$ListView6 = GUICtrlCreateListView("col1|col2|col3",  0, 20, 833, 658)
$ListView6_0 = GUICtrlCreateListViewItem("Item1", $ListView6)
$ListView6_1 = GUICtrlCreateListViewItem("Item2", $ListView6)
$ListView6_2 = GUICtrlCreateListViewItem("Item3", $ListView6)
$ListView6_3 = GUICtrlCreateListViewItem("Item4", $ListView6)
GUICtrlCreateTabItem("")
GUISetState()

;Create Inner GUI to hold the listviews for second tab
$hGuiInner2 = GUICreate("",  834,679, 182,28, $WS_POPUP,$WS_EX_MDICHILD, $hgui1)
$hLabelMask2 = GUICtrlCreateLabel("",264 , 0, 750, 21, BitOR($SS_NOTIFY, $SS_CENTER))
GUICtrlsetBkColor ($hLabelMask2,0xffffff )
$hTab3 = GUICtrlCreateTab(0,0,834,679)
$hTab3_0 = GUICtrlCreateTabItem("Agie V3")
$ListView7 = GUICtrlCreateListView("col1|col2|col3",  0, 20, 833, 658)
$ListView7_0 = GUICtrlCreateListViewItem("Item1", $ListView7)
$ListView7_1 = GUICtrlCreateListViewItem("Item2", $ListView7)
$ListView7_2 = GUICtrlCreateListViewItem("Item3", $ListView7)
$ListView7_3 = GUICtrlCreateListViewItem("Item4", $ListView7)
$hTab3_1 = GUICtrlCreateTabItem("Agie V2")
$ListView8 = GUICtrlCreateListView("col1|col2|col3",  0, 20, 833, 658)
$hTab3_2 = GUICtrlCreateTabItem("Agie V22")
$ListView9 = GUICtrlCreateListView("col1|col2|col3",  0, 20, 833, 658)
$hTab3_3 = GUICtrlCreateTabItem("Agie VP2")
$ListView10 = GUICtrlCreateListView("col1|col2|col3",  0, 20, 833, 658)
$hTab3_4 = GUICtrlCreateTabItem("Progress")
$ListView11 = GUICtrlCreateListView("col1|col2|col3",  0, 20, 833, 658)
GUICtrlCreateTabItem("")
GUISetState()

$aLV_Offset= _ScreenOffset(ControlGetHandle($hGuiInner1,"",$ListView5)) ; just to get the location of all listview (left top width hieght)

#EndRegion End tabs

#Region GUI Message Loop

While 1
    $idMsg = GUIGetMsg()
    Switch $idMsg
        Case $GUI_EVENT_MOUSEMOVE
            if _IsPressed("01") Then
                $aHwndTo = DllCall("user32.dll", "hwnd", "WindowFromPoint", "uint", MouseGetPos(0), "uint", MouseGetPos(1))
                _Drag($aHwndTo[0])
                if MouseGetPos(0) > $aLV_Offset[0] and MouseGetPos(1) > $aLV_Offset[1] and MouseGetPos(0) < $aLV_Offset[2] and MouseGetPos(1) < $aLV_Offset[3] then
                    $aHwndFrom = DllCall("user32.dll", "hwnd", "WindowFromPoint", "uint", MouseGetPos(0), "uint", MouseGetPos(1))
                endif
            endif
        Case $GUI_EVENT_DROPPED
            $aHwndTo = DllCall("user32.dll", "hwnd", "WindowFromPoint", "uint", MouseGetPos(0), "uint", MouseGetPos(1))
            _Drop($aHwndTo[0],$aHwndFrom[0])
        Case $GUI_EVENT_CLOSE
            Exit
        Case $htab1
            Switch GUICtrlRead($htab1)
                Case 0
                    ; Adjust child GUIs accordingly
                    GUISetState(@SW_HIDE, $hGuiInner1)
                    GUISetState(@SW_SHOW, $hGuiInner2)
                Case 1
                    GUISetState(@SW_HIDE, $hGuiInner2)
                    GUISetState(@SW_SHOW, $hGuiInner1)
            EndSwitch
    EndSwitch
WEnd
#EndRegion GUI Message Loop

#Region Functions

; WM_NOTIFY event handler
Func _WM_NOTIFY($hWndGUI, $MsgID, $wParam, $lParam)
    #forceref $hWndGUI, $MsgID, $wParam
    Local $tNMHDR, $event, $hwndFrom, $icode, $i_idNew, $dwFlags, $lResult, $idFrom, $i_idOld, $sButtonName, $hTreeView1, $hTreeView2
    Local $tNMTOOLBAR, $tNMTBHOTITEM
    $tNMHDR = DllStructCreate($tagNMHDR, $lParam)
    $hwndFrom = DllStructGetData($tNMHDR, "hWndFrom")
    $idFrom = DllStructGetData($tNMHDR, "IDFrom")
    $icode = DllStructGetData($tNMHDR, "Code")
    $hTreeview1 = $cTreeView1
    $hTreeview2 = $cTreeView2
    If Not IsHWnd($cTreeView1) Then $hTreeview1 = GUICtrlGetHandle($cTreeView1)
    If Not IsHWnd($cTreeView2) Then $hTreeview2 = GUICtrlGetHandle($cTreeView2)
    Switch $hwndFrom
        Case $hToolbar1
            Switch $icode
                Case $NM_LDOWN
                    ;case for which button was clicked
                    Switch $iItem
                        Case $e_new
                            _button_Click($e_new)
                        Case $e_edit
                            _button_Click($e_edit)
                        Case $e_save
                            _button_Click($e_save)
                        Case $e_delete
                            _button_Click($e_delete)
                        Case $e_print
                            _button_Click($e_print)
                        Case $e_undo
                            _button_Click($e_undo)
                    EndSwitch
                Case $TBN_HOTITEMCHANGE
                    $tNMTBHOTITEM = DllStructCreate($tagNMTBHOTITEM, $lParam)
                    $i_idOld = DllStructGetData($tNMTBHOTITEM, "idOld")
                    $i_idNew = DllStructGetData($tNMTBHOTITEM, "idNew")
                    $iItem = $i_idNew
                    $dwFlags = DllStructGetData($tNMTBHOTITEM, "dwFlags")
            EndSwitch
        Case $hTreeView1, $hTreeView2
;~          Switch $icode
;~              Case $NM_CLICK ; The user has clicked the left mouse button within the control
;~                  _DebugPrint("$NM_CLICK" & @CRLF & "--> hWndFrom:" & @TAB & $hWndFrom & @CRLF & _
;~                          "-->IDFrom:" & @TAB & $iDFrom & @CRLF & _
;~                          "-->Code:" & @TAB & $iCode, $Debugmode)
;~                  ; Return 1 ; nonzero to not allow the default processing
;~                  Return 0 ; zero to allow the default processing
;~              Case $NM_DBLCLK ; The user has double-clicked the left mouse button within the control
;~                  _DebugPrint("$NM_DBLCLK" & @CRLF & "--> hWndFrom:" & @TAB & $hWndFrom & @CRLF & _
;~                          "-->IDFrom:" & @TAB & $iDFrom & @CRLF & _
;~                          "-->Code:" & @TAB & $iCode, $Debugmode)
;~                  ; Return 1 ; nonzero to not allow the default processing
;~                  Return 0 ; zero to allow the default processing
;~              Case $NM_RCLICK ; The user has clicked the right mouse button within the control
;~                  _DebugPrint("$NM_RCLICK" & @CRLF & "--> hWndFrom:" & @TAB & $hWndFrom & @CRLF & _
;~                          "-->IDFrom:" & @TAB & $iDFrom & @CRLF & _
;~                          "-->Code:" & @TAB & $iCode, $Debugmode)
;~                  ; Return 1 ; nonzero to not allow the default processing
;~                  Return 0 ; zero to allow the default processing
;~              Case $NM_RDBLCLK ; The user has double-clicked the right mouse button within the control
;~                  _DebugPrint("$NM_RDBLCLK" & @CRLF & "--> hWndFrom:" & @TAB & $hWndFrom & @CRLF & _
;~                          "-->IDFrom:" & @TAB & $iDFrom & @CRLF & _
;~                          "-->Code:" & @TAB & $iCode, $Debugmode)
;~                  ; Return 1 ; nonzero to not allow the default processing
;~                  Return 0 ; zero to allow the default processing
;~              Case $NM_KILLFOCUS ; control has lost the input focus
;~                  _DebugPrint("$NM_KILLFOCUS" & @CRLF & "--> hWndFrom:" & @TAB & $hWndFrom & @CRLF & _
;~                          "-->IDFrom:" & @TAB & $iDFrom & @CRLF & _
;~                          "-->Code:" & @TAB & $iCode, $Debugmode)
;~                  ; No return value
;~              Case $NM_RETURN ; control has the input focus and that the user has pressed the key
;~                  _DebugPrint("$NM_RETURN" & @CRLF & "--> hWndFrom:" & @TAB & $hWndFrom & @CRLF & _
;~                          "-->IDFrom:" & @TAB & $iDFrom & @CRLF & _
;~                          "-->Code:" & @TAB & $iCode, $Debugmode)
;~                  ; Return 1 ; nonzero to not allow the default processing
;~                  Return 0 ; zero to allow the default processing
;~                  ; Case $NM_SETCURSOR ; control is setting the cursor in response to a WM_SETCURSOR message
;~                  ; Local $tInfo = DllStructCreate($tagNMMOUSE, $lParam)
;~                  ; $hWndFrom = HWnd(DllStructGetData($tInfo, "hWndFrom"))
;~                  ; $iIDFrom = DllStructGetData($tInfo, "IDFrom")
;~                  ; $iCode = DllStructGetData($tInfo, "Code")
;~                  ; _DebugPrint("$NM_SETCURSOR" & @CRLF & "--> hWndFrom:" & @TAB & $hWndFrom & @CRLF & _
;~                  ; "-->IDFrom:" & @TAB & $iIDFrom & @CRLF & _
;~                  ; "-->Code:" & @TAB & $iCode & @CRLF & _
;~                  ; "-->ItemSpec:" & @TAB & DllStructGetData($tInfo, "ItemSpec") & @CRLF & _
;~                  ; "-->ItemData:" & @TAB & DllStructGetData($tInfo, "ItemData") & @CRLF & _
;~                  ; "-->X:" & @TAB & DllStructGetData($tInfo, "X") & @CRLF & _
;~                  ; "-->Y:" & @TAB & DllStructGetData($tInfo, "Y") & @CRLF & _
;~                  ; "-->HitInfo:" & @TAB & DllStructGetData($tInfo, "HitInfo"))
;~                  ; Return 0 ; to enable the control to set the cursor
;~                  ; Return 1 ; nonzero to prevent the control from setting the cursor
;~              Case $NM_SETFOCUS ; control has received the input focus
;~                  _DebugPrint("$NM_SETFOCUS" & @CRLF & "--> hWndFrom:" & @TAB & $hWndFrom & @CRLF & _
;~                          "-->IDFrom:" & @TAB & $iDFrom & @CRLF & _
;~                          "-->Code:" & @TAB & $iCode, $Debugmode)
;~                  ; No return value
;~              Case $TVN_BEGINDRAGA, $TVN_BEGINDRAGW
;~                  _DebugPrint("$TVN_BEGINDRAG", $Debugmode)
;~              Case $TVN_BEGINLABELEDITA, $TVN_BEGINLABELEDITW
;~                  _DebugPrint("$TVN_BEGINLABELEDIT", $Debugmode)
;~              Case $TVN_BEGINRDRAGA, $TVN_BEGINRDRAGW
;~                  _DebugPrint("$TVN_BEGINRDRAG", $Debugmode)
;~              Case $TVN_DELETEITEMA, $TVN_DELETEITEMW
;~                  _DebugPrint("$TVN_DELETEITEM", $Debugmode)
;~              Case $TVN_ENDLABELEDITA, $TVN_ENDLABELEDITW
;~                  _DebugPrint("$TVN_ENDLABELEDIT", $Debugmode)
;~              Case $TVN_GETDISPINFOA, $TVN_GETDISPINFOW
;~                  _DebugPrint("$TVN_GETDISPINFO", $Debugmode)
;~              Case $TVN_GETINFOTIPA, $TVN_GETINFOTIPW
;~                  _DebugPrint("$TVN_GETINFOTIP", $Debugmode)
;~              Case $TVN_ITEMEXPANDEDA, $TVN_ITEMEXPANDEDW
;~                  _DebugPrint("$TVN_ITEMEXPANDED", $Debugmode)
;~              Case $TVN_ITEMEXPANDINGA, $TVN_ITEMEXPANDINGW
;~                  _DebugPrint("$TVN_ITEMEXPANDING", $Debugmode)
;~              Case $TVN_KEYDOWN
;~                  _DebugPrint("$TVN_KEYDOWN", $Debugmode)
;~              Case $TVN_SELCHANGEDA, $TVN_SELCHANGEDW
;~                  _DebugPrint("$TVN_SELCHANGED", $Debugmode)
;~              Case $TVN_SELCHANGINGA, $TVN_SELCHANGINGW
;~                  _DebugPrint("$TVN_SELCHANGING", $Debugmode)
;~              Case $TVN_SETDISPINFOA, $TVN_SETDISPINFOW
;~                  _DebugPrint("$TVN_SETDISPINFO", $Debugmode)
;~              Case $TVN_SINGLEEXPAND
;~                  _DebugPrint("$TVN_SINGLEEXPAND", $Debugmode)
;~          EndSwitch

    EndSwitch
    Return $GUI_RUNDEFMSG
    EndFunc

func _button_Click($btn_ID)
    Switch $btn_ID
        Case $e_new
            _DebugPrint("Clicked New button" & @LF, $Debugmode)
        case $e_edit
            _DebugPrint("Clicked Edit button" & @LF, $Debugmode)
        Case $e_save
            _DebugPrint("Clicked Save button" & @LF, $Debugmode)
        Case $e_delete
            _DebugPrint("Clicked Delete button" & @LF, $Debugmode)
        Case $e_print
            _DebugPrint("Clicked Print button" & @LF, $Debugmode)
        Case $e_undo
            _DebugPrint("Clicked Undo button" & @LF, $Debugmode)
    EndSwitch
endfunc  ;==>_button_Click

Func _TreeItemFromPoint($hWnd)
    Local $tMPos = _WinAPI_GetMousePos(True, $hWnd)
    Return _GUICtrlTreeView_HitTestItem($hWnd, DllStructGetData($tMPos, 1), DllStructGetData($tMPos, 2))
EndFunc ;==>_TreeItemFromPoint

Func _Drag($hWnd)
    $hTvItemHover = _TreeItemFromPoint($hWnd)
    If $hTvItemHover = 0 Then

    Else ;Entered the Treeview
        $aRect = _GUICtrlTreeView_DisplayRect($hWnd, $hTvItemHover)
        $iTreeY = _WinAPI_GetMousePosY(True, $hWnd)
        Switch $iTreeY
            Case $aRect[1] To $aRect[1]+Int(($aRect[3]-$aRect[1])/4)
                _SendMessage($hWnd, $TVM_SELECTITEM, $TVGN_DROPHILITE, 0) ;remove DropTarget
                $fWhere = -1
            Case 1+$aRect[1]+Int(($aRect[3]-$aRect[1])/3) To $aRect[1]+Int(($aRect[3]-$aRect[1])*2/3)
                _SendMessage($hWnd, $TVM_SELECTITEM, $TVGN_DROPHILITE, $hTvItemHover) ;add DropTarget
                $fWhere = 0
            Case 1+$aRect[1]+Int(($aRect[3]-$aRect[1])*2/3) To $aRect[3]
                _SendMessage($hWnd, $TVM_SELECTITEM, $TVGN_DROPHILITE, 0) ;remove DropTarget
                $fWhere = 1
        EndSwitch
    EndIf
EndFunc ;==>_Drag

Func _Drop($hWndTo, $hWndFrom)
    If $hTvItemHover <> 0 Then
        if _WinAPI_GetClassName($hWndFrom) = "SysListView32" then
            ; Get selected item in the listview
            $tmpItemArr = _GUICtrlListView_GetSelectedIndices($hWndFrom, TRUE)
            $tmpItem = _GUICtrlListView_GetItemText($hWndFrom, $tmpItemArr[1])

            ; Get the selected item in the treeview
            $hSelected_Item = _GUICtrlTreeView_GetSelection($hWndTo)

            $myMSG = "Dragged: " & $tmpItem & @CRLF _
            & "Dropped On: " & _GUICtrlTreeView_GetText($hWndTo, $hTvItemHover)
            _DebugPrint(@CRLF & $myMsg,$Debugmode)
            ; Reset drop target
            _SendMessage(GUICtrlGetHandle($hWndTo), $TVM_SELECTITEM, $TVGN_DROPHILITE, 0) ;remove DropTarget
        EndIf
    Else
        MsgBox(0, "", "No drop target")
    EndIf
EndFunc ;==>_Drop

Func _ScreenOffset($hWnd)
    $aWin1 = WinGetPos($hGuiInner1)
    $aWin2 = WinGetPos($hWnd)
    Local $tPoint = DllStructCreate("int X;int Y")
    local $aCoords[4]
    DllStructSetData($tPoint, "X", 0)
    DllStructSetData($tPoint, "Y", 0)
    _WinAPI_ClientToScreen($hWnd, $tPoint)
    DllStructGetData($tPoint, "X")
    DllStructGetData($tPoint, "Y")

    $aCoords[0] = $awin2[0];Left
    $aCoords[1] = $awin2[1];Top
    $aCoords[2] = $awin2[2]+$aCoords[0];Width + left
    $aCoords[3] = $awin2[3]+$aCoords[1];Height + Top

    return $aCoords
EndFunc   ;==>_ScreenOffset

Func _DebugPrint($sText, $isEnabled, $sLine = @ScriptLineNumber)
    if $isenabled then
        ConsoleWrite(">--------------------------------" & @CRLF & _
        "-->Line(" & StringFormat("%04d", $sLine) & "):" & @TAB & $sText & @CRLF & _
        ">--------------------------------" & @CRLF)
    EndIf
EndFunc ;==>_DebugPrint


#EndRegion functions
Edited by JakeJohnson74

Share this post


Link to post
Share on other sites



This is really weird, normally I get replies to my posts - Wonder why this post is dead?

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

    • AndyS19
      By AndyS19
      I have a listview with 3 columns and I want to set the 3rd column's color based on the item's 'Param' value, but even though I set up for the 3rd column, the entire row always gets the color.
      My test code is below, but here is the pertinent code:
      Func WM_NOTIFY($hWnd, $iMsg, $iwParam, $ilParam) #forceref $hWnd, $iMsg, $iwParam, $ilParam Local $hWndFrom, $iCode, $tNMHDR $tNMHDR = DllStructCreate($tagNMHDR, $ilParam) $hWndFrom = HWnd(DllStructGetData($tNMHDR, "hWndFrom")) $iCode = DllStructGetData($tNMHDR, "Code") Switch $hWndFrom Case $hListView Switch $iCode Case $NM_CUSTOMDRAW Local $iDrawStage, $tCustDraw $tCustDraw = DllStructCreate($tagNMLVCUSTOMDRAW, $ilParam) $iDrawStage = DllStructGetData($tCustDraw, 'dwDrawStage') Switch $iDrawStage Case BitOR(0, $CDDS_ITEMPREPAINT) ;, $CDDS_SUBITEM) setItemColor($tCustDraw, $hWndFrom) Return $CDRF_NOTIFYSUBITEMDRAW EndSwitch EndSwitch EndSwitch Return $GUI_RUNDEFMSG EndFunc ;==>WM_NOTIFY Func setItemColor($tCustDraw, $hWnd) Local $iIndex, $color, $iSubitem $iIndex = DllStructGetData($tCustDraw, 'dwItemSpec') ; item number $color = _GUICtrlListView_GetItemParam($hWnd, $iIndex) $iSubitem = DllStructGetData($tCustDraw, 'iSubItem') ; Here, I want to only change the color of the 3rd col, and not the 1st and 2nd cols DllStructSetData($tCustDraw, 'iSubItem', 2) ; always use the 3rd column (the 'sample' col) logmsg("+++: setItemColor($tCustDraw, 0x" & Hex($hWnd) & ") entered ... " _ & ", $iIndex = " & $iIndex & ", $iSubItem = " & $iSubitem & ", $color = " & Hex($color)) DllStructSetData($tCustDraw, 'clrText', $color) ; set the Text color DllStructSetData($tCustDraw, 'clrTextBk', bitnot($color)) ; set the background color EndFunc ;==>setItemColor Func logmsg($msg, $lnum = @ScriptLineNumber) ConsoleWrite("+++:" & $lnum & ": " & $msg & @CRLF) EndFunc ;==>logmsg
      Here is the full test code:
      #include-once ;#cs #NoTrayIcon #AutoIt3Wrapper_UseUpx=n #AutoIt3Wrapper_Au3Check_Parameters=-d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6 #AutoIt3Wrapper_UseX64=N Opt("GUICloseOnESC", 1) ; ESC closes GUI? (0 = no, 1 = yes) Opt("GUIOnEventMode", 1) ; Change to OnEvent mode Opt('MustDeclareVars', 1) OnAutoItExitRegister("_test_exit") Opt("GUIEventOptions", 1) ;0=default, 1=just notification, 2=GuiCtrlRead tab index Opt("WinTitleMatchMode", -2) ;1=start, 2=subStr, 3=exact, 4=advanced, -1 to -4=Nocase #include <GuiListBox.au3> #include <ListViewConstants.au3> #include <GuiListView.au3> #include <WindowsConstants.au3> #include <GUIConstantsEx.au3> #include <ColorConstants.au3> Global $__MCP_obj, $__MCP_GUI_hWnd, $idListView, $hListView Global $hMainWin test() Exit Func test() $hMainWin = GUICreate("Test window", 120, 100, @DesktopWidth / 2, -1) GUICtrlCreateButton("Hwnd", 10, 10, 40, 20) GUICtrlSetOnEvent(-1, "handle_1stTEST_btn") GUICtrlCreateButton("ID", 50, 10, 40, 20) GUICtrlSetOnEvent(-1, "handle_2ndTEST_btn") GUISetOnEvent($GUI_EVENT_CLOSE, "_test_exit") GUISetState(@SW_SHOW) While (1) Sleep(17) WEnd EndFunc ;==>test Func _myColorPicker($obj) logmsg("+++: $obj = 0x" & Hex($obj) & @CRLF) Local $flags = 0 Local $ww, $wh, $x, $y, $w, $h $__MCP_obj = $obj $ww = 350 $wh = 500 $x = 200 $y = 150 $__MCP_GUI_hWnd = GUICreate("myColorPicker", $ww, $wh, $x, $y, $flags) $x = 10 $y = 10 $w = 150 $h = 20 GUICtrlCreateButton("Set caller's color", $x, $y, $w, $h) GUICtrlSetOnEvent(-1, "__MCP_handle_SetColor_btn") $y += $h + 5 $w = $ww - 25 $h = $wh - 100 $idListView = GUICtrlCreateListView("", $x, $y, $w, $h, -1, BitOR($LVS_EX_GRIDLINES, $LVS_EX_FULLROWSELECT)) $hListView = GUICtrlGetHandle($idListView) $x = $ww / 2 - 50 $y = $wh - 60 $w = 100 $h = 25 GUICtrlCreateButton("Quit Popup", $x, $y, $w, $h) GUICtrlSetOnEvent(-1, "__MCP_handle_QUIT_btn") GUICtrlSetFont($idListView, 8.5, -1, -1, "courier new") _GUICtrlListView_AddColumn($idListView, "Name", 100) _GUICtrlListView_AddColumn($idListView, "Value", 100) _GUICtrlListView_AddColumn($idListView, "Sample", 100) _GUICtrlListView_SetColumnWidth($idListView, 0, 100) _GUICtrlListView_SetColumnWidth($idListView, 1, 80) logmsg("+++: $idListView = " & $idListView) logmsg("+++: $hListView = 0x" & Hex($hListView)) __MCP_populateListView($hListView) GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY") GUISetState(@SW_SHOW, $__MCP_GUI_hWnd) EndFunc ;==>_myColorPicker Func WM_NOTIFY($hWnd, $iMsg, $iwParam, $ilParam) #forceref $hWnd, $iMsg, $iwParam, $ilParam Local $hWndFrom, $iCode, $tNMHDR $tNMHDR = DllStructCreate($tagNMHDR, $ilParam) $hWndFrom = HWnd(DllStructGetData($tNMHDR, "hWndFrom")) $iCode = DllStructGetData($tNMHDR, "Code") Switch $hWndFrom Case $hListView Switch $iCode Case $NM_CUSTOMDRAW Local $iDrawStage, $tCustDraw $tCustDraw = DllStructCreate($tagNMLVCUSTOMDRAW, $ilParam) $iDrawStage = DllStructGetData($tCustDraw, 'dwDrawStage') Switch $iDrawStage Case BitOR(0, $CDDS_ITEMPREPAINT) ;, $CDDS_SUBITEM) setItemColor($tCustDraw, $hWndFrom) Return $CDRF_NOTIFYSUBITEMDRAW EndSwitch EndSwitch EndSwitch Return $GUI_RUNDEFMSG EndFunc ;==>WM_NOTIFY Func setItemColor($tCustDraw, $hWnd) Local $iIndex, $color, $iSubitem $iIndex = DllStructGetData($tCustDraw, 'dwItemSpec') ; item number $color = _GUICtrlListView_GetItemParam($hWnd, $iIndex) $iSubitem = DllStructGetData($tCustDraw, 'iSubItem') ; Here, I want to only change the color of the 3rd col, and not the 1st and 2nd cols DllStructSetData($tCustDraw, 'iSubItem', 2) ; always use the 3rd column (the 'sample' col) logmsg("+++: setItemColor($tCustDraw, 0x" & Hex($hWnd) & ") entered ... " _ & ", $iIndex = " & $iIndex & ", $iSubItem = " & $iSubitem & ", $color = " & Hex($color)) DllStructSetData($tCustDraw, 'clrText', $color) ; set the Text color DllStructSetData($tCustDraw, 'clrTextBk', bitnot($color)) ; set the background color EndFunc ;==>setItemColor Func logmsg($msg, $lnum = @ScriptLineNumber) ConsoleWrite("+++:" & $lnum & ": " & $msg & @CRLF) EndFunc ;==>logmsg Func __MCP_exit() GUIDelete($__MCP_GUI_hWnd) EndFunc ;==>__MCP_exit Func __MCP_handle_SetColor_btn() If (IsHWnd($__MCP_obj)) Then GUISetBkColor($COLOR_BLUE, $__MCP_obj) Else GUICtrlSetBkColor($__MCP_obj, $COLOR_BLUE) EndIf EndFunc ;==>__MCP_handle_SetColor_btn Func __MCP_populateListView($hWnd) Local $text, $parts, $iIndex Local Static $aItems[] = [ _ "BLACK | " & $CLR_BLACK & "|" & "", _ "BLUE | " & $CLR_BLUE & "|" & "", _ "RED | " & $CLR_RED & "|" & "", _ "WHITE | " & $CLR_WHITE & "|" & "", _ "YELLOW | " & $CLR_YELLOW & "|" & "" _ ] _GUICtrlListView_BeginUpdate($hWnd) _GUICtrlListView_DeleteAllItems($hWnd) For $ndx = 0 To UBound($aItems) - 1 $text = $aItems[$ndx] $parts = StringSplit($text, "|", 2) $parts[0] = StringStripWS($parts[0], 3) $parts[2] = StringStripWS($parts[2], 3) $iIndex = _GUICtrlListView_AddItem($hWnd, $parts[0], -1, $parts[1]) _GUICtrlListView_AddSubItem($hWnd, $iIndex, Hex($parts[1]), 1) _GUICtrlListView_AddSubItem($hWnd, $iIndex, $parts[0], 2) Next _GUICtrlListView_EndUpdate($hWnd) EndFunc ;==>__MCP_populateListView Func __MCP_handle_QUIT_btn() GUIDelete($__MCP_GUI_hWnd) EndFunc ;==>__MCP_handle_QUIT_btn Func handle_1stTEST_btn() _myColorPicker($hMainWin) EndFunc ;==>handle_1stTEST_btn Func handle_2ndTEST_btn() _myColorPicker(@GUI_CtrlId) EndFunc ;==>handle_2ndTEST_btn Func _test_exit() Exit EndFunc ;==>_test_exit  
    • nacerbaaziz
      By nacerbaaziz
      Hello guys
      Today I'll give you three functions to manage the list View items
      These functions will help you to do some works in your list view items
      1. list view Read
      To get the selected item text  
      2. listView_checke
      To checke an item
      3. isListViewChecked
      To see if the item is checked
      All of these functions will be illustrated by the following example
      You can download the include file from the link below
      Now with the example
      #include <easy_listView_functions.au3> #include <GUIConstantsEx.au3> #include <GuiListView.au3> #include <MsgBoxConstants.au3> Example() Func Example()  Local $idListview  GUICreate("ListView Get Item Checked State", 1000, 700)  $idListview = GUICtrlCreateListView("", 50, 30, 250, 120, 50)  _GUICtrlListView_SetExtendedListViewStyle($idListview, BitOR($LVS_EX_FULLROWSELECT, $LVS_EX_CHECKBOXES)) ; Add items $item1 = GUICtrlCreateListViewItem("item1", $idListview) $item2 = GUICtrlCreateListViewItem("item2", $idListview) _listview_Checke($idListview, "item1") $btn = GUICtrlCreateButton("&read", 100, 150, 50, 50) $btn2 = GUICtrlCreateButton("&if checked", 100, 200, 100, 50)  GUISetState(@SW_SHOW) while 1 switch GUIGetMSG() case $GUI_EVENT_CLOSE  GUIDelete() exit case $btn $read = _ListView_read($idListView) if $read then msgBox(0, "read listview", $read) else msgBox(0, "read listview", "no text ditected") endIf case $btn2 if _isListviewChecked($idListView, "item1") then msgBox(0, "get", "the item is checked") else msgBox(0, "get", "the item isn't checked") endIf endSwitch wend EndFunc   ;==>Example
       
      easy_listView_functions.au3
    • corgano
      By corgano
      I can't explain easily what i want to do, so i made a picture:

      What i want to do is to specify a treeview item, and then be able to move it right to be a child of the previous item, or left to do the opposite (make a child into a sibling). I also want to move and child items of the target with it, like in the bottom half of the above image depicts. However I didn't see any functions in the help file to move items around. All i want is a button that when pressed, makes the selected item and any of selected item's children move one layer to the right / left. Does anyone know how?

      Edit: something along the lines of _GUICtrlTreeView_Level but SET level
    • dascondor
      By dascondor
      So I having issues with this GUI/Listview. My main GUI works like it needs to but the ListView GUIs don't. The exit buttons do not work on them and om have a hard time getting them to work. And I'm trying to make the  listview GUI resizeable. But I'm not sure how to fix either of these issues any thoughts.
      #include <ButtonConstants.au3> #include <EditConstants.au3> #include <GUIConstantsEx.au3> #include <StaticConstants.au3> #include <WindowsConstants.au3> #include <File.au3> #include <ScreenCapture.au3> #include <MsgBoxConstants.au3> #include <WinAPIFiles.au3> #include <Array.au3> #include <GuiListView.au3> #include <GuiImageList.au3> #include <ListviewConstants.au3> #include 'MultiPing.au3' Opt("GUIOnEventMode", 1) #Region ;Declares ; Reads text file for the base list of IP's Global $aBase_IPlist = _FileReadToArray_mod(".\IP_List.txt") Global $replace2 = "Second" Global $replace3 = "Thrid" ;Global $userdata1 = GUICtrlRead($data1) ;Global $userdata2 = GUICtrlRead($data2) Global $savefolder = "C:\Users\" Global $paths = "\Desktop\PingChecks" Global $1stpaths = "\~~~Store" Global $2ndpaths = "~~~" Global $results = FileExists($savefolder & @UserName & $paths) ;Global $foldercheck = FileExists($savefolder & @UserName & $paths & $1stpaths & $userdata1 & $userdata2 & $2ndpaths) ;Global $savefile = "C:\Users\" & @UserName & "\Desktop\PingChecks\~~~Store" & $userdata1 & $userdata2 & "~~~\" #EndRegion ;Declares #Region ### START Koda GUI section ### Form= $IPMonkey = GUICreate("IP Monkey", 573, 254, -1, -1) GUISetIcon("C:\Users\Dlex\Pictures\monkeyicon.ico", -1) GUISetFont(16, 800, 0, "Arial") GUISetBkColor(0xFFFFFF) GUISetOnEvent($GUI_EVENT_CLOSE, "SpecialEvents") GUISetOnEvent($GUI_EVENT_MINIMIZE, "SpecialEvents") GUISetOnEvent($GUI_EVENT_MAXIMIZE, "SpecialEvents") GUISetOnEvent($GUI_EVENT_RESTORE, "SpecialEvents") $data1 = GUICtrlCreateInput("1", 184, 120, 89, 32, BitOR($GUI_SS_DEFAULT_INPUT, $ES_CENTER)) GUICtrlSetColor(-1, 0x000000) $data2 = GUICtrlCreateInput("23", 280, 120, 89, 32, BitOR($GUI_SS_DEFAULT_INPUT, $ES_CENTER)) GUICtrlSetColor(-1, 0x000000) $GOButton = GUICtrlCreateButton("GO", 80, 192, 75, 25) GUICtrlSetFont(-1, 10, 800, 0, "Arial") GUICtrlSetColor(-1, 0x000000) GUICtrlSetBkColor(-1, 0x00FF00) GUICtrlSetTip(-1, "Runs A Live Continuous Ping" & @CRLF & _ "Until Told Other Wise") GUICtrlSetOnEvent(-1, "GOButtonClick") $quickscan = GUICtrlCreateButton("Quick Scan", 224, 192, 107, 25) GUICtrlSetFont(-1, 12, 800, 0, "Arial") GUICtrlSetColor(-1, 0x000000) GUICtrlSetBkColor(-1, 0xFFFF00) GUICtrlSetOnEvent(-1, "quickscanClick") GUICtrlSetTip(-1, "Quickly Scans, Then Saves" & @CRLF & _ "Results In Your 'PingChecks' " & @CRLF & _ "Folder Under Your Store Number Folder") Global $exitbutton = GUICtrlCreateButton("Exit", 416, 192, 75, 25) GUICtrlSetFont(-1, 12, 800, 0, "Arial") GUICtrlSetColor(-1, 0x000000) GUICtrlSetBkColor(-1, 0xFF0000) GUICtrlSetTip(-1, "What Do You Think This Button Does?") GUICtrlSetOnEvent(-1, "exitbuttonClick") $titlebar = GUICtrlCreateLabel("IP Monkey", 16, 120, 107, 28) GUICtrlSetColor(-1, 0x000000) $Pic1 = GUICtrlCreatePic("C:\Users\Dlex\Pictures\monkeyicon-0.jpg", 16, 16, 100, 100) GUICtrlSetOnEvent(-1, "Pic1Click") $infobutton = GUICtrlCreateButton("?", 536, 8, 27, 25) GUICtrlSetColor(-1, 0x000000) GUICtrlSetBkColor(-1, 0xFF8000) GUICtrlSetTip(-1, "Unsure what to do?" & @CRLF & _ "This will get give you " & @CRLF & _ "the help for IP Monkey") GUICtrlSetOnEvent(-1, "infobuttonClick") $Whatstorelabel = GUICtrlCreateLabel("What Store?", 208, 56, 130, 28) GUICtrlSetColor(-1, 0x000000) GUISetState(@SW_SHOW) #EndRegion ### END Koda GUI section ### #Region ;ping gui ; ------ pinger GUI ------------------- Global $StopPing = 0 Local $Win_X = 1200, $Win_Y = 880 ; dimension of window Global $PingGui = GUICreate("IP Monkey", $Win_X, $Win_Y, -1, -1) GUISetOnEvent($GUI_EVENT_CLOSE, "SpecialEvents") Global $listview = GUICtrlCreateListView("", 10, 10, $Win_X - 20, $Win_Y - 40) GUICtrlSetFont(-1, 8) $button1 = GUICtrlCreateLabel("Hit Exit To Quit", 10, $Win_Y - 25, $Win_X - 20, 20, -1,$ES_CENTER) GUICtrlSetFont(-1, 10, 800) GUICtrlSetTip(-1, "exit") GUICtrlSetOnEvent(-1, 'SpecialEvents') GUICtrlSetStyle($listview, $LVS_ICON) ; + $LVS_NOLABELWRAP) GUISetState(@SW_HIDE) ; hidden at startup ; --------- end of pinger gui ------------- #EndRegion ;ping gui ; Generate colored square images $hImage = _GUIImageList_Create(30, 30) _GUIImageList_Add($hImage, _GUICtrlListView_CreateSolidBitMap($listview, 0xFFFF00, 30, 30)) ; yellow _GUIImageList_Add($hImage, _GUICtrlListView_CreateSolidBitMap($listview, 0xFF0000, 30, 30)) ; red _GUIImageList_Add($hImage, _GUICtrlListView_CreateSolidBitMap($listview, 0x00FF00, 30, 30)) ; green _GUICtrlListView_SetImageList($listview, $hImage, 0) While 1 Sleep(100) WEnd Func exitbuttonClick() MsgBox(0,'0','0') Exit EndFunc ;==>exitbuttonClick Func GOButtonClick() $userdata1 = GUICtrlRead($data1) $userdata2 = GUICtrlRead($data2) ; pass the wanted new octet replace_And_Go($userdata1, $userdata2) ; generate a list of new IP and Go EndFunc ;==>GOButtonClick Func infobuttonClick() EndFunc ;==>infobuttonClick Func Pic1Click() EndFunc ;==>Pic1Click Func quickscanClick() $userdata1 = GUICtrlRead($data1) $userdata2 = GUICtrlRead($data2) replace_And_Go2($userdata1, $userdata2) EndFunc ;==>quickscanClick Func SpecialEvents() Select Case @GUI_CtrlId = $GUI_EVENT_CLOSE _button1() Case @GUI_CtrlId = $GUI_EVENT_MINIMIZE Case @GUI_CtrlId = $GUI_EVENT_RESTORE Case @GUI_CtrlId = $GUI_EVENT_MAXIMIZE EndSelect EndFunc ;==>SpecialEvents #Region ; Main_GO/Replace_and_GO #cs ############################## second script ############################################# ; this is to ping continuously a list of IP addresses, get and display ping result "live" ; it simulates the dos "ping -t" command but performed simultaneously on many IP ; presenting the results in a ListView highlighting not responding devices with a red box #ce Func replace_And_Go($s_2, $s_3) ; Create a new array wit a new list of IP according to passed second and third octet Local $aNew_IPlist = $aBase_IPlist For $i = 0 To UBound($aNew_IPlist) - 1 $aNew_IPlist[$i][1] = StringReplace(StringReplace($aBase_IPlist[$i][1], $replace2, $s_2), $replace3, $s_3) Next GUISetState(@SW_HIDE, $IPMonkey) GUISetState(@SW_SHOW, $PingGui) ; pass the new list to the pinger Main_GO($aNew_IPlist) GUISetState(@SW_HIDE, $PingGui) GUISetState(@SW_SHOW, $IPMonkey) EndFunc ;==>replace_And_Go Func Main_GO($IPlist) HotKeySet("{esc}", "exitbuttonClick") $StopPing = 0 ; $IPlist = _FileReadToArray_mod(".\IP_List.txt") ; Reads text file for list of IP's ; ; the above command, it loads in the $IPlist array the values contained in the file IP_List.txt ; values in the file should be separated by a semicolon, something like in the following example: ; ; hostname1;192.168.0.1 ; hostname2;192.168.0.5 ; hostnameX;10.59.7.200 ; etc.... ; ; if values in the file are not separated by a semicolon, but another char is used, for example a comma, ; then just pass it as second parameter of the function: $IPlist = _FileReadToArray_mod(".\IP_List.txt", ",") ; _GUICtrlListView_BeginUpdate($listview) _GUICtrlListView_DeleteAllItems($listview) _GUICtrlListView_AddArray($listview, $IPlist) ; fill ListView _GUICtrlListView_EndUpdate($listview) While Not $StopPing ; 1 ; continuously ping addresses of the previously loaded file (IP_List.txt) Sleep(10) ; ; $IPlist is the array loaded with all the IP to be pinged (a 2d array in this case) ; | ; | 1 means the IP are in the second column of the $IPlist array (first colun is nr. 0) ; | | ; | | +--> 0 means return back an array loaded with results from all pinged addresses (responding and not responding) ; | | | if you use 1 then only responding addresses are loaded in the returned array [default] ; | | | if you use 2 then only NOT responding addresses are loaded in the returned array ; | | | In this case we do not need an array to be returned, we only need to perform all pings and pass results ; | | | directly (on the fly) to the "_refresh" callback function that will refresh the listview ; | | | ; | | | 0 means NO lookup name resolution must be performed ; | | | | ; | | | | +--> this is the callback function to be called for each pinged address each time the ping has finished ; | | | | | (see the MultiPing.au3 file for info on all passed params) ; | | | | | 6 parameters are passed to this function, but only 2 are used by the called function in this case: ; | | | | | [4] roundtrip of the responding ping or -1 if IP is down ; | | | | | [5] Index (position) of this IP within the caller's passed array ; | | | | | ; v v v v v _nPing($IPlist, 1, 0, 0, "_refresh") WEnd EndFunc ;==>Main_GO #EndRegion ; Main_GO/Replace_and_GO #Region ; QuickScan/Replace_and_GO2 Func replace_And_Go2($s_2, $s_3) ; Create a new array wit a new list of IP according to passed second and third octet Local $aNew_IPlist = $aBase_IPlist For $i = 0 To UBound($aNew_IPlist) - 1 $aNew_IPlist[$i][1] = StringReplace(StringReplace($aBase_IPlist[$i][1], $replace2, $s_2), $replace3, $s_3) Next GUISetState(@SW_HIDE, $IPMonkey) GUISetState(@SW_SHOW, $PingGui) ; pass the new list to the pinger QuickRun($aNew_IPlist) GUISetState(@SW_HIDE, $PingGui) GUISetState(@SW_SHOW, $IPMonkey) EndFunc ;==>replace_And_Go2 Func QuickRun($IPlist) $userdata1 = GUICtrlRead($data1) $userdata2 = GUICtrlRead($data2) HotKeySet("{esc}", "_button1") Local $Win_X = 1200, $Win_Y = 880 ; dimension of window $PingGui = GUICreate("IP Monkey" & "~~~" & @UserName & "~~~" & "Store" & $userdata1 & $userdata2 & "~~~" & @MON & "." & @MDAY & "." & @YEAR & "~~~" & @HOUR & "." & @MIN, $Win_X, $Win_Y, -1, -1) GUISetOnEvent($GUI_EVENT_CLOSE, "_button1", $PingGui) $listview = GUICtrlCreateListView("", 10, 10, $Win_X - 20, $Win_Y - 40) GUICtrlSetFont(-1, 8) GUICtrlSetStyle($listview, $LVS_ICON) ; + $LVS_NOLABELWRAP) ; Generate colored square images $hImage = _GUIImageList_Create(30, 30) _GUIImageList_Add($hImage, _GUICtrlListView_CreateSolidBitMap($listview, 0xFFFF00, 30, 30)) ; yellow _GUIImageList_Add($hImage, _GUICtrlListView_CreateSolidBitMap($listview, 0xFF0000, 30, 30)) ; red _GUIImageList_Add($hImage, _GUICtrlListView_CreateSolidBitMap($listview, 0x00FF00, 30, 30)) ; green _GUICtrlListView_SetImageList($listview, $hImage, 0) $button1 = GUICtrlCreateButton("Exit", 10, $Win_Y - 25, $Win_X - 20, 20) GUICtrlSetTip(-1, "End of program") GUICtrlSetOnEvent(-1, "exitbuttonClick") GUISetState(@SW_SHOW) ;~ $IPlist = _FileReadToArray_mod(".\IP_List.txt") ; Reads text file for list of IP's _GUICtrlListView_BeginUpdate($listview) _GUICtrlListView_AddArray($listview, $IPlist) ; fill ListView _GUICtrlListView_EndUpdate($listview) ;While 1 ; perform Pings and update ListView by the "_refresh" callback function $aFinalResult = _nPing($IPlist, 1, 0, 0, "_refresh") ;~ _ArrayDisplay($aFinalResult) ;DirCheck() EndFunc ;==>QuickRun #EndRegion ; QuickScan/Replace_and_GO2 #Region ; Misc Funcs (network) Func _refresh($Params) ; this receive ping results and displays them in the ListView _GUICtrlListView_SetItemImage($listview, $Params[5], 0) ; set colour to Yellow Sleep(50) ; a little wait If $Params[4] = -1 Then ; Device not responding to ping _GUICtrlListView_SetItemImage($listview, $Params[5], 1) ; set colour to RED _GUICtrlListView_EnsureVisible($listview, $Params[5]) ; Position view to this item Else ; Device responds to ping _GUICtrlListView_SetItemImage($listview, $Params[5], 2) ; set colour to GREEN EndIf EndFunc ;==>_refresh Func _button1() ; Button 1 clicked ;~ $StopPing = 1 Exit EndFunc ;==>_button1 #EndRegion ; Misc Funcs (network)  
      MultiPing.au3
      IP_List.txt
    • perlabsrat
      By perlabsrat
      Hello,
      I found a good drag and drop example here: https://www.autoitscript.com/forum/topic/28062-drop-multiple-files-on-any-control/
      I have been searching but not finding a way to do a variant of this example.
      I want to have a form with 2 or more list box controls on the form that have $GUI_DROPACCEPTED enabled. I then want to be able to drop separate groups of files on each list box  so that I have 2 separate list of dropped items that I can act upon independently rather than this example which only has one target.
      I have modified the example to add the 2nd list box but I am not sure how to determine which control hwnd got the drop event and then only add the files to that list box. In the current example both controls add the files to $hList1
       
      Apparently $hWnd  in WM_DROPFILES_FUNC() is not the control that triggers the event as I compared its value to the hwnd of each control.
      hwnd from $hList1 = 0x002F0BB8 hwnd from $hList2 = 0x003C06E0 hwnd from WM_DROPFILES_FUNC = 0x002F1180 hwnd from WM_DROPFILES_FUNC = 0x002F1180  
      Any ideas?

       
      ;Example from https://www.autoitscript.com/forum/topic/28062-drop-multiple-files-on-any-control/ #include <GUIConstants.au3> ;~ Global $WM_DROPFILES = 0x233 Global $gaDropFiles[1], $str = "" ### Koda GUI section start ### ;~ $hGUI = GUICreate("Test", 400, 200, 219, 178, -1, BitOR($WS_EX_ACCEPTFILES, $WS_EX_TOPMOST)) ;~ $hList = GUICtrlCreateList("", 5, 5, 390, 190) ;~ GUICtrlSetState (-1, $GUI_DROPACCEPTED) Global $hGUI = GUICreate("Test", 573, 419, 219, 178, -1, BitOR($WS_EX_ACCEPTFILES, $WS_EX_TOPMOST, $WS_EX_WINDOWEDGE)) Global $hList1 = GUICtrlCreateList("", 5, 5, 390, 188) GUICtrlSetState(-1, $GUI_DROPACCEPTED) GUICtrlSetData(-1, "List1") Global $hList2 = GUICtrlCreateList("", 42, 205, 390, 188) GUICtrlSetState(-1, $GUI_DROPACCEPTED) GUICtrlSetData(-1, "List2") ConsoleWrite("hwnd from $hList1 = " & GUICtrlGetHandle($hList1) & @CRLF) ConsoleWrite("hwnd from $hList2 = " & GUICtrlGetHandle($hList2) & @CRLF) GUISetState(@SW_SHOW) ### Koda GUI section end ### GUIRegisterMsg($WM_DROPFILES, "WM_DROPFILES_FUNC") While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $GUI_EVENT_DROPPED $str = "" For $i = 0 To UBound($gaDropFiles) - 1 $str &= "|" & $gaDropFiles[$i] Next GUICtrlSetData($hList1, $str) EndSwitch WEnd Func WM_DROPFILES_FUNC($hWnd, $msgID, $wParam, $lParam) ConsoleWrite("hwnd from WM_DROPFILES_FUNC = " & $hGUI & @CRLF) Local $nSize, $pFileName Local $nAmt = DllCall("shell32.dll", "int", "DragQueryFile", "hwnd", $wParam, "int", 0xFFFFFFFF, "ptr", 0, "int", 255) For $i = 0 To $nAmt[0] - 1 $nSize = DllCall("shell32.dll", "int", "DragQueryFile", "hwnd", $wParam, "int", $i, "ptr", 0, "int", 0) $nSize = $nSize[0] + 1 $pFileName = DllStructCreate("char[" & $nSize & "]") DllCall("shell32.dll", "int", "DragQueryFile", "hwnd", $wParam, "int", $i, "ptr", DllStructGetPtr($pFileName), "int", $nSize) ReDim $gaDropFiles[$i + 1] $gaDropFiles[$i] = DllStructGetData($pFileName, 1) $pFileName = 0 Next EndFunc ;==>WM_DROPFILES_FUNC