Posts: 1,058
Threads: 367
Joined: Oct 2007
I would like to use in one of my dialogs the icon associated to a certain file type, which of course may vary. I found many useful topics in the Forum, and I concluded to the following function :
Function tempf10
;ITEMIDLIST to display name
;www.quickmacros.com/forum/viewtopic.php?p=30548
ITEMIDLIST* pidl=PidlFromStr("C:\tmp\hlp.txt")
SHFILEINFOW x
int ok=SHGetFileInfoW(+pidl 0 &x sizeof(x) SHGFI_PIDL|SHGFI_DISPLAYNAME|SHGFI_SYSICONINDEX)
CoTaskMemFree pidl
if(!ok) end "failed"
str s.ansi(&x.szDisplayName)
out s
x.hIcon
out x.iIcon
However, I have difficulty in interpreting the icon handle, namely &x.hIcon
Any advice will be much appreciated.
Posts: 12,092
Threads: 142
Joined: Dec 2002
If need icon handle:
GetFileIcon(".txt")
If need icon path, for many file types it is not possible.
Posts: 1,058
Threads: 367
Joined: Oct 2007
Thank you very much. I should have known that.
Posts: 1,058
Threads: 367
Joined: Oct 2007
Dear Gintaras, Let me please extend my inquiry by asking you to comment on the following code, written to populate an ImageList using GetIcon statements:
Function tempf12
,__ImageList- il=ImageList_Create(16 16 ILC_MASK|ILC_COLOR32 0 8)
,rep(15) ImageList_ReplaceIcon(il -1 GetIcon(".doc"))
,handle=ImageList_GetIcon(il 5 0)
,SendMessage(id(7 hDlg) BM_SETIMAGE IMAGE_ICON handle)
It is tested and it works, however I am wondering whether there exists a faster way to do it.
Furthermore, I am wondering whether the above ImageList can be saved as .bmp file on disc, for further access.
Many thanks in advance.
Posts: 12,092
Threads: 142
Joined: Dec 2002
I don't know other ways to set button image.
To save imagelist, I would try ImageList_Write. See also __Stream class function CreateOnFile. It probably will be not .bmp format, but can be loaded with ImageList_Read.
Posts: 1,058
Threads: 367
Joined: Oct 2007
Thanks for these very useful advises. I will try to follow them. Best regards.
Posts: 1,058
Threads: 367
Joined: Oct 2007
It worked, following the guidance given above. I attach the routines for any comments.
Function Dialog137c_Write
;http://www.quickmacros.com/forum/viewtopic.php?p=31363
str dd=
;BEGIN DIALOG
;0 "" 0x90C80AC8 0x0 0 0 224 136 "Dialog"
;3 Button 0x54034040 0x4 31 16 15 14 "Button"
;4 Button 0x54034040 0x4 81 17 15 14 "Button"
;5 Button 0x54034040 0x4 131 16 15 14 "Button"
;6 Button 0x54034040 0x4 175 16 15 14 "Button"
;7 Button 0x54034040 0x4 206 16 15 14 "Button"
;8 Button 0x54034040 0x4 31 41 15 14 "Button"
;9 Button 0x54034040 0x4 79 42 15 14 "Button"
;10 Button 0x54034040 0x4 131 42 15 14 "Button"
;11 Button 0x54034040 0x4 174 40 15 14 "Button"
;12 Button 0x54034040 0x4 206 42 15 14 "Button"
;1 Button 0x54030001 0x4 116 116 48 14 "OK"
;2 Button 0x54030000 0x4 168 116 48 14 "Cancel"
;END DIALOG
;DIALOG EDITOR: "" 0x2040308 "*" "" "" ""
if(!ShowDialog(dd &sub.DlgProc 0)) ret
#sub DlgProc
function# hDlg message wParam lParam
int handle i
sel message
,case WM_INITDIALOG
;,__ImageList- il=ImageList_Create(16 16 ILC_MASK|ILC_COLOR32 0 8)
,__ImageList-- il.Load("C:\Documents and Settings\S.E.Simopoulos\My QM\imagelists\Tamtiriri.bmp")
,str sico
,int n=ImageList_GetImageCount(il)
,outt F"{n}"
,ImageList_ReplaceIcon(il 2 GetIcon(".eml")) ;; replace existing
,ImageList_ReplaceIcon(il -1 GetIcon(".pdf")) ;; add new
,ImageList_ReplaceIcon(il -1 GetIcon(".jpg"))
,n =ImageList_GetImageCount(il)
,outt F"{n}"
,
,for i 0 n
,,handle=ImageList_GetIcon(il i 0)
,,SendMessage(id(i+3 hDlg) BM_SETIMAGE IMAGE_ICON handle)
;
,__Stream x
;
,str f="C:\tmp\ses_Stream.txt"
,int fl=0x00000002 ;;STGM_READWRITE
,if(!FileExists(f)) fl|0x00001000 ;;STGM_CREATE
,x.CreateOnFile(f fl)
,ImageList_Write(il x)
,case WM_DESTROY
,case WM_COMMAND goto messages2
ret
;messages2
sel wParam
,case IDOK
,case IDCANCEL
ret 1
Function Dialog137d_Read
;http://www.quickmacros.com/forum/viewtopic.php?p=31363
str dd=
;BEGIN DIALOG
;0 "" 0x90C80AC8 0x0 0 0 224 136 "Dialog"
;3 Button 0x54034040 0x4 31 16 15 14 "Button"
;4 Button 0x54034040 0x4 81 17 15 14 "Button"
;5 Button 0x54034040 0x4 131 16 15 14 "Button"
;6 Button 0x54034040 0x4 175 16 15 14 "Button"
;7 Button 0x54034040 0x4 206 16 15 14 "Button"
;8 Button 0x54034040 0x4 31 41 15 14 "Button"
;9 Button 0x54034040 0x4 79 42 15 14 "Button"
;10 Button 0x54034040 0x4 131 42 15 14 "Button"
;11 Button 0x54034040 0x4 174 40 15 14 "Button"
;12 Button 0x54034040 0x4 206 42 15 14 "Button"
;1 Button 0x54030001 0x4 116 116 48 14 "OK"
;2 Button 0x54030000 0x4 168 116 48 14 "Cancel"
;END DIALOG
;DIALOG EDITOR: "" 0x2040308 "*" "" "" ""
if(!ShowDialog(dd &sub.DlgProc 0)) ret
#sub DlgProc
function# hDlg message wParam lParam
int handle i
sel message
,case WM_INITDIALOG
,__ImageList- il
,__Stream x
;
,str f="C:\tmp\ses_Stream.txt"
,int fl=0x00000002 ;;STGM_READWRITE
,if(!FileExists(f)) fl|0x00001000 ;;STGM_CREATE
,x.CreateOnFile(f fl)
,il=ImageList_Read(x)
,,
,str sico
,int n=ImageList_GetImageCount(il)
,outt F"{n}"
,
,for i 0 n
,,handle=ImageList_GetIcon(il i 0)
,,SendMessage(id(i+3 hDlg) BM_SETIMAGE IMAGE_ICON handle)
;
,case WM_DESTROY
,case WM_COMMAND goto messages2
ret
;messages2
sel wParam
,case IDOK
,case IDCANCEL
ret 1
|