Unable to use correct icon in Listview Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
User avatar
WeedTrek
Posts: 75
Joined: 22 Mar 2019, 14:29
Location: Cache Creek BC Canada
Contact:

Unable to use correct icon in Listview

17 Mar 2021, 19:10

---SOLVED by garry and teadrinker---
I'm rebuilding the most useless and annoying tool ever, the "Desktop Cleanup Wizard" from XP, it mostly works but I'm having trouble with showing icons in GUI 3.
In lines 75 through 85, I'm trying to get the icons attached to each listview line but I keep getting the wrong ones. I've hammered on this for hours now and I believe I don't quite understand what the problem is.
Here is the code, btw it makes a .txt list of "checked" entries from GUI 2, then parses that .txt list to add the icons into Gui 3's listview, probably wrong.

Code: Select all

#SingleInstance, force
;Menu, Tray, Icon, %A_ScriptDir%\info.ico

Gui, 1: New
Gui, 1: Add, Picture, x0 y0 w164 h314, Bitmap200.bmp
Gui, 1: Add, Picture, x164 y0 w351 h314, whitebkg.jpg
Gui, Font, s13, Verdana
Gui, 1: Add, Text, x170 y10 w500 h50 +BackgroundTrans, Welcome to the Desktop Cleanup`nWizard
Gui, Font
Gui, 1: Add, Text, x170 y70 w500 h50 +BackgroundTrans, This wizard helps you clean up your desktop by moving`nunused shortcuts to a desktop folder called Unused`nDesktop Shortcuts.
Gui, 1: Add, Text, x170 y126 w500 h50 +BackgroundTrans, The wizard does not move, change or delete any of your`nprograms. If you later decide that you want a shortcut back`non your desktop, you can restore it from the Unused`nDesktop Shortcuts folder.
Gui, 1: Add, Text, x170 y280 w500 h50 +BackgroundTrans, To continue, click Next.
Gui, 1: Add, Button, x253 y326 w75 h23 +Disabled, `< Back
Gui, 1: Add, Button, x329 y326 w75 h23 vNext gCheckDesktop, Next `>
Gui, 1: Add, Button, x415 y326 w75 h23 vCancel gCancel, Cancel
Gui, 1: Show, w500 h360, Desktop Cleanup Wizard

return

CheckDesktop:
Gui, 1: Hide
Gui, 2: New
Gui, 2: Add, Text, w500 h30, The shortcuts selected below will be moved to Unused Desktop Shortcuts bla bla bla...
Gui, 2: Add, ListView, x40 y130 h146 w380 Checked +ReadOnly +Sort vList1, Shortcut to Clean Up                         |Date Last Used
Gui, 2: Add, Button, x253 y326 w75 h23 gBackTo1, `< Back
Gui, 2: Add, Button, x329 y326 w75 h23 vNext gConfirmShortcuts, Next `>
Gui, 2: Add, Button, x415 y326 w75 h23 vCancel gCancel, Cancel
Loop, %A_Desktop%\*.lnk
{
	FileGetShortcut, %A_LoopFileFullPath%, ShortcutTarget
	SplitPath, A_LoopFileFullPath,,,, OutNameNoExt
	if !FileExist(ShortcutTarget)
	{
		LV_Add("Check", OutNameNoExt, "No Target")
		continue
	}
	FileGetTime, DateCreatedTimeRaw, %A_LoopFileFullPath%, C
	FileGetTime, LastAccessedTimeRaw, %A_LoopFileFullPath%, A
	if (DateCreatedTimeRaw <= LastAccessedTimeRaw)
		Checkbox = "Check"
	else
		Checkbox = ""
	FormatTime, LastAccessedTimeFormatted, %LastAccessedTimeRaw%, M`/dd`/yyyy
	LV_Add(Checkbox, OutNameNoExt, LastAccessedTimeFormatted)
}
Gui, 2: Show, w500 h360, Desktop Cleanup Wizard
return

ConfirmShortcuts:
FileDelete, %A_Temp%\temp.txt
ShortcutNames := ""
Row := 0    
Loop
{
	Row := LV_GetNext(Row, "C")  ; finds checked checkboxes
	if (!Row)
		break
	LV_GetText(Name, Row, 1)      
	FileAppend, %Name%`,, %A_Temp%\temp.txt
}
Gui, 2: Hide
Gui, 3: New
Gui, 3: Add, Picture, x0 y0 w164 h314, Bitmap200.bmp
Gui, 3: Add, Picture, x164 y0 w351 h314, whitebkg.jpg
Gui, 3: Font, s13, Verdana
Gui, 3: Add, Text, x170 y10 w500 h50 +BackgroundTrans, Completing the Desktop Cleanup`nWizard
Gui, 3: Font
Gui, 3: Add, Text, x170 y70 w500 h50 +BackgroundTrans, Windows will move the following (number of checked items) bla bla
Gui, 3: Add, ListView, x173 y122 h116 w286 -Hdr +ReadOnly vList2, HiddenColumnName



; This is where I'm having trouble, associating the icons which "FileGetShortcut" gets, the wrong icons are shown

ImageListID := IL_Create()
LV_SetImageList(ImageListID)
FileRead, ShortcutsToMove, %A_Temp%\temp.txt
Loop, Parse, ShortcutsToMove, `,
{
	If A_Loopfield = 
		break
FileGetShortcut, %A_Desktop%\%A_LoopField%.lnk, ShortcutTarget
IL_Add(ImageListID, ShortcutTarget)
LV_Add("Icon" . A_Index, A_LoopField)
}





Gui, 3: Add, Button, x253 y326 w75 h23 gBackTo2, `< Back
Gui, 3: Add, Button, x329 y326 w75 h23 vNext gMoveUnusedShortcuts, Finish
Gui, 3: Add, Button, x415 y326 w75 h23 vCancel gCancel, Cancel
Gui, 3: Show, w500 h360, Desktop Cleanup Wizard
return

MoveUnusedShortcuts:
If !FileExist(A_Desktop "\Unused Desktop Shortcuts")
	FileCreateDir, %A_Desktop%\Unused Desktop Shortcuts
Loop, Parse, ShortcutsToMove, `,
{
	If A_Loopfield = 
		break
	;FileMove, %A_Desktop%\%A_LoopField%.lnk, %A_Desktop%\Unused Desktop Shortcuts
	MsgBox, Shortcuts not moved, testing
}
ExitApp

BackTo1:
Gui, 2: Hide
Gui, 1: Show
return

BackTo2:
Gui, 3: Hide
Gui, 2: Show
return

Esc::
GuiClose:
Cancel:
FileDelete, %A_Temp%\temp.txt
ExitApp

I've tried keeping the list of Gui 2's "checked" shortcuts in a variable, but I could only make it work from a parsed list, otherwise I was getting "this variable name contains an illegal character" even though there were none. Thanks very much for any help, even if it makes you guilty of helping to resurrect the most annoying, useless and hated tool XP ever offered. I found a blog post by the software guy who was responsible for removing Desktop Cleanup Wizard (fldrclnr.dll) from XP in 2006, that's an awesome flex bro way to go lol
Last edited by WeedTrek on 18 Mar 2021, 17:26, edited 1 time in total.
My Weed Trek video archive: http://weedtrek.ca
User avatar
WeedTrek
Posts: 75
Joined: 22 Mar 2019, 14:29
Location: Cache Creek BC Canada
Contact:

Re: Unable to use correct icon in Listview

18 Mar 2021, 14:17

ok here is my problem simplified:
- "Listbox 1" on GUI2 shows all found shortcuts on the desktop, "checked" shortcuts (so far) are the ones without targets, and whichever other ones the user checks
- The "checked" items populate the next listbox on GUI3 when "next" is clicked on GUI2, but retrieving each checked line's icon from its shortcut has been a challenge.
I need to show the correct Icon1 from each shortcut's associated program/file/folder.
Here is the entire thing closer to completion:
Dektop_Cleanup_Wizard.zip
(17.07 KiB) Downloaded 22 times
It will not actually move any found shortcuts at the end screen, that's on purpose for testing. Everything else works except for the icons on GUI3's listbox entries.
Thanks very much :)
My Weed Trek video archive: http://weedtrek.ca
garry
Posts: 3793
Joined: 22 Dec 2013, 12:50

Re: Unable to use correct icon in Listview  Topic is solved

18 Mar 2021, 14:42

@WeedTrek thank you for simplified script, looks nice

Code: Select all

Loop, Parse, ShortcutsToMove, `,
{
	if A_Loopfield = 
		break
	FileGetShortcut, %A_Desktop%\%A_LoopField%.lnk, ShortcutTarget
    IconNumber := IL_Add(ImageListID, "%pictxx05%" )      ;- clear with picture which not exist ( maybe this not needed )
	IconNumber := IL_Add(ImageListID, ShortcutTarget)
	LV_Add("Icon" . iconnumber, A_LoopField)
}
User avatar
WeedTrek
Posts: 75
Joined: 22 Mar 2019, 14:29
Location: Cache Creek BC Canada
Contact:

Re: Unable to use correct icon in Listview

18 Mar 2021, 14:55

Thanks garry! You were doing the youtube downloader years ago and I was using that in Aaron's Youtube Television (I'm aaronbewza), I totally remember you from the old site.
I didn't realize the "IL_Add" needed a handle for "LV_add" to work, that's great. I might have a follow-up question in a while if I can't figure out the icons for folders and AHK files etc
but this gets me much farther ahead than I was :)
My Weed Trek video archive: http://weedtrek.ca
User avatar
WeedTrek
Posts: 75
Joined: 22 Mar 2019, 14:29
Location: Cache Creek BC Canada
Contact:

Re: Unable to use correct icon in Listview

18 Mar 2021, 15:11

Success! Using garry's code which put a handle where it was needed, and the other code which gets shortcuts from all filetypes, I was able to come up with this, it works 100% for all filetypes that I've tested it with:

Code: Select all

Loop, Parse, ShortcutsToMove, `,
{
	if A_Loopfield = 
		break
	FileGetShortcut, %A_Desktop%\%A_LoopField%.lnk, ShortcutTarget
	ThisIcon := DllCall("Shell32\ExtractAssociatedIcon", "Ptr", 0, "Str", ShortcutTarget, "ShortP", 0, "Ptr")
	Handle = HICON:%ThisIcon%
	IconNumber := IL_Add(ImageListID, Handle)
	LV_Add("Icon" . iconnumber, A_LoopField)
}
I will post the completed script once I finish it up. Thanks very much again!
My Weed Trek video archive: http://weedtrek.ca
garry
Posts: 3793
Joined: 22 Dec 2013, 12:50

Re: Unable to use correct icon in Listview

18 Mar 2021, 16:08

hello Aaron
now I use youtube-dl.exe with user 'teadrinker's script , run DOS in a GUI :
https://www.autohotkey.com/boards/viewtopic.php?f=28&t=84885

your example above is also from user teadrinker ,
someone has a solution how to add the ico to iconnumber
EDIT : I see you have already a solution , modified script , is possible to mark YOUR script as solved ( ? )

this was an old idea , some icons in a folder and depending text or extension add to iconnumber ( now forget it because you have the solution )

Code: Select all

R3I =%a_scriptdir%\icons_LVmenu
xxa:= R3I . "\ahk.ico"
xxt:= R3I . "\text.ico"
;...
     if (ext="ahk")
        IconNumber := IL_Add(ILSTATUS,xxa)
     if (ext="txt")
       IconNumber := IL_Add(ILSTATUS,xxt)
  LV_Add("icon" . IconNumber ,C1,C2)
  ;....       
User avatar
WeedTrek
Posts: 75
Joined: 22 Mar 2019, 14:29
Location: Cache Creek BC Canada
Contact:

Re: Unable to use correct icon in Listview

18 Mar 2021, 17:25

haha thanks :) I think it is actually "garry and teadrinker" who have the combined correct solution... I smashed them together is the only thing I did.
It works 100% so far. I will try your current downloader, looks awesome, and thanks again.
My Weed Trek video archive: http://weedtrek.ca

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: No registered users and 105 guests