Jump to content

Recommended Posts


Hello all
I have a question please
this  a question is about the context menu
When i create a list box  Or combo box
if i create a context menu for this list
When i press the application key or the shortcut shift + f10
the menu options is appear normally
but When i create a List view
if i create a context menu for this list
When i press the application key or the shortcut shift + f10
the menu options isn't appear
But the right mouse button works normally
I need a solution please because I deal with the screen readers users
Unfortunately They can not use the mouse to navigate
So I have to find a solution to activate keyboard shortcuts
am waiting  for your help

Edited by nacerbaaziz
Link to post
Share on other sites
  • Moderators

@nacerbaaziz you know what comes next, you need to provide code that shows the issue you are encountering.

"Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball

How to get your question answered on this forum!

Link to post
Share on other sites

hello again
this is my example
When i press the application key or the shortcut shift + f10
the menu options isn't appear
But the right mouse button works normally


#include <GUIConstants.au3>
#include <WindowsConstants.au3>
#include <Array.au3>
#include <GuiListView.au3>
main()
func main()
local $GUI = GUICreate("listView context menu", 800, 400, @DesktopWidth / 2 - 192, @DesktopHeight / 2 - 235, -1, $WS_EX_ACCEPTFILES + $WS_EX_TOPMOST)
global $list = GUICtrlCreateListView("", 0, 10, 700, 150, bitOr($LVS_SINGLESEL,$LVS_SORTASCENDING))

    _GUICtrlListView_AddColumn($list, "Name", 150, 0)
    _GUICtrlListView_AddColumn($list, "version", 50, 0)
    _GUICtrlListView_AddColumn($list, "Publisher", 150, 0)
    _GUICtrlListView_AddColumn($list, "Uninstall file path", 400, 0)
local $menu = GUICtrlCreateContextMenu($list)
local $Ref = GUICtrlCreateMenuItem("refresh", $menu)
local $Unins = GUICtrlCreateMenuItem("Uninstall", $menu)
Unins_refresh()
GUISetState(@sw_Show, $GUI)
while 1
Switch GUIGetMSG()
case $GUI_Event_Close
exit
case $Ref
Unins_refresh()
case $Unins
            $selecteditem = _GUICtrlListView_GetItemTextString($list, Int(_GUICtrlListView_GetSelectedIndices($list)))
            $selecteditemarray = StringSplit($selecteditem, "|")

Dim $iMsgBoxAnswer
$iMsgBoxAnswer = MsgBox(4132,"uninstall " &             $selecteditemarray[1] & "?","are you sure want to uninstall " &             $selecteditemarray[1] & " version" &             $selecteditemarray[2] & "?")
Select
   Case $iMsgBoxAnswer = 6 ;Yes

run($selecteditemarray[4])
EndSelect

EndSwitch
Wend
endFunc
Func Unins_refresh()
    _GUICtrlListView_DeleteAllItems($list)
    ProgressOn("Uninstall Manager", "Loading...", "0%")

local $r_var, $r_hash = 0, $UninsName = "", $UnInsPath = "", $UninsVersion = "", $UninsPublisher = "", $SystemComponent
local $RegKey = "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall"
    While 1
        $r_hash += 1
        $r_var = RegEnumKey($regKey, $r_hash)
        If @error <> 0 Then
$r_var = ""
$r_hash = 0
$UninsName = ""
$UnInsPath = ""
$UninsVersion = ""
$UninsPublisher = ""
            ExitLoop

        Else
        $r_var = $Regkey & "\" &         $r_var
$UNinsName = RegRead($r_var, "DisplayName")
if @error then $UNinsName = ""
$UNinsVersion = RegRead($r_var, "DisplayVersion")
if @error then $UNinsVersion = ""
$UninsPublisher = RegRead($r_var, "Publisher")
if @error then $UninsPublisher = ""
$UNinsPath = RegRead($r_var, "UninstallString")
if @error then $UNinsPath = ""
$SystemComponent = RegRead($r_var, "SystemComponent")
if @error then $SystemComponent = 0
if not ($UninsPath = "") and not ($UninsName = "") and not ($SystemComponent = 1) then
            GUICtrlCreateListViewItem($UninsName & "|" & $UninsVersion & "|" & $UninsPublisher & "|" & $UninsPath, $list)
endIf
        EndIf
    WEnd
$RegKey = "HKCU\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall"
    While 1
        $r_hash += 1
        $r_var = RegEnumKey($regKey, $r_hash)
        If @error <> 0 Then
$r_var = ""
$r_hash = 0
$UninsName = ""
$UnInsPath = ""
$UninsVersion = ""
$UninsPublisher = ""
            ExitLoop

        Else
        $r_var = $Regkey & "\" &         $r_var
$UNinsName = RegRead($r_var, "DisplayName")
if @error then $UNinsName = ""
$UNinsVersion = RegRead($r_var, "DisplayVersion")
if @error then $UNinsVersion = ""
$UninsPublisher = RegRead($r_var, "Publisher")
if @error then $UninsPublisher = ""
$UNinsPath = RegRead($r_var, "UninstallString")
if @error then $UNinsPath = ""
$SystemComponent = RegRead($r_var, "SystemComponent")
if @error then $SystemComponent = 0
if not ($UninsPath = "") and not ($UninsName = "") and not ($SystemComponent = 1) then
            GUICtrlCreateListViewItem($UninsName & "|" & $UninsVersion & "|" & $UninsPublisher & "|" & $UninsPath, $list)
endIf
        EndIf
WEnd
###
if @OSArch = "x64" then
$RegKey = "HKLM64\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall"
    While 1
        $r_hash += 1
        $r_var = RegEnumKey($regKey, $r_hash)
        If @error <> 0 Then
$r_var = ""
$r_hash = 0
$UninsName = ""
$UnInsPath = ""
$UninsVersion = ""
$UninsPublisher = ""
            ExitLoop

        Else
        $r_var = $Regkey & "\" &         $r_var
$UNinsName = RegRead($r_var, "DisplayName")
if @error then $UNinsName = ""
$UNinsVersion = RegRead($r_var, "DisplayVersion")
if @error then $UNinsVersion = ""
$UninsPublisher = RegRead($r_var, "Publisher")
if @error then $UninsPublisher = ""
$UNinsPath = RegRead($r_var, "UninstallString")
if @error then $UNinsPath = ""
$SystemComponent = RegRead($r_var, "SystemComponent")
if @error then $SystemComponent = 0
if not ($UninsPath = "") and not ($UninsName = "") and not ($SystemComponent = 1) then
            GUICtrlCreateListViewItem($UninsName & "|" & $UninsVersion & "|" & $UninsPublisher & "|" & $UninsPath, $list)
endIf
        EndIf
WEnd
$RegKey = "HKCU64\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall"
    While 1
        $r_hash += 1
        $r_var = RegEnumKey($regKey, $r_hash)
        If @error <> 0 Then
$r_var = ""
$r_hash = 0
$UninsName = ""
$UnInsPath = ""
$UninsVersion = ""
$UninsPublisher = ""
            ExitLoop

        Else
        $r_var = $Regkey & "\" &         $r_var
$UNinsName = RegRead($r_var, "DisplayName")
if @error then $UNinsName = ""
$UNinsVersion = RegRead($r_var, "DisplayVersion")
if @error then $UNinsVersion = ""
$UninsPublisher = RegRead($r_var, "Publisher")
if @error then $UninsPublisher = ""
$UNinsPath = RegRead($r_var, "UninstallString")
if @error then $UNinsPath = ""
$SystemComponent = RegRead($r_var, "SystemComponent")
if @error then $SystemComponent = 0
if not ($UninsPath = "") and not ($UninsName = "") and not ($SystemComponent = 1) then

            GUICtrlCreateListViewItem($UninsName & "|" & $UninsVersion & "|" & $UninsPublisher & "|" & $UninsPath, $list)
endIf
        EndIf
WEnd
endIf
endFunc


:)
Please help me

Edited by nacerbaaziz
Link to post
Share on other sites

I recently encountered a similar issue with trying to allow update on arrow up and down in a list view

same thing should help you as well

Global $g_hList1 = GUICtrlCreateListView("#|x|y", 5, 24, 161, 201, $LVS_SHOWSELALWAYS Or $LVS_SINGLESEL)
Global $g_hList1_LVN = GUICtrlCreateDummy() ;listview notifications

GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY")

;Event loop etc....
If GuiGetMsg() == $g_hList1_LVN Then
            ;Your Code
EndIf
;;;.................................

Func WM_NOTIFY($hWnd, $iMsg, $wParam, $lParam)
    Static Local $hWndList1 = GUICtrlGetHandle($g_hList1)
    If Not IsHWnd($hWndList1) Then $hWndList1 = GUICtrlGetHandle($g_hList1)
    If @error Then Return $GUI_RUNDEFMSG
    If $wParam = $g_hList1 Then
        Local $tNMHDR = DllStructCreate($tagNMHDR, $lParam)

        Switch DllStructGetData($tNMHDR, "Code")

            Case $LVN_KEYDOWN, $NM_CLICK
                GUICtrlSendToDummy($g_hList1_LVN, $lParam)
        EndSwitch
    EndIf

    Return $GUI_RUNDEFMSG
EndFunc   ;==>WM_NOTIFY
































































;

To see it in full context check here:

You also don't really need the dummy control but I wanted to receive an even in my event loop and handle it there rather than in the WM_Notify callback

Noticed I saved the listview handle as well; It seems that sometimes it takes forever for the GUICtrlGetHandle() function to return...

Edited by Bilgus
Made the code post Long so you can use the popup button to get it in a separate window
Link to post
Share on other sites

Basically you don't get notifications for keypress in the list view so you register a callback for WM_NOTIFY and look for the handle of the listview

This calls the dummy control when it gets a key even or mouse click

in the event for the dummy control you check for a mouse right click or keyboard key and pop your menu

If you want more code than that follow the link and you can see the code in action for the arrow keys

I put the code for DrawPathPoints in a file for you in the example code post..

Edited by Bilgus
Link to post
Share on other sites
  • Moderators

You have all that code, but don't understand 18 lines that were provided to you? Are you just copying your code from somewhere, without actually understanding what how it works?

"Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball

How to get your question answered on this forum!

Link to post
Share on other sites
  • 3 weeks later...

hiI understand the code,
but let's say I have more than one list view in the same GUI
so how can I do each list view its own context menu
This is the code that I do, please help me to adjust it.
I apologize for my difficulty in understanding.

#include <Misc.au3>
#include <ListViewConstants.au3>
#include <GUIConstants.au3>
Global $GUI = GUICreate("test")
Global $g_hList1 = GUICtrlCreateListView("#|x|y", 5, 24, 161, 70, $LVS_SHOWSELALWAYS Or $LVS_SINGLESEL)
Global $g_hList1_LVN = GUICtrlCreateDummy()
Global $context = GUICtrlCreateContextMenu($g_hList1_LVN)
GUICtrlCreateMenuItem("1", $context)
GUICtrlCreateMenuItem("2", $context)

Global $g_hList2 = GUICtrlCreateListView("#|x|y", 5, 100, 161, 70, $LVS_SHOWSELALWAYS Or $LVS_SINGLESEL)
Global $g_hList2_LVN = GUICtrlCreateDummy()
Global $context2 = GUICtrlCreateContextMenu($g_hList2_LVN)
GUICtrlCreateMenuItem("3", $context2)
GUICtrlCreateMenuItem("4", $context2)

GUISetState()
GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY")
While 1
    Switch GUIGetMsg()
        Case $gui_event_close
            Exit
        Case $g_hList1_LVN
            ShowMenu($GUI, GUIGetMsg(), $context)
    EndSwitch
WEnd
Func WM_NOTIFY($hWnd, $iMsg, $wParam, $lParam)
    Static Local $hWndList1 = GUICtrlGetHandle($g_hList1)
    If Not IsHWnd($hWndList1) Then $hWndList1 = GUICtrlGetHandle($g_hList1)
    If @error Then Return $GUI_RUNDEFMSG
    If $wParam = $g_hList1 Then
        Local $tNMHDR = DllStructCreate($tagNMHDR, $lParam)
        Switch DllStructGetData($tNMHDR, "Code")
            Case $LVN_KEYDOWN, $NM_CLICK
                If _IsPressed("02") Or _IsPressed("5D") Then
                    GUICtrlSendToDummy($g_hList1_LVN, $lParam)
                EndIf
        EndSwitch
    EndIf
    Return $GUI_RUNDEFMSG
EndFunc   ;==>WM_NOTIFY
Func ShowMenu($hWnd, $idCtrl, $idContext)
    Local $aPos, $x, $y
    Local $hMenu = GUICtrlGetHandle($idContext)

    $aPos = ControlGetPos($hWnd, "", $idCtrl)

    $x = $aPos[0]
    $y = $aPos[1] + $aPos[3]

    ClientToScreen($hWnd, $x, $y)
    TrackPopupMenu($hWnd, $hMenu, $x, $y)
EndFunc   ;==>ShowMenu

; Convert the client (GUI) coordinates to screen (desktop) coordinates
Func ClientToScreen($hWnd, ByRef $x, ByRef $y)
    Local $tPoint = DllStructCreate("int;int")

    DllStructSetData($tPoint, 1, $x)
    DllStructSetData($tPoint, 2, $y)

    DllCall("user32.dll", "int", "ClientToScreen", "hwnd", $hWnd, "struct*", $tPoint)

    $x = DllStructGetData($tPoint, 1)
    $y = DllStructGetData($tPoint, 2)
    ; release Struct not really needed as it is a local
    $tPoint = 0
EndFunc   ;==>ClientToScreen

; Show at the given coordinates (x, y) the popup menu (hMenu) which belongs to a given GUI window (hWnd)
Func TrackPopupMenu($hWnd, $hMenu, $x, $y)
    DllCall("user32.dll", "int", "TrackPopupMenuEx", "hwnd", $hMenu, "int", 0, "int", $x, "int", $y, "hwnd", $hWnd, "ptr", 0)
EndFunc   ;==>TrackPopupMenu

@Bilgus

Edited by Jos
added codebox ... please use that in the future and tidied code
Link to post
Share on other sites

There is the bare minimum for what you want

#include <Misc.au3>
#include <ListViewConstants.au3>
#include <GUIConstants.au3>
#include <GuiMenu.au3>

Global $GUI = GUICreate("test")
Global $g_iTemp
Global $g_hList1 = GUICtrlCreateListView("#|x|y", 5, 24, 161, 70, $LVS_SHOWSELALWAYS Or $LVS_SINGLESEL)
GUICtrlCreateListViewItem("text", $g_hList1)
Global $g_hList1_LVN = GUICtrlCreateDummy()

Global $context = GUICtrlCreateContextMenu($g_hList1)
GUICtrlCreateMenuItem("1", $context)
GUICtrlCreateMenuItem("2", $context)

Global $g_hList2 = GUICtrlCreateListView("#|x|y", 5, 100, 161, 70, $LVS_SHOWSELALWAYS Or $LVS_SINGLESEL)
GUICtrlCreateListViewItem("text", $g_hList2)
Global $g_hList2_LVN = GUICtrlCreateDummy()
Global $context2 = GUICtrlCreateContextMenu($g_hList2)
GUICtrlCreateMenuItem("3", $context2)
GUICtrlCreateMenuItem("4", $context2)

GUISetState()
GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY")
While 1
    Switch GUIGetMsg()
        Case $gui_event_close
            Exit
        Case $g_hList1_LVN ;This is just a dummy it only recieves events
            ConsoleWrite("LV1 EVENT" & @CRLF)
            $g_iTemp = GUICtrlRead($g_hList1_LVN) ;Retrieve the code that WM_NOTIFY SENT
            If $g_iTemp = $LVN_KEYDOWN Then
                If _IsPressed("79") And (_IsPressed("A0") Or _IsPressed("A1")) Then ;Right/ Left Shift & F10
                    ShowMenu($GUI, $g_hList1, $context)
                Else
                    ConsoleWrite("Some Other Keys" & @CRLF)
                EndIf
            Else
                ConsoleWrite("Some Other Event" & @CRLF)
            EndIf
        Case $g_hList2_LVN
            ConsoleWrite("LV2 EVENT" & @CRLF)
            $g_iTemp = GUICtrlRead($g_hList1_LVN)
            If $g_iTemp = $LVN_KEYDOWN Then
                If _IsPressed("79") And (_IsPressed("A0") Or _IsPressed("A1")) Then ;Right/ Left Shift & F10
                    ShowMenu($GUI, $g_hList2, $context2)
                EndIf
            EndIf
    EndSwitch
WEnd
Func WM_NOTIFY($hWnd, $iMsg, $wParam, $lParam)
    Local $tNMHDR, $iCode ;
    Switch $wParam
        Case $g_hList1
            $tNMHDR = DllStructCreate($tagNMHDR, $lParam)
            $iCode = DllStructGetData($tNMHDR, "Code")
            Switch $iCode
                Case $LVN_KEYDOWN, $NM_CLICK
                    GUICtrlSendToDummy($g_hList1_LVN, $iCode) ;send the code back to be processed by the dummy
            EndSwitch
        Case $g_hList2
            $tNMHDR = DllStructCreate($tagNMHDR, $lParam)
            $iCode = DllStructGetData($tNMHDR, "Code")
            Switch $iCode
                Case $LVN_KEYDOWN, $NM_CLICK
                    GUICtrlSendToDummy($g_hList2_LVN, $iCode)
            EndSwitch
    EndSwitch
    Return $GUI_RUNDEFMSG
EndFunc   ;==>WM_NOTIFY

Func ShowMenu($hWnd, $idCtrl, $idContext)
    Local $aPos, $x, $y
    Local $hMenu = GUICtrlGetHandle($idContext)

    $aPos = ControlGetPos($hWnd, "", $idCtrl)

    $x = $aPos[0]
    $y = $aPos[1] + $aPos[3]

    ClientToScreen($hWnd, $x, $y)
    TrackPopupMenu($hWnd, $hMenu, $x, $y)
EndFunc   ;==>ShowMenu

; Convert the client (GUI) coordinates to screen (desktop) coordinates
Func ClientToScreen($hWnd, ByRef $x, ByRef $y)
    Local $tPoint = DllStructCreate("int;int")

    DllStructSetData($tPoint, 1, $x)
    DllStructSetData($tPoint, 2, $y)

    DllCall("user32.dll", "int", "ClientToScreen", "hwnd", $hWnd, "struct*", $tPoint)

    $x = DllStructGetData($tPoint, 1)
    $y = DllStructGetData($tPoint, 2)
    ; release Struct not really needed as it is a local
    $tPoint = 0
EndFunc   ;==>ClientToScreen

; Show at the given coordinates (x, y) the popup menu (hMenu) which belongs to a given GUI window (hWnd)
Func TrackPopupMenu($hWnd, $hMenu, $x, $y)
    ;DllCall("user32.dll", "int", "TrackPopupMenuEx", "hwnd", $hMenu, "int", 0, "int", $x, "int", $y, "hwnd", $hWnd, "ptr", 0)
    _GUICtrlMenu_TrackPopupMenu($hMenu, $hWnd, $x, $y)
EndFunc   ;==>TrackPopupMenu

 

Edited by Bilgus
Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    No registered users viewing this page.

  • Similar Content

    • By nacerbaaziz
      hello guys, please i need your help
      am trying to work with CreateWindowEx api, i created the window with it controls, also i setup the call back function
      i'am using WinMSGLoop to focus with the keyboard.
      here i have a problem, i hope that you can help me.
      on the controls i used the UDF that comme with the autoit, such as _GUIButton_Create, _GUIListBox_Create....
      but i can't find a STATIC control UDF, for that i used this

      local $h_ssrvlbl = _WinAPI_CreateWindowEx(0, "STATIC", "الخادم", BitOr($WS_VISIBLE, $WS_CHILD, $WS_CLIPSIBLINGS, $WS_CLIPCHILDREN), 250, 10, 100, 20, $hWnd)
      as you can see here, there is an arabic text, so here is the problem, the arabic text isn't show normally, what is the problem here?
      also i have  an other question about keyboard focus, when i used WinMSGLoop, it worked, but if i press alt+tab to switch windows or focus an other window and return back to my window, the focus of control is kill.
      can any one help me to solve that please?
      my code will be as file here with the include files
      i hope can any one help me here
      thanks in advance
       
      speed Test win.zip
    • By MarkBuchanan
      Hello,

      I am new to AutoIt so please bare with me. I am trying to write a script that installs a certain program on Win 10 and then based on a successful install create a file in a specific directory. Below is my install script which works, just not quite sure how to get it to write the file when its done. My thought is to add a "If FileExists" command at the end to make sure that the files are in the install folder and based on that write the file just not sure how to accomplish it. I hope that makes sense and thank you in advance for any help. 
       
      Local $Title="MobilePass Install"
      Local $FilePATH="\\XXXXXXX\XXXXXX"
      Local $UserName "*****8"
      Local $Password = "*******8"   ;Check if Application location already exists
      If FileExists ("C:\Program Files\WindowsApps\05EB1CFA.SafeNetMobilePASS_1.8.3.0_x64__bnm8hg3x9na9j") Then
      Exit
      Else
      Local $pid = RunAsWait ($UserName, $ComputerDomainName, $Password, 1, "MobilePASS+Setup_1.8.3.0_signed.exe", "", @SW_HIDE )
      Endif
       
    • By UEZ
      This project has been discontinued!
       
      Here a small tool I wrote to update my Sysinternal tools collection without the need to download always the whole package or visiting the site to check for updates. I know that there are several tools available (also some tools written in AutoIt) but here another one for the collection. It was good exercise for me to code it.
       
       
        
       
       
      Some files from the live web site cannot be downloaded although they are visible!
       
      Here the download link of the source code only: AutoIt Sysinternal Tools Synchronizer v0.99.6 build 2020-09-23 beta.7z  (1557 downloads previously)
      -=> Requires AutoIt version 3.3.13.20 or higher / tested on Win8.1 real machine and some VMs: Win7 / Vista / Win10
       
      Compiled exe only: @MediaFire
       
      Just select the Sysinternal Tools folder or create one and press the synchronize button to download the selected items. Click on AutoIt label (near to left upper corner) to open menu.
       
      Special thanks to LarsJ, Melba23 and mesale0077 for their help. 
       
      I've still some ideas to implement which are more gimmick related, so it is not finished yet...
      If you want to add your language please check out #Region Language. Thanks. 
       
      Please report any bug or if you have any suggestions.
       
      The language of the tool tip from each of the executable in the left list view were automatically created using Google translator and weren't checked for correctness.
       
      Br,
      UEZ
    • By Cengokill
      Hi everyone,
      I have created a ListView that is in a tab, and I want to display an image in that tab, with the ListView on top.
      However, the image still appears on top of my ListView.
      If I remove the tabs everything works. 
      I looked at the autoit documentation and the <GuiListView.au3> documentation , I can't figure out how to display a background image, and put on top a ListView, inside a tab. 😥
      Here is the code:
      Opt("GUIOnEventMode", 1) $Form1 = GUICreate($Titre, 700, 627, $Form1Width, $Form1Height); main window $tabulation = GUICtrlCreateTab(148,0,700,580); creating tabs $tab1=GUICtrlCreateTabItem("Tab 1"); first tab GUICtrlSetState(-1, $GUI_SHOW); this tab is selected by default $Pic1 = GUICtrlCreatePic("image.jpg", 0, 30, 700, 627) GUICtrlSetState(-1, $GUI_DISABLE). $idListview = GUICtrlCreateListView("list 1|list 2|list 3", 200, 50, 390, 200) GUISetState(@SW_SHOW) While 1     Sleep(100) WEnd Thank you in advance.

    • By DrJohn
      Hello all.  It's me again.
      I've got a ListView with an associated ImageList to display icons.  What I seem to be hung up on is how to keep the ImageList updated to match the ListView as the latter changes.  I thought it was the case that the indices of the items in the ListView and those in the ImageList just needed to match.  So, for example, if I:
      Delete an item from the ListView [_GUICtrlListView_DeleteItem()], and also delete the image at the matching index in the ImageList [_GUIImageList_Remove()]. Then add a new item to the end of the ListView [_GUICtrlListView_AddItem()], and correspondingly add an image at the end of the ImageList [_GUIImageList_AddIcon()] Shouldn't everything stay in sync?
      Here's the code I thought would work:
      #include <GUIConstantsEx.au3> #include <GuiListView.au3> #include <FontConstants.au3> #include <WindowsConstants.au3> #include <GuiImageList.au3> Test() func Test() $gui = GUICreate("Test", 400, 300) ; Create ListView $lv = _GUICtrlListView_Create($gui, "", 10, 10, 380, 240, $LVS_DEFAULT) _GUICtrlListView_AddColumn($lv, "Col1", 50) _GUICtrlListView_AddColumn($lv, "Col2", 50) for $i = 0 to 2 $s = StringFormat("%d,1", $i+1) _GUICtrlListView_AddItem($lv, $s, $i) $s = StringFormat("%d,2", $i+1) _GUICtrlListView_AddSubItem($lv, $i, $s, 1) next ; Add ImageList $img_list = _GUIImageList_Create(16, 16, 5, 3) for $i = 0 to 2 $ico = StringFormat("%d.ico", $i+1) _GUIImageList_AddIcon($img_list, $ico) next _GUICtrlListView_SetImageList($lv, $img_list, 1) ; $btn = GUICtrlCreateButton("Test", 10, 260, 60, 30) GUISetState(@SW_SHOW) HotKeySet("^q", Quit) ; Loop until the user exits. while True switch GUIGetMsg() case $GUI_EVENT_CLOSE Exit case $btn ; Remove 2nd list item and image _GUICtrlListView_DeleteItem($lv, 1) _GUIImageList_Remove($img_list, 1) ; Add new item to end of ListView $idx = _GUICtrlListView_AddItem($lv, "foo") _GUICtrlListView_AddSubItem($lv, $idx, "bar", 1) ; Add new image to end of ImageList _GUIImageList_AddIcon($img_list, "5.ico") endswitch wend GUIDelete() endfunc func Quit() Exit endfunc What seems to happen is that when the new item is added to the ListView, its icon is 1.ico (the first item in the ImageList), rather than 5.ico (the newly added item that should be at the end of the ImageList).
      Or do I need to re-create the whole ImageList any time the ListView changes?
      A zip file is attached that contains the script and also the .ico files, for easier testing.
      Thanks!
      /John
      test.zip
×
×
  • Create New...