News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

SHGetFileInfo help

Started by maruf10, February 23, 2010, 06:46:00 PM

Previous topic - Next topic

maruf10

I think accessing shell32.dll can help ...

i have got this line from winasm.net ...
but don't understand its meaning exactly .....

Quote
invoke GetModuleHandle,CTEXT("Shell32.DLL")
mov Shellhdl,eax

invoke LoadImage, Shellhdl, 160, IMAGE_ICON, 16, 16, LR_SHARED
INVOKE SendDlgItemMessage,hWin,1012,STM_SETIMAGE,IMAGE_ICON,eax


ragdog

Hi

By winasm have i found this

invoke GetModuleHandle,CTEXT("c:\windows\system32\Shell32.DLL")
invoke LoadImage, eax, 160, IMAGE_ICON, 16, 16, LR_SHARED
invoke SendDlgItemMessage,hWin,1015,STM_SETIMAGE,IMAGE_ICON,eax


This draw this icons on a dialog item

qWord

the code loads shell32.dll in process to obtain an icon (ordinal=160) from it's resource section. Then it sets the icon to a static controll (it must be created with the SS_ICON-style).
FPU in a trice: SmplMath
It's that simple!

maruf10

Is it possible to retrive any icon from shell32.dll providing file path ??
I want to compare that icon with "File folder" icon

qWord

Quote from: maruf10 on February 27, 2010, 07:05:02 PM
Is it possible to retrive any icon from shell32.dll providing file path ??
not sure what you mean - for system dll's there is no need to specific an path.
FPU in a trice: SmplMath
It's that simple!

maruf10

Please check this code :


.386
.model flat, stdcall
option casemap :none
;include \masm32\include\windows.inc
;include \masm32\include\kernel32.inc
;include \masm32\include\masm32.inc
include \masm32\include\masm32rt.inc
include \masm32\include\debug.inc


includelib \masm32\lib\kernel32.lib
includelib \masm32\lib\masm32.lib
includelib \masm32\lib\debug.lib


.code

start:

.data
cmd2 db 'cmd /c dir "H:\file\*.exe"  /s/w/b/a-d >'  ;folder to be checked
;module_name db "C:\windows\system32\shell32.dll",0
         dest2 db "H:\go.txt",0
         helloworld db " Hello world ", 0
NewLine db 10,13,0
         shfi SHFILEINFO <>
   
.code
          invoke wshell , addr cmd2



.data
          aline dd 170 dup(0)
          spos dd 0
          answ dd 0
          alen dd 0
          lcnt dd 0
  temp dd 0
  numb dd 0


.code
       
  invoke read_disk_file , addr dest2 , addr answ , addr alen
  ;invoke GetModuleHandle , offset module_name
         

          .repeat

   
                    invoke readline,answ,addr aline,spos
                    mov temp,eax
                   
                     .if eax!=NULL
                     
invoke SHGetFileInfo , addr aline , NULL , addr shfi , sizeof shfi , SHGFI_ICON + SHGFI_LARGEICON + SHGFI_ICONLOCATION + SHGFI_TYPENAME+SHGFI_USEFILEATTRIBUTES
                  invoke StdOut , OFFSET shfi.szTypeName
                     
                       
                 
                        PrintDec shfi.iIcon
    invoke StdOut , OFFSET NewLine
                      inc lcnt
                   
                    .endif
                   


                    mov eax,temp
                    mov spos,eax

                   
                   
          .until eax==0


 
       
          invoke GlobalFree,answ
          invoke wsprintf,addr aline,SADD("lines read=%li"),lcnt
          invoke MessageBox,0,addr aline,0,0
          invoke ExitProcess,eax

END start



i want to differentiate among various .exe file having different icon ....
i have placed three files 2 having firefox icon in a folder....
but the debug window of this code shows different icon type for that two files ...
i think those output should be same  for all same icon type file though their name is different...
where is the error ??
hope you will explain these three lines too : :red

Quote
  invoke wshell , addr cmd2
  invoke read_disk_file , addr dest2 , addr answ , addr alen
  invoke readline,answ,addr aline,spos

qWord

Quote from: maruf10 on February 27, 2010, 07:34:10 PM
Quote
  invoke wshell , addr cmd2
  invoke read_disk_file , addr dest2 , addr answ , addr alen
  invoke readline,answ,addr aline,spos
These functions are part of the masm32.lib - for a description look at masm32\help\masmlib.chm.

wshell creates a process of cmd.exe with the parameters '/c dir "H:\file\*.exe"  /s/w/b/a-d >H:\go.txt'.
This list all executables in the folder h:\file\ and redirect ('>') the output to the file go.txt. You can do this also by hand when typing the line into the command window.

Quote from: maruf10 on February 27, 2010, 07:34:10 PM
where is the error ??
there is no error. After a quick google search I've figured out that the index in the System Image List  is differently for each item in a folder.
FPU in a trice: SmplMath
It's that simple!


maruf10

Quote
SHGFI_ICON
    Retrieve the handle to the icon that represents the file and the index of the icon within the system image list. The handle is copied to the hIcon member of the structure specified by psfi, and the index is copied to the iIcon member.

I hv got this from msdn ...
need some assistance < clear cut example >to implement this  because my code is not responding for iIcon ....  :red
should i convert the value of iIcon frm int to string ??
it will be devastating for me if it not works  :(

qWord

using iIcon for comparing will not work, because each icon in a folder has it own index (AFAIKS). Why do you want to compare files by their icons?
FPU in a trice: SmplMath
It's that simple!

maruf10

just want to check .exe files having folder icon of my pen drive ... exmple : newfolder.exe , new folder.exe etc etc ....
it doesn't matter whether it is important or not ... i just want to delete those files .....

BlackVortex

For those files, what does shfi.szDisplayName contain ?

Should be string with path to the file containing the icon, example :  "C:\Windows\system32\imageres.dll" for default icons.

maruf10

#27
Quote
szDisplayName
    A string that contains the name of the file as it appears in the Windows Shell, or the path and file name of the file that contains the icon representing the file.

http://msdn.microsoft.com/en-us/library/bb759792%28VS.85%29.aspx

shfi.szDisplayName just displays the file name here   :red....


invoke SHGetFileInfo, addr aline, NULL, addr shfi, sizeof shfi, SHGFI_ICON or SHGFI_LARGEICON or SHGFI_ICONLOCATION or SHGFI_TYPENAME or SHGFI_DISPLAYNAME or SHGFI_USEFILEATTRIBUTES

invoke StdOut , OFFSET shfi.szDisplayName


here "aline" is the path to that file

qWord

in attachmend an Sample program that compare two icons by using GetDIBits. May it helps you to solve your problem...
FPU in a trice: SmplMath
It's that simple!

maruf10

The line below is not working in masm32 .....
Quote
invoke CmpIcon,_hIcon1,_hIcon2

which library/header file should i add to use this ??