Jump to content
Sign in to follow this  
Syed26

Reference to _GUICtrlListView_GetItem.au3

Recommended Posts

Syed26

Hi All,

        I am working to create an administrator tool for the client tool which i created with Autoit. for that i want a tool should have an edit option so i am trying to imply the same method used in _GUICtrlListView_GetItem.au3 and modified the code according to mine. but when i try to edit the edit windows is showing somewhere else. Could someone help me on this?

 

Here is my code:

#include "_XMLDomWrapper.au3"
#include <GUIConstantsEx.au3>
#include <GuiListView.au3>
#include <WindowsConstants.au3>
#include <WinAPI.au3>
#include <EditConstants.au3>
#include <GuiEdit.au3>
Opt('MustDeclareVars', 1)
Global $GUI, $Label1, $Label2, $msg, $OSArc, $OSDDown, $option, $Label3, $Button, $hListView, $64corecount, $64XMLOpen, $Comment, $RegKey
Global $hEdit, $hDC, $hBrush, $Item = -1, $SubItem = 0

Global $Style = BitOR($WS_CHILD, $WS_VISIBLE, $ES_AUTOHSCROLL, $ES_LEFT)
$GUI = GUICreate("ListView Get Item", 600, 700, -1, -1, BitOR($WS_MINIMIZEBOX, $WS_GROUP, $WS_CAPTION, $WS_POPUP, $WS_SYSMENU))
$Label1 = GUICtrlCreateLabel("Select Operating System", 15, 30, 180, 60)
$OSDDown = GUICtrlCreateCombo("Win 7", 225, 25, 150, 60)
GUICtrlSetData(-1, "Win 8")
$Label2 = GUICtrlCreateLabel("Select OS Architecture", 15, 100, 180, 60)
$OSArc = GUICtrlCreateCombo("64 Bit", 225, 95, 150, 60)
GUICtrlSetData(-1, "32 Bit")
$Label3 = GUICtrlCreateLabel("Select your option", 15, 175, 180, 60)
$option = GUICtrlCreateCombo("Core Applications", 225, 170, 150, 60)
GUICtrlSetData(-1, "Optional Application|Customization")
$Button = GUICtrlCreateButton("Load", 450, 85, 90, 40)
GUISetState()

GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY")
GUIRegisterMsg($WM_COMMAND, "WM_COMMAND")
While 1
    $msg = GUIGetMsg()

    If $msg = $GUI_EVENT_CLOSE Then ExitLoop
    
    If $msg = $Button Then
        $hListView = _GUICtrlListView_Create ($GUI, "App Name|Path", 2, 280, 576, 396, BitOR($LVS_EDITLABELS, $LVS_REPORT))
        _GUICtrlListView_SetColumnWidth ($hListView, 0, 180)
        _GUICtrlListView_SetColumnWidth ($hListView, 1, $LVSCW_AUTOSIZE_USEHEADER)
        _GUICtrlListView_SetExtendedListViewStyle ($hListView, $LVS_EX_GRIDLINES)
        action ()
    EndIf
    
WEnd

Func action ()
    GUICtrlSetState($Button, $GUI_DISABLE)
    
    If GUICtrlRead($OSDDown) = "Win 7"  And GUICtrlRead($OSArc) = "64 Bit"  Then
        
        $64XMLOpen = _XMLFileOpen (@DesktopDir&"\CoreApps.xml")
        
        $64corecount = _XMLGetNodeCount ("/root/Application")
        
        For $i = 1 To $64corecount Step + 1
            $Comment = _XMLGetChildText ("/root/Application[" & $i & "]/Name")
            $RegKey = _XMLGetChildText ("/root/Application[" & $i & "]/Location")
            
            _GUICtrlListView_AddItem ($hListView, $Comment[1])
            _GUICtrlListView_AddSubItem ($hListView, $i - 1, $RegKey[1], 1)
        Next
    EndIf
EndFunc   ;==>action

Func WM_NOTIFY ($hWnd, $iMsg, $iwParam, $ilParam)
    Local $tNMHDR, $hWndFrom, $iCode

    $tNMHDR = DllStructCreate($tagNMHDR, $ilParam)
    $hWndFrom = DllStructGetData($tNMHDR, "hWndFrom")
    $iCode = DllStructGetData($tNMHDR, "Code")

    Switch $hWndFrom
        Case $hListView
            Switch $iCode
                Case $NM_DBLCLK
                    Local $aHit = _GUICtrlListView_SubItemHitTest ($hListView)

                    If ($aHit[0] <> -1) And ($aHit[1] = 0) Then
                        $Item = $aHit[0]
                        $SubItem = 0
                        Local $aRect = _GUICtrlListView_GetItemRect ($hListView, $Item)
                    ElseIf ($aHit[0] <> -1) And ($aHit[1] > 0) Then
                        $Item = $aHit[0]
                        $SubItem = $aHit[1]
                        Local $aRect = _GUICtrlListView_GetSubItemRect ($hListView, $Item, $SubItem)
                    Else
                        Return $GUI_RUNDEFMSG
                    EndIf

                    Local $iItemText = _GUICtrlListView_GetItemText ($hListView, $Item, $SubItem)
                    Local $iLen = _GUICtrlListView_GetStringWidth ($hListView, $iItemText)
                    ;$hEdit = _GUICtrlEdit_Create ($GUI, $iItemText, $aRect[0] + 3, $aRect[1], $iLen + 10, 17, $Style)
                    $hEdit = _GUICtrlEdit_Create ($GUI, $iItemText, $aRect[0] + 3, $aRect[1], $iLen + 10, 17, $Style)

                    _GUICtrlEdit_SetSel ($hEdit, 0, -1)
                    _WinAPI_SetFocus ($hEdit)
                    $hDC = _WinAPI_GetWindowDC ($hEdit)
                    $hBrush = _WinAPI_CreateSolidBrush (0x0000FF)
                    FrameRect($hDC, 0, 0, $iLen + 10, 17, $hBrush)
            EndSwitch
    EndSwitch
    Return $GUI_RUNDEFMSG
EndFunc   ;==>WM_NOTIFY

Func FrameRect($hDC, $nLeft, $nTop, $nRight, $nBottom, $hBrush)
    Local $stRect = DllStructCreate("int;int;int;int")

    DllStructSetData($stRect, 1, $nLeft)
    DllStructSetData($stRect, 2, $nTop)
    DllStructSetData($stRect, 3, $nRight)
    DllStructSetData($stRect, 4, $nBottom)

    DllCall("user32.dll", "int", "FrameRect", "hwnd", $hDC, "ptr", DllStructGetPtr($stRect), "hwnd", $hBrush)
EndFunc   ;==>FrameRect

Func WM_COMMAND($hWnd, $msg, $wParam, $lParam)
    Local $iCode = BitShift($wParam, 16)

    Switch $lParam
        Case $hEdit
            Switch $iCode
                Case $EN_KILLFOCUS
                    Local $iText = _GUICtrlEdit_GetText ($hEdit)
                    _GUICtrlListView_SetItemText ($hListView, $Item, $iText, $SubItem)
                    _WinAPI_DeleteObject ($hBrush)
                    _WinAPI_ReleaseDC ($hEdit, $hDC)
                    _WinAPI_DestroyWindow ($hEdit)

                    $Item = -1
                    $SubItem = 0
            EndSwitch
    EndSwitch

    Return $GUI_RUNDEFMSG
EndFunc   ;==>WM_COMMAND

Here is my XML File:

- <root>
- <Application>
  <Name>Adobe Flash Player</Name> 
  <Location>\Macromed\Flash\FlashUtil32_11_8_800_94_ActiveX.exe</Location> 
  </Application>
- <Application>
  <Name>Adobe Reader</Name> 
  <Location>\Adobe\Reader 11.0\Reader\AcroRd32.exe</Location> 
  </Application>
  </root>

I downloaded the XML Dom Wrapper UDF file from the below link.

'?do=embed' frameborder='0' data-embedContent>>

Edited by Syed26

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  

×