Hey Skan...
I just spent 20 mins working on my idea.... and strangely i have it semi-working!
Let me explain. First here's the code.
Code:
F10:: ;Create a Custom Desktop.ini file and copy it to clipboard for easily changing folder icons.
;By Vixay on Fri December 19, 2008 12:38:19 PM
CustomFolderIcon:
FileN = %A_Temp%\Desktop.ini
FileText =
(
[.ShellClassInfo]
IconFile=%tFolder%\%File%
IconIndex=%IconGroup%
)
IfExist, %FileN%
{
FileDelete, %FileN%
}
FileAppend, %FileText%, %FileN%
If ErrorLevel = 0
{
FileSetAttrib, +ASH, %FileN%
FileToClipboard(FileN)
}
Return
; Converts a file copied as Name to a file struct on clipboard
;^v::Send %Clipboard% ;Paste as plain text - opposite of function
;http://www.autohotkey.com/forum/topic25416.html
FileToClipboard(PathToCopy)
{
; Expand to full paths:
Loop, Parse, PathToCopy, `n, `r
Loop, %A_LoopField%, 1
temp_list .= A_LoopFileLongPath "`n"
PathToCopy := SubStr(temp_list, 1, -1)
; Allocate some movable memory to put on the clipboard.
; This will hold a DROPFILES struct and a null-terminated list of
; null-terminated strings.
; 0x42 = GMEM_MOVEABLE(0x2) | GMEM_ZEROINIT(0x40)
hPath := DllCall("GlobalAlloc","uint",0x42,"uint",StrLen(PathToCopy)+22)
; Lock the moveable memory, retrieving a pointer to it.
pPath := DllCall("GlobalLock","uint",hPath)
NumPut(20, pPath+0) ; DROPFILES.pFiles = offset of file list
pPath += 20
; Copy the list of files into moveable memory.
Loop, Parse, PathToCopy, `n, `r
{
DllCall("lstrcpy","uint",pPath+0,"str",A_LoopField)
pPath += StrLen(A_LoopField)+1
}
; Unlock the moveable memory.
DllCall("GlobalUnlock","uint",hPath)
DllCall("OpenClipboard","uint",0)
; Empty the clipboard, otherwise SetClipboardData may fail.
DllCall("EmptyClipboard")
; Place the data on the clipboard. CF_HDROP=0xF
DllCall("SetClipboardData","uint",0xF,"uint",hPath)
DllCall("CloseClipboard")
}
This works well! I put this right about the CreateSimpleIcon in IconEx V1.00. I have set F10 as the hotkey for this. I tried it, it creates the file flawlessly and puts it on the clipboard as well!
I can paste it and it has the correct attributes and everything. But when I try to refresh and see my changes, it doesn't work!
I suspect this has to do with how Windows manages the Icon Cache and all that. Or maybe you need a corresponding registry entry? I vaguely remember something about BAGS and the number of BAGS that windows can have for folder customizations and all. I think maybe restarting will solve this issue, haven't tested yet. But do you have any ideas? Anyone more knowledgable on this care to shed some light? I know that IconPackager had an option to rebuild the Icon Cache to ensure that their changes are shown... anyway i'm left scratching my head for right now. Maybe there needs to be a dllcall to refresh it correctly.
The second issue, is that the path is absolute... i don't know how to make it use the environment variables instead of the actual path, but i guess it's ok even then.
summary: 2 problems
1) Copying Desktop.ini doesn't actually change the folder icon (maybe refresh issue, maybe need something more)
2) Path to icon is absolute, doesn't use environment variables. (Impossible to make it relative since we don't know where it might be copied!)
/Edit: spelling and clarifications