Jump to content

Getting list control(view) item image


Recommended Posts

Hi

I wrote the following code to fetch and store the first item image in a list control in a GUI application.

For some reason _GUICtrlListView_GetItemImage returns me (-1), and I don't understand why.

Can you assist please?

Thanks!

-------------------------------------------------------

#include <GuiListView.au3>

#Include <GuiImageList.au3>

#Include <GDIPlus.au3>

; Get list control handle

$PAListCtrlID = 1530

$hListView = ControlGetHandle("My App Title", "", $PAListCtrlID)

; Get first list item image handle

$imgIndex = _GUICtrlListView_GetItemImage($hListView, 0) ; image index in image list of the first ;item image. Returns: -1

; Get image list handle

$SMALL_ICONS = 1;

$imgList = _GUICtrlListView_GetImageList($hListView, $SMALL_ICONS)

MsgBox(0, "$imgList", $imgList)// != 0

MsgBox(0, "$imgList size", _GUIImageList_GetImageCount($imgList)) ; Returns 0 ! why ??? Can it be that a list control will have icons but the image list is empty !?

MsgBox(4160, "Information", "Item 1 Text: " & _GUICtrlListView_GetItemText($hListView, 0, 6)) ; This gives us the first item text in sub item 6 correctly (don't mind the 6 - what's really matters here is to show that referencing item 0 seems to be ok. So why does _GUICtrlListView_GetItemImage returns -1 ???)

$hIcon = _GUIImageList_GetIcon($imgList, $imgIndex);

MsgBox(0, "$hIcon", $hIcon) ;Returns 0

;$fileName = @MyDocumentsDir & "\a.ico"

;_GDIPlus_ImageSaveToFile($hIcon, $fileName)

Edited by dushkin
Link to comment
Share on other sites

The function works fine with an AutoIt GUI and controls.

Since we don't have your app to test with, you'll have to find a way to post a short but running reproducer script that we can run to see your issue. Try some of the common apps and utilities that come with windows and see if you can reproduce your issue.

:(

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
Link to comment
Share on other sites

The function works fine with an AutoIt GUI and controls.

Since we don't have your app to test with, you'll have to find a way to post a short but running reproducer script that we can run to see your issue. Try some of the common apps and utilities that come with windows and see if you can reproduce your issue.

:(

Thanks.

Should I understand from your answer that I can use the GetItemImage function only on applications that I built with AutoIt???

Can't I use it on my, for example, Visual C++ MFC applications?

If so, how can I work on my applications?

Thanks again!

Link to comment
Share on other sites

The function works fine with an AutoIt GUI and controls.

Since we don't have your app to test with, you'll have to find a way to post a short but running reproducer script that we can run to see your issue. Try some of the common apps and utilities that come with windows and see if you can reproduce your issue.

:(

I tried my script on windows explorer. I right click the "start" button and got "Start Menu" window. I tried to work on the list view on the right (see attachment). Everything I try in order to save the folder icon of "Programs" folder failed. What specially puzzled me is that ControlGetHandle("Start Menu", "", $PAListCtrlID) returned what seems to be a valid value (not null) but _GUICtrlListView_GetImageList returned null.

Also I failed to get the text of the first item (Programs).

------------------------------------------------------------------

; Get image list handle

$PAListCtrlID = 1

$hListView = ControlGetHandle("Start Menu", "", $PAListCtrlID)

$imgIndex = _GUICtrlListView_GetItemImage($hListView, 1)

$SMALL_ICONS = 1;

$imgList = _GUICtrlListView_GetImageList($hListView, $SMALL_ICONS)

MsgBox(4160, "Information", "Item 1 Text: " & _GUICtrlListView_GetItemText($hListView, 1, 3)) ; This gives the first item text

$hIcon = _GUIImageList_GetIcon($imgList, $imgIndex);

$fileName = @MyDocumentsDir & "\a.ico"

_GDIPlus_ImageSaveToFile($hIcon, $fileName)

-------------------------------------------------------------

I did manage to get some data from the list control by using:

MsgBox(0, "$imgList size", ControlListView("Start Menu", "FolderView", $PAListCtrlID, "GetItemCount"))

MsgBox(0, "$imgList size", ControlListView("Start Menu", "FolderView", $PAListCtrlID, "GetText", 0, 2))

But retrieving the list control images is still my Achilles' heel... :)

post-56238-12710541733094_thumb.jpg

Edited by dushkin
Link to comment
Share on other sites

If there are filenames in the listview you could use _FileGetIcon from my FileInfo-UDF.

#783762

Programming today is a race between software engineers striving to
build bigger and better idiot-proof programs, and the Universe
trying to produce bigger and better idiots.
So far, the Universe is winning.

Link to comment
Share on other sites

If there are filenames in the listview you could use _FileGetIcon from my FileInfo-UDF.

#783762

Thanks Funkey.

I am not sure it is relevant for me.

I am using a application specific data (and icons) in my list view. So I am not using the windows DLL you use in your function.

Maybe you know a way to get an item icon in general from any list view?

Link to comment
Share on other sites

You could try to use _GUICtrlListView_GetItemRect and PixelChecksum to find out what icon is used.

Programming today is a race between software engineers striving to
build bigger and better idiot-proof programs, and the Universe
trying to produce bigger and better idiots.
So far, the Universe is winning.

Link to comment
Share on other sites

I don't see your problem. This gives me the image index for all the items in an explorer window just fine:

#include <GUIListView.au3>

$sWindow = "[CLASS:ExploreWClass]"
$sControl = "[CLASS:SysListView32; INSTANCE:1]"
$hWin = WinGetHandle($sWindow, "")
ConsoleWrite("$hWin = " & $hWin & @LF)
$hLV = ControlGetHandle($hWin, "", $sControl)
ConsoleWrite("$hLV = " & $hLV & @LF)
$iCnt = _GUICtrlListView_GetItemCount($hLV)
ConsoleWrite("$iCnt = " & $iCnt & @LF)
$hImgList = _GUICtrlListView_GetImageList($hLV, 1) ; 1 = small icons
ConsoleWrite("$hImgList = " & $hImgList & @LF)
For $n = 0 To $iCnt - 1
    $sItemText = _GUICtrlListView_GetItemText($hLV, $n)
    $iItemImg = _GUICtrlListView_GetItemImage($hLV, $n)
    ConsoleWrite($n & ":  " & $sItemText & " = " & $iItemImg & @LF)
Next

Result when C:\Temp is open:

>Running:(3.3.6.0):C:\Program Files\AutoIt3\autoit3.exe "C:\Program Files\AutoIt3\Scripts\Test_1.au3"    
$hWin = 0x007202C8
$hLV = 0x02D803C2
$iCnt = 26
$hImgList = 0x000EC978
0:  dog photo = 5
1:  Temp1 = 5
2:  Temp2 = 5
3:  Testing = 5
4:  NIAPS_Server_Data.db = 23
5:  Prairie Wind.bmp = 24
6:  PrinterInfo.txt = 15
7:  ResultsFor_Factor.jpg = 25
8:  Rhododendron.bmp = 24
9:  River Sumida.bmp = 24
10:  sample2.txt = 15
11:  Santa Fe Stucco.bmp = 24
12:  Soap Bubbles.bmp = 24
13:  Telnet.log = 15
14:  temp = 3
15:  Temp1.txt = 15
16:  Temp2.txt = 15
17:  Temp3.txt = 15
18:  Test-1.rtf = 26
19:  Test.htm = 7
20:  Test.ini = 9
21:  Test.log = 15
22:  Test.txt = 15
23:  Test.txt.BAK = 3
24:  Test.zip = 27
25:  Thumbs.db = 23
+>17:29:51 AutoIT3.exe ended.rc:0
+>17:29:53 AutoIt3Wrapper Finished
>Exit code: 0    Time: 4.971

Note the window class for an explorer window may change depending on your version (this works with XP Pro SP3).

:(

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
Link to comment
Share on other sites

  • 4 weeks later...

Hi there!

I used your example, and saw that it really works.

Thanks!

Now I am facing a problem implementing it on my own application instead of the explorer.

Although I get what seems to be valid image indexes from GUICtrlListView_GetItemImage, _GUIImageList_GetIcon returns NULL.

Can you or someone else advise please?

Thanks!

Here is the code:

#include <GUIListView.au3>
#Include <GDIPlus.au3>
#Include <GuiImageList.au3>

;$sWindow = "[CLASS:ExploreWClass]"
;$sControl = "[CLASS:SysListView32; INSTANCE:1]"
$sWindow = "My app title"
$sControl = "[CLASS:SysListView32; INSTANCE:2]"

$hWin = WinGetHandle($sWindow, "")
ConsoleWrite("$hWin = " & $hWin & @LF)

$hLV = ControlGetHandle($hWin, "", $sControl)
ConsoleWrite("$hLV = " & $hLV & @LF)

$iCnt = _GUICtrlListView_GetItemCount($hLV)
ConsoleWrite("$iCnt = " & $iCnt & @LF)

$hImgList = _GUICtrlListView_GetImageList($hLV, 1) ; 1 = small icons
ConsoleWrite("$hImgList = " & $hImgList & @LF)

;-----------------
;Here I get 0 !!!!
;-----------------
ConsoleWrite("Image List Count: " & _GUIImageList_GetImageCount($hImgList) & @LF)

For $itemIx = 0 To $iCnt - 1

    ;--------------------------------------------------------
    ;I get here what seems to be valid icon image indexes!!!
    ;--------------------------------------------------------
    $iItemImgIx1 = _GUICtrlListView_GetItemImage($hLV, $itemIx, 1)
    $iItemImgIx2 = _GUICtrlListView_GetItemImage($hLV, $itemIx, 2)
    $iItemImgIx3 = _GUICtrlListView_GetItemImage($hLV, $itemIx, 3)
    
    ConsoleWrite(@LF & "Item " & $itemIx & " images: 1st Img = " & $iItemImgIx1 & "; 2nd Img = " & $iItemImgIx2 & "; 3nd Img = " & $iItemImgIx3 & @LF)

    ;--------------------
    ;Here I get NULL !!!!
    ;--------------------
    $icon1 = _GUIImageList_GetIcon($hImgList, $iItemImgIx1)
Next

Actually... _GUIImageList_GetImageCount returns me 0 also for the explorer window... :idea:

Edited by dushkin
Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...