I had already searched for "SHGetFileInfo hidden" and found a useful post on a newsgroup mentioning LVIS_CUT. I took a dissassembler to comctl32.dll to find out what happens when LVIS_CUT is set and that led me to discovering the ImageList functions for the first time. Honestly, I couldn't get the colours right so to me it was a bad script.
. CreateIconIndirect creates a new icon, the old icon will be leaked if it's not destroyed manually.
I was attempting to work on a replacement post that hopefully did it properly. I still failed, but one of the things I did achieve was using the built-in IL functions for some things if it helps any:
Code: Select all
#NoEnv ; Recommended for performance and compatibility with future AutoHotkey releases.
; #Warn ; Enable warnings to assist with detecting common errors.
SendMode Input ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir% ; Ensures a consistent starting directory.
; Show a menu of the first n files matching a pattern, and their icons.
pattern = %A_ScriptDir%\*
n = 15
VarSetCapacity(ICONINFO, 32), VarSetCapacity(BITMAP, 32)
; Allocate memory for a SHFILEINFOW struct.
VarSetCapacity(fileinfo, fisize := A_PtrSize + 688)
Loop, Files, %pattern%, FD
{
; Add a menu item for each file.
Menu F, Add, %A_LoopFileName%, donothing
; Get the file's icon.
if DllCall("shell32\SHGetFileInfoW", "wstr", A_LoopFileFullPath
, "uint", 0, "ptr", &fileinfo, "uint", fisize, "uint", 0x100 | SHGFI_ATTRIBUTES := 0x000000800)
{
hicon := NumGet(fileinfo, 0, "ptr")
dwAttributes := NumGet(fileinfo, A_PtrSize + 4, "UInt")
if (dwAttributes & SFGAO_GHOSTED := 0x00008000) {
if (DllCall("GetIconInfo", "Ptr", hicon, "Ptr", &ICONINFO)) {
hbmColor := NumGet(ICONINFO, 32 - A_PtrSize, "Ptr")
hbmMask := NumGet(ICONINFO, 32 - (A_PtrSize * 2), "Ptr")
if (DllCall("GetObject", "Ptr", hbmColor, "Int", A_PtrSize == 8 ? 32 : 24, "Ptr", &BITMAP)) {
width := NumGet(BITMAP, 4, "Int")
height := NumGet(BITMAP, 8, "Int")
if ((im := IL_Create(1, 0, True))) {
if ((idx := DllCall("ImageList_Add", "Ptr", im, "Ptr", hbmColor, "Ptr", hbmMask)) != -1) {
clrBk := DllCall("GetSysColor", "UInt", COLOR_MENU := 4, "UInt")
clrFg := RGB(255, 255, 255)
scrdc := DllCall("GetDC", "Ptr", A_ScriptHwnd, "Ptr")
hdc := DllCall("CreateCompatibleDC", "Ptr", scrdc, "Ptr")
;hbmMask := DllCall("CreateCompatibleBitmap", "Ptr", scrdc, "Int", width, "Int", height, "Ptr")
DllCall("SelectObject", "Ptr", hdc, "Ptr", hbmMask, "Ptr")
if (DllCall("ImageList_DrawEx", "Ptr", im, "Int", idx, "Ptr", hdc, "Int", 2, "Int", 0, "Int", width, "Int", height, "UInt", clrBk, "UInt", clrFg, "UInt", ILD_MASK := 0x00000010 | ILD_BLEND50 := 0)) {
;hbmColor := DllCall("CreateCompatibleBitmap", "Ptr", scrdc, "Int", width, "Int", height, "Ptr")
DllCall("SelectObject", "Ptr", hdc, "Ptr", hbmColor, "Ptr")
DllCall("ImageList_DrawEx", "Ptr", im, "Int", idx, "Ptr", hdc, "Int", 0, "Int", 0, "Int", width, "Int", height, "UInt", clrBk, "UInt", clrFg, "UInt", ILD_BLEND50 := 0x00000004)
DllCall("SelectObject", "Ptr", hdc, "Ptr", 0, "Ptr")
DllCall("DestroyIcon", "Ptr", hicon)
;NumPut(hbmColor, ICONINFO, 32 - 8, "Ptr")
;NumPut(hbmMask, ICONINFO, 32 - 16, "Ptr")
hicon := DllCall("CreateIconIndirect", "Ptr", &ICONINFO, "Ptr")
}
DllCall("DeleteDC", "Ptr", hdc)
DllCall("ReleaseDC", "Ptr", 0, "Ptr", scrdc)
}
IL_Destroy(im)
}
}
if (hbmColor)
DllCall("DeleteObject", "Ptr", hbmColor)
if (hbmMask)
DllCall("DeleteObject", "Ptr", hbmMask)
}
}
; Set the menu item's icon.
Menu F, Icon, %A_Index%&, HICON:%hicon%
; Because we used ":" and not ":*", the icon will be automatically
; freed when the program exits or if the menu or item is deleted.
}
}
until A_Index = n
Menu F, Show
donothing:
return
RGB(r,g,b)
{
return (r)|(g << 8)|(b << 16)
}
I tried quite a few of them. Most are just synonyms for ILD_BLEND. ILD_TRANSPARENCY killed the transparency. ILD_BLEND25 makes things worse.
I tried RGB black and white, and CLR_NONE/CLR_DEFAULT to no avail. But I don't know what I'm doing here...
. As I don't know assembler, I rely on its decompiler a lot.
R.e. the brightness: I believe so.