News:

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

how to show file icon?

Started by elmo, November 07, 2010, 11:38:45 AM

Previous topic - Next topic

elmo

I have modify code from C:\masm32\examples\exampl06\listview
I hope I can show file icon like that
But I fail. I have search in: http://www.masm32.com/board/index.php?topic=12161.0

It still not solve my problem. Below was my code. What's wrong with my code?



         szText szColFileName,"FileName"
         szText szColTypeName,"TypeName"
         szText szColDisplayName,"DisplayName"
         szText szColiIcon,"iIcon"
         szText szColhIcon,"hIcon"


         INVOKE CreateWindowEx,
                  WS_EX_CLIENTEDGE,addr LISTVIEWclass,
                  NULL,
                  WS_CHILD or WS_VISIBLE or LVS_REPORT or LVS_SHAREIMAGELISTS,
                  0,50,400,300,hWin5,NULL,
                  400000h,NULL
         mov hList1, eax

         mov eax,LVS_EX_FULLROWSELECT or LVS_EX_HEADERDRAGDROP or LVS_EX_SUBITEMIMAGES or LVS_EX_GRIDLINES
         INVOKE SendMessage, hList1, LVM_SETEXTENDEDLISTVIEWSTYLE,0,eax

         INVOKE SHGetFileInfo,SADD("C:\"),0, addr sfi, sizeof SHFILEINFO,SHGFI_SYSICONINDEX or SHGFI_SMALLICON
         mov hImageListS,eax
         INVOKE SendMessage, hList1, LVM_SETIMAGELIST, LVSIL_SMALL, hImageListS


         INVOKE SendMessage, hList1, WM_SETFONT, hFont, 1
         INVOKE SendMessage, hList1, LVM_SETTEXTCOLOR, 0, 00ffff00h
         INVOKE SendMessage, hList1, LVM_SETBKCOLOR, 0, 00000000h
         INVOKE SendMessage, hList1, LVM_SETTEXTBKCOLOR, 0, 00000000h




         mov lvc.imask, LVCF_TEXT+LVCF_WIDTH
         mov lvc.pszText, offset szColFileName
         mov lvc.lx, 50         ;COLUMN WIDTH
         INVOKE SendMessage, hList1, LVM_INSERTCOLUMN, 0, addr lvc

         mov lvc.imask, LVCF_TEXT+LVCF_WIDTH
         mov lvc.pszText, offset szColTypeName
         mov lvc.lx,50
         INVOKE SendMessage, hList1, LVM_INSERTCOLUMN, 1, addr lvc

         mov lvc.imask, LVCF_TEXT+LVCF_WIDTH
         mov lvc.pszText, offset szColDisplayName
         mov lvc.lx,50
         INVOKE SendMessage, hList1, LVM_INSERTCOLUMN, 2, addr lvc

         mov lvc.imask, LVCF_TEXT+LVCF_WIDTH
         mov lvc.pszText, offset szColiIcon
         mov lvc.lx,50
         INVOKE SendMessage, hList1, LVM_INSERTCOLUMN, 3, addr lvc

         mov lvc.imask, LVCF_TEXT+LVCF_WIDTH
         mov lvc.pszText, offset szColhIcon
         mov lvc.lx,50
         INVOKE SendMessage, hList1, LVM_INSERTCOLUMN, 4, addr lvc




         INVOKE GetCurrentDirectory, lengthof szPath, addr szPath      ;CURRENT DIRECTORY STORE TO szPath
         INVOKE lstrcat, addr szPath,SADD("\")
         INVOKE lstrcat, addr szPath,SADD("*.*")
         INVOKE FindFirstFile, addr szPath, addr FindData
         .if eax != INVALID_HANDLE_VALUE
            mov hFind, eax
            xor edi, edi
            mov edi,0
            .while eax != 0
         ;      ;.if byte ptr [FindData.cFileName] != '.'
         ;         ;.if (FindData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
         ;         ;.else
         ;            ;invoke MessageBox,hWin5,addr FindData.cFileName,ADDR CONFIRM_DEBUG,MB_OK
         ;            .if (FindData.dwFileAttributes & FILE_ATTRIBUTE_READONLY)
         ;               invoke MessageBox,hWin5,addr FindData.cFileName,SADD("ReadOnly"),MB_OK
         ;            .endif
         ;            .if (FindData.dwFileAttributes & FILE_ATTRIBUTE_ARCHIVE)
         ;               invoke MessageBox,hWin5,addr FindData.cFileName,SADD("ARCHIVE"),MB_OK
         ;            .endif
         ;            .if (FindData.dwFileAttributes & FILE_ATTRIBUTE_HIDDEN)
         ;               invoke MessageBox,hWin5,addr FindData.cFileName,SADD("HIDDEN"),MB_OK
         ;            .endif
         ;            .if (FindData.dwFileAttributes & FILE_ATTRIBUTE_SYSTEM)
         ;               invoke MessageBox,hWin5,addr FindData.cFileName,SADD("SYSTEM"),MB_OK
         ;            .endif
         ;            INVOKE LoadListView, edi, addr FindData
         ;            inc edi
         ;            ;GET LAST MODIFIED TIME
         ;            ;INVOKE FileTimeToLocalFileTime, addr FindData.ftLastWriteTime, addr Lft
         ;            ;INVOKE FileTimeToSystemTime, addr Lft, addr time



                     invoke SHGetFileInfo,ADDR FindData.cFileName, NULL, addr sfi, sizeof sfi, SHGFI_ICON+SHGFI_LARGEICON+SHGFI_ICONLOCATION+SHGFI_TYPENAME

                     mov lvi.imask,LVIF_TEXT+LVIF_PARAM
                     push edi
                     pop lvi.iItem
                     mov lvi.iSubItem,0
                     lea eax,FindData.cFileName
                     mov lvi.pszText,eax
                     push edi
                     pop lvi.lParam
                     invoke SendMessage,hList1,LVM_INSERTITEM,0,addr lvi

                     mov lvi.imask,LVIF_TEXT
                     inc lvi.iSubItem
                     lea eax,sfi.szTypeName
                     mov lvi.pszText,eax
                     invoke SendMessage,hList1,LVM_SETITEM,0,addr lvi

                     mov lvi.imask,LVIF_TEXT
                     inc lvi.iSubItem
                     lea eax,sfi.szDisplayName
                     mov lvi.pszText,eax
                     invoke SendMessage,hList1,LVM_SETITEM,0,addr lvi

                     mov lvi.imask,LVIF_TEXT
                     inc lvi.iSubItem
                     lea eax,sfi.iIcon
                     mov lvi.pszText,eax
                     invoke SendMessage,hList1,LVM_SETITEM,0,addr lvi


                     mov lvi.imask,LVIF_TEXT
                     inc lvi.iSubItem
                     invoke SHGetFileInfo,ADDR FindData.cFileName,0,ADDR sfi,SIZEOF sfi, SHGFI_ICON or SHGFI_LARGEICON or SHGFI_DISPLAYNAME
                     lea eax,sfi.hIcon
                     ;mov lvi.pszText,eax
                     mov lvi.iImage, eax
                     invoke SendMessage,hList1,LVM_SETITEM,0,addr lvi



                     INVOKE FindNextFile, hFind, addr FindData
                     inc edi
         ;         ;.endif
         ;      ;.endif
            .endw
         .endif
         mov edi,0
be the king of accounting programmer world!

Coma

                     mov lvi.imask,LVIF_TEXT or LVIF_IMAGE
                     inc lvi.iSubItem
                     invoke SHGetFileInfo,ADDR FindData.cFileName,0,ADDR sfi,SIZEOF sfi, SHGFI_ICON or SHGFI_LARGEICON or SHGFI_DISPLAYNAME
                     lea eax,sfi.hIcon
                     ;mov lvi.pszText,eax

                     mov    eax,sfi.iIcon
                     mov lvi.iImage,eax

                     invoke SendMessage,hList1,LVM_SETITEM,0,addr lvi
Coma Homepage 20:00-23:00 GMT+2 --- http://ge2001.dyndns.org:44792

elmo

#2
The code works good! Thank you Coma

Now, I have 1 more problem about this.
If I do doubleclick on file.doc, it will show it' contain in MicrosoftWord.
If I do doubleclick on file.xls, it will show it' contain in MicrosoftExcel.
If I do doubleclick on file.jpg, it will show it' contain WindowsPictureAndFaxViewer
etc...
How to do this?


If I do doubleclick on file.exe, I can run it by :   

   invoke WinExec,ADDR Dir,SW_NORMAL   ;FILE MUST EXE,COM, BAT or PIF
        ;WHERE DIR IS DIRECTORY OF THE .EXE FILE









         INVOKE CreateWindowEx,
                  WS_EX_CLIENTEDGE,addr LISTVIEWclass,
                  NULL,
                  WS_CHILD or WS_VISIBLE or LVS_REPORT or LVS_SHAREIMAGELISTS,
                  0,150,360,200,hWin5,NULL,
                  400000h,NULL
         mov hList1, eax



         mov eax,LVS_EX_FULLROWSELECT or LVS_EX_HEADERDRAGDROP or LVS_EX_SUBITEMIMAGES or LVS_EX_GRIDLINES
         INVOKE SendMessage, hList1, LVM_SETEXTENDEDLISTVIEWSTYLE,0,eax



         invoke SHGetFileInfo, SADD("C:\"), FILE_ATTRIBUTE_NORMAL,addr sfi,sizeof SHFILEINFO, SHGFI_SYSICONINDEX
         mov hImageListS,eax
         INVOKE SendMessage, hList1, LVM_SETIMAGELIST, LVSIL_SMALL, hImageListS



         INVOKE SendMessage, hList1, WM_SETFONT, hFont, 1
         INVOKE SendMessage, hList1, LVM_SETTEXTCOLOR, 0, 00ffff00h
         INVOKE SendMessage, hList1, LVM_SETBKCOLOR, 0, 00000000h
         INVOKE SendMessage, hList1, LVM_SETTEXTBKCOLOR, 0, 00000000h




         mov lvc.imask, LVCF_TEXT+LVCF_WIDTH
         mov lvc.pszText, offset szColFileName
         mov lvc.lx, 50         ;COLUMN WIDTH
         INVOKE SendMessage, hList1, LVM_INSERTCOLUMN, 0, addr lvc

         mov lvc.imask, LVCF_TEXT+LVCF_WIDTH
         mov lvc.pszText, offset szColTypeName
         mov lvc.lx,50
         INVOKE SendMessage, hList1, LVM_INSERTCOLUMN, 1, addr lvc

         mov lvc.imask, LVCF_TEXT+LVCF_WIDTH
         mov lvc.pszText, offset szColDirectory
         mov lvc.lx,50
         INVOKE SendMessage, hList1, LVM_INSERTCOLUMN, 2, addr lvc

         mov lvc.imask, LVCF_TEXT+LVCF_WIDTH
         mov lvc.pszText, offset szColAttribut
         mov lvc.lx,50
         INVOKE SendMessage, hList1, LVM_INSERTCOLUMN, 3, addr lvc




         INVOKE GetCurrentDirectory, lengthof szPath, addr szPath      ;CURRENT DIRECTORY STORE TO szPath
         INVOKE lstrcat, addr szPath,SADD("\")
         INVOKE lstrcat, addr szPath,SADD("*.*")
         INVOKE FindFirstFile, addr szPath, addr FindData
         .if eax != INVALID_HANDLE_VALUE
            mov hFind, eax
            xor edi, edi
            mov edi,0
            .while eax != 0
               ;.if byte ptr [FindData.cFileName] != '.'
                  ;.if (FindData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
                  ;.else
                     ;invoke MessageBox,hWin5,addr FindData.cFileName,ADDR CONFIRM_DEBUG,MB_OK
                     ;GET LAST MODIFIED TIME
                     ;INVOKE FileTimeToLocalFileTime, addr FindData.ftLastWriteTime, addr Lft
                     ;INVOKE FileTimeToSystemTime, addr Lft, addr time




                     ;FILE NAME
                     ;invoke SHGetFileInfo,ADDR FindData.cFileName, NULL, addr sfi, sizeof sfi, SHGFI_ICON+SHGFI_LARGEICON+SHGFI_ICONLOCATION+SHGFI_TYPENAME
                     mov lvi.imask,LVIF_PARAM
                     push edi
                     pop lvi.iItem
                     mov lvi.iSubItem,0
                     push edi
                     pop lvi.lParam
                     invoke SendMessage,hList1,LVM_INSERTITEM,0,addr lvi




                     ;FILE ICON
                     mov lvi.imask,LVIF_TEXT or LVIF_IMAGE
                     mov lvi.iSubItem,0
                     invoke SHGetFileInfo,ADDR FindData.cFileName,0,ADDR sfi,SIZEOF sfi, SHGFI_ICON or SHGFI_LARGEICON or SHGFI_DISPLAYNAME
                     lea eax,FindData.cFileName
                     mov lvi.pszText,eax
                     mov eax,sfi.iIcon
                     mov lvi.iImage,eax
                     invoke SendMessage,hList1,LVM_SETITEM,0,addr lvi





                     ;FILE TYPE
                     invoke SHGetFileInfo,ADDR FindData.cFileName, NULL, addr sfi, sizeof sfi, SHGFI_ICON+SHGFI_LARGEICON+SHGFI_ICONLOCATION+SHGFI_TYPENAME
                     mov lvi.imask,LVIF_TEXT
                     inc lvi.iSubItem
                     lea eax,sfi.szTypeName
                     mov lvi.pszText,eax
                     invoke SendMessage,hList1,LVM_SETITEM,0,addr lvi




                     ;FILE DIRECTORY
                     mov lvi.imask,LVIF_TEXT
                     inc lvi.iSubItem
                     INVOKE GetCurrentDirectory,lengthof szPath, addr szPath      ;CURRENT DIRECTORY STORE TO szPath
                     lea eax,szPath
                     mov lvi.pszText,eax
                     invoke SendMessage,hList1,LVM_SETITEM,0,addr lvi




                     ;FILE ATTRIBUT
                     mov lvi.imask,LVIF_TEXT
                     inc lvi.iSubItem
                     .if (FindData.dwFileAttributes & FILE_ATTRIBUTE_READONLY)
                        invoke lstrcat,addr szAttribut,SADD("R")
                     .endif
                     .if (FindData.dwFileAttributes & FILE_ATTRIBUTE_ARCHIVE)
                        invoke lstrcat,addr szAttribut,SADD("A")
                     .endif
                     .if (FindData.dwFileAttributes & FILE_ATTRIBUTE_HIDDEN)
                        invoke lstrcat,addr szAttribut,SADD("H")
                     .endif
                     .if (FindData.dwFileAttributes & FILE_ATTRIBUTE_SYSTEM)
                        invoke lstrcat,addr szAttribut,SADD("S")
                     .endif
                     lea eax,szAttribut
                     mov lvi.pszText,eax
                     invoke SendMessage,hList1,LVM_SETITEM,0,addr lvi
                     invoke lstrcpy,addr szAttribut,SADD(" ")





                     INVOKE FindNextFile, hFind, addr FindData
                     inc edi
                  ;.endif
               ;.endif
            .endw
         .endif
         mov edi,0
be the king of accounting programmer world!

Coma

response to the WM_NOTIFY message.

szOpen                  db "open",0
szWordpad             db "wordpad.exe",0 ;i.e. ADDR Buffer program used to open the selected file

; -------------------------------------------------------------------------
WP_WM_NOTIFY:
cmp     eax,WM_NOTIFY
jne     WP_WM_DISPLAYCHANGE ;branch to next message
; -------------------------------------------------------------------------
mov     ebx,WP_lParam
mov     eax,[ebx+0]
cmp     eax,hList1
jne     WP_Return ;exit
;---
mov     eax,[ebx+8]
cmp     eax,NM_DBLCLK
je      WM_NotifyhList1Execute
cmp     eax,NM_RETURN
je      WM_NotifyhList1Execute
jmp     WP_Return ;exit
;---
WM_NotifyhList1Execute:
invoke  SendMessage,hList1,LVM_GETNEXTITEM,-1,LVNI_SELECTED or LVNI_FOCUSED
cmp     eax,-1
;je      Error
mov     lvi.iSubItem,0 ;not a subitem
mov     lvi.pszText,OFFSET BufferFile
mov     lvi.cchTextMax,MAX_PATH
invoke  SendMessage,hList1,LVM_GETITEMTEXT,eax,ADDR lvi ;eax=index item

invoke  GetCurrentDirectory,lengthof szPath,ADDR szPath
;invoke  PathAddBackslash,ADDR szPath ;only adds Backslash if missed
;invoke  lstrcat,ADDR szPath,ADDR BufferFile
;invoke  MessageBox,0,ADDR szPath,0,MB_OK ; usefull to see the string
;invoke  ShellExecute,handleMainWindow,ADDR string 'open',ADDR Buffer program used to open the selected file,ADDR Buffer filename from Listview,ADDR Buffer default directory,SW_SHOWNORMAL
;to open a file with a specified program further coding is required, checking the extension and than open the file with the program of your choice, but maybe it is not available on the users system !

invoke  ShellExecute,hWin5,ADDR szOpen,ADDR BufferFile,0,ADDR szPath,SW_SHOWNORMAL ; use the default program associated with the file on the users (not the programmers !) system
cmp     eax,32
;jbe     Error

jmp     WP_Return ;exit

http://msdn.microsoft.com/en-us/library/bb775583%28VS.85%29.aspx
http://msdn.microsoft.com/en-us/library/bb774867%28VS.85%29.aspx
http://msdn.microsoft.com/en-us/library/bb762153%28VS.85%29.aspx
http://msdn.microsoft.com/en-us/library/bb762154%28v=VS.85%29.aspx

maybe it is more easy to get the text of the selected item or subitem using the NMITEMACTIVATE structure.
Coma Homepage 20:00-23:00 GMT+2 --- http://ge2001.dyndns.org:44792

elmo

What an awesome! Thank you Coma
The code work good!  :cheekygreen:  :U

I can use SHELLEXECUTEINFO too      (http://www.winasm.net/forum/index.php?showtopic=2096&st=5)

But, now the new problem appear.

In Windows, if we do right-click on file.asm/ Then we chose, Open With/ Then we click Notepad, It will show the contain of file.asm in Notepad.
But In my PC, I have installed VisualStudio.NET.  So, If I use the following code, It will show the contain of file.asm in VisualStudio.NET
How to open it with Notepad, so it will like Windows (Open With)?



Here is my code:

                  invoke SetCurrentDirectory,SADD("C:\masm32\bin\")


                  invoke GetCurrentDirectory,lengthof szPath,ADDR szPath
                  invoke PathAddBackslash,ADDR szPath         ;only adds Backslash if missed
                  invoke lstrcat,ADDR szPath,SADD("File.asm")
                  invoke MessageBox,0,ADDR szPath,0,MB_OK         ;usefull to see the string

                  szText szOpen,"OPEN"
                  ;invoke RtlZeroMemory, addr sei, sizeof sei
                  ;mov sei.cbSize, sizeof sei
                  ;mov sei.fMask, SEE_MASK_NOCLOSEPROCESS or SEE_MASK_NO_CONSOLE
                  ;mov sei.lpVerb, offset szOpen
                  ;mov sei.lpFile, offset szPath
                  ;invoke ShellExecuteEx, addr sei

                  invoke  ShellExecute,hWin5,ADDR szOpen,ADDR szPath,0,ADDR szPath,SW_SHOWNORMAL
be the king of accounting programmer world!

dedndave

try holding the shift key when you right-click
you may get the "Open With" selection on the context menu
otherwise, you may have to change some registry settings to get the Open With option

Coma

You can create a custom popup menu.
Handle the messages via the WM_COMMAND message (get the item text from the listview control and use ShellExecute).

WM_CREATE:
invoke  CreatePopupMenu
mov     hPopup,eax
invoke  AppendMenu,hPopup,MF_STRING,6000,ADDR szNotepad
invoke  AppendMenu,hPopup,MF_STRING,6001,ADDR szWordpad
invoke  AppendMenu,hPopup,MF_SEPARATOR,0,0
invoke  AppendMenu,hPopup,MF_STRING,6008,ADDR szDefault
invoke  AppendMenu,hPopup,MF_STRING,6009,ADDR szCancel

WM_NOTIFY:
mov     ebx,WP_lParam
mov     eax,[ebx+0]
cmp     eax,hList1
jne     WP_Return ;exit
;---
mov     eax,[ebx+8]
cmp     eax,NM_RCLICK
je      WM_NotifyhList1Popup
cmp     eax,NM_DBLCLK
je      WM_NotifyhList1Execute
cmp     eax,NM_RETURN
je      WM_NotifyhList1Execute
jmp     WP_Return ;exit
;---
WM_NotifyhList1Execute:
invoke  SendMessage,hList1,LVM_GETNEXTITEM,-1,LVNI_SELECTED or LVNI_FOCUSED
cmp     eax,-1
;je      Error
mov     lvi.iSubItem,0 ;not a subitem
mov     lvi.pszText,OFFSET BufferFile
mov     lvi.cchTextMax,MAX_PATH
invoke  SendMessage,hList1,LVM_GETITEMTEXT,eax,ADDR lvi ;eax=index item
invoke  GetCurrentDirectory,lengthof szPath,ADDR szPath
;invoke  ShellExecute,hWin5,ADDR string 'open',ADDR Buffer program used to open the selected file,ADDR Buffer filename from Listview,ADDR Buffer default directory,SW_SHOWNORMAL ;use this if you like to open the file with a custom program (i.e. Notepad.exe)
invoke  ShellExecute,hWin5,ADDR szOpen,ADDR BufferFile,0,ADDR szPath,SW_SHOWNORMAL ; use the default program associated with the file on the users (not the programmers !) system
cmp     eax,32
;jbe     Error
jmp     WP_Return ;exit
;---
WM_NotifyhList1Popup:
invoke  SendMessage,hList1,LVM_GETITEMCOUNT,0,0
cmp     eax,0
je      WP_Return ;exit, listview is empty, nothing to do
invoke  SetFocus,hList1
invoke  GetCursorPos,ADDR pt
invoke  TrackPopupMenuEx,hPopup,TPM_LEFTBUTTON,pt.x,pt.y,hWin5,0
jmp     WP_Return ;exit

WM_COMMAND:
mov     eax,WP_wParam ;control or menu ID in ax
cmp     ax,6000
jne     WP_Return ;next popup menu id or exit

Get the listview item here and perform ShellExecute.

jmp   WP_Return ;exit


This should work ... (not tested, maybe i forget something)


As i said in a post above, the file association depends on the user system !
You can't assume that i.e. Notepad.exe or Wordpad.exe is available on the user's system !
Also you should know the path to that programs, you can't suppose that the Path var, to i.e. Notepad.exe, is available on the user's system.
So, what you want to do is not save !!!
In other words, if the user like to open an asm file with visual studio you should accept that.
Anyway, with a popupmenu, you can offer an alternativ program to open the asm file (if failed display a messagebox to inform the user).
Under no circumstances you should change the file association in the registry on the user's system without inquiry !

Coma Homepage 20:00-23:00 GMT+2 --- http://ge2001.dyndns.org:44792

elmo

From my previous code, I try to use this following code to show filesize in the listview.

                 invoke CreateFile,
                     ADDR FindData.cFileName,
                     GENERIC_READ,
                     FILE_SHARE_READ,
                     NULL,
                     OPEN_EXISTING,
                     FILE_ATTRIBUTE_NORMAL,
                     NULL
            mov hFile, eax
            mov lvi.imask,LVIF_TEXT
            inc lvi.iSubItem
            INVOKE GetCurrentDirectory,lengthof szPath, addr szPath      ;CURRENT DIRECTORY STORE TO szPath
            invoke lstrcat,addr szPath,SADD("\")
            invoke lstrcat,addr szPath,ADDR FindData.cFileName
            invoke GetFileSize, hFile, 0
            ;invoke filesize,ADDR szPath
            mov lvi.pszText,eax
            invoke SendMessage,hList1,LVM_SETITEM,0,addr lvi



But it fail. What wrong with the code? It not work.

http://www.asmcommunity.net/board/index.php?topic=27810.0;wap2
http://www.daniweb.com/forums/thread63061.html
be the king of accounting programmer world!

elmo

Yes!!! I found the solution. But if I find a Folder, it size=0. What's wrong?

            ;FILE SIZE
            mov lvi.imask,LVIF_TEXT
            inc lvi.iSubItem
            invoke lstrcpy,addr szPath,SADD(" ")
            INVOKE GetCurrentDirectory,lengthof szPath, addr szPath      ;CURRENT DIRECTORY STORE TO szPath
            invoke lstrcat,addr szPath,SADD("\")
            invoke lstrcat,addr szPath,ADDR FindData.cFileName
            invoke wsprintf,addr buffer, addr template,FindData.nFileSizeLow
            lea eax,buffer
            ;invoke filesize,ADDR szPath
            mov lvi.pszText,eax
            invoke SendMessage,hList1,LVM_SETITEM,0,addr lvi



Now, I want to show data about:
FileLastAccessTime or FileLastModifiedTime
FileCreateTime

Could you help me show the code to solve this?
be the king of accounting programmer world!

Coma

#9
Maybe another member can help you with your last question (i don't have time this weekend).

But i just found this:

Maybe you can use the 'openas' keyword (sei.Verb = "openas") with API ShellExecuteEx and the ShellExecuteInfo structure.

If this works things are much more easy now and it is exactly what you want to do (Displaying the OpenWith dialog).

Tell us if it works.
Coma Homepage 20:00-23:00 GMT+2 --- http://ge2001.dyndns.org:44792

elmo

Yes I found a way how to show file time from here:
http://www.asmcommunity.net/board/index.php?action=printpage;topic=11157.0

:cheekygreen: :green2 :dance:


But some file in my window explorer, show different time with the following code.
Example:
With windowsExplorer, a file name show:   modified=Sunday, October 03, 2010, 7:47:36 AM
But with the folowing code, it's show:   modified=Sunday, October 03, 2010, 8:47:36 AM
so it's time different 1 hour.
What's wrong with the following code?
Could you help me please?.
Thank you.


         ;FILE TIME
         mov lvi.imask,LVIF_TEXT
         inc lvi.iSubItem
         invoke CreateFile,
                  ADDR FindData.cFileName,
                  GENERIC_READ,FILE_SHARE_READ,0,
                  OPEN_EXISTING,FILE_ATTRIBUTE_NORMAL,0
         mov hFile,eax
         invoke GetFileTime,eax,ADDR Created,ADDR LastAccessed,ADDR LastWrittenTo
         invoke FileTimeToSystemTime, ADDR Created, ADDR systemCreated
         invoke FileTimeToSystemTime, ADDR LastAccessed, ADDR systemLastAccessed
         invoke FileTimeToSystemTime, ADDR LastWrittenTo, ADDR systemLastWrittenTo
         invoke GetTimeZoneInformation, ADDR zoneInfo
         invoke SystemTimeToTzSpecificLocalTime, ADDR zoneInfo, ADDR systemCreated, ADDR localCreated
         invoke SystemTimeToTzSpecificLocalTime, ADDR zoneInfo, ADDR systemLastAccessed, ADDR localLastAccessed
         invoke SystemTimeToTzSpecificLocalTime, ADDR zoneInfo, ADDR systemLastWrittenTo, ADDR localLastWrittenTo

         ;typedef struct _SYSTEMTIME
         ;{
         ;   WORD wYear;
         ;   WORD wMonth;
         ;   WORD wDayOfWeek;
         ;   WORD wDay;
         ;   WORD wHour;
         ;   WORD wMinute;
         ;   WORD wSecond;
         ;   WORD wMilliseconds;
         ;}   SYSTEMTIME, *PSYSTEMTIME;

         mov esi, OFFSET localLastWrittenTo
         ASSUME esi:ptr SYSTEMTIME
         movzx eax, [esi].wSecond
         push eax
         movzx eax, [esi].wMinute
         push eax
         movzx eax, [esi].wHour
         push eax
         movzx eax, [esi].wYear
         push eax
         movzx eax, [esi].wMonth
         push eax
         movzx eax, [esi].wDay
         push eax
         ASSUME esi:nothing

         push OFFSET ftimemodified
         push OFFSET buf
         call wsprintf
         lea eax,buf
         mov lvi.pszText,eax
         invoke SendMessage,hList1,LVM_SETITEM,0,addr lvi
be the king of accounting programmer world!

donkey

The one hour discrepancy is probably because you have daylight savings time in your time zone, it will offset the time by an hour. BTW, you can get the information formatted for you without wsprintf using:

invoke FileTimeToSystemTime, OFFSET ftLastWriteTime, OFFSET stLocal
invoke GetDateFormat, LOCALE_SYSTEM_DEFAULT, NULL, OFFSET stLocal, "dd MMM yyyy", OFFSET szDate, 64


If you do use wsprintf without INVOKE you have to adjust ESP, it uses C calling convention.
"Ahhh, what an awful dream. Ones and zeroes everywhere...[shudder] and I thought I saw a two." -- Bender
"It was just a dream, Bender. There's no such thing as two". -- Fry
-- Futurama

Donkey's Stable

elmo

Donkey, Thanks for the Info!!  :U
http://www.asmcommunity.net/board/index.php?action=printpage;topic=6731.0


Now, I have new problem. I want to list the drive that avail in my PC. My PC has drive
C:\
D:\
E:\
G:\
H:\
The following code show wrong icon. And not show drive letter (C:\, D:\, E:\, G:\, H:\) in my listview
Could you help me to solve this problem?

Thank you.

I had try to modify the code from:
http://www.winasm.net/forum/index.php?showtopic=3163
But it fail to add a string in my ListView.




;LIST OF THE DRIVE LETTER THAT EXIST IN YOUR MACHINE
INVOKE SendMessage, hList1, LVM_DELETEALLITEMS, 0, 0


;=================================================================================
;WRONG IN HERE
invoke SHGetFileInfo,SADD("C:\"),FILE_ATTRIBUTE_NORMAL,addr sfi,sizeof SHFILEINFO,SHGFI_SYSICONINDEX or SHGFI_SMALLICON
;=================================================================================
mov hImageListS,eax
INVOKE SendMessage, hList1, LVM_SETIMAGELIST, LVSIL_SMALL, hImageListS

invoke GetLogicalDriveStrings,sizeof drivestr,addr drivestr
lea esi,drivestr
lea ebx,[esi+eax]
.while esi < ebx
;DRIVE TYPE
invoke GetDriveType,esi
.if eax == DRIVE_FIXED
;show Type=HDD
.elseif eax == DRIVE_CDROM
;show Type=CDROM
.elseif eax == DRIVE_REMOVABLE
;show Type=REMOVABLE
.endif

;DETERMINE NTFS/FAT
INVOKE GetVolumeInformation,
                  esi,
        addr vol_filename,320, ;DEVICE NAME
     0,
          0,
        0,
ADDR volname, ;FILE SYSTEM(NTFS/FAT)
MAX_PATH

;DISK SPACE
invoke GetDiskFreeSpaceEx, esi,addr freeSpace,addr totalSpace,0
invoke StrFormatByteSize64, totalSpace, totalSpace+4, ADDR totalbuffer, SIZEOF totalbuffer
invoke StrFormatByteSize64, freeSpace, freeSpace+4, ADDR freebuffer, SIZEOF freebuffer

;ROW ID
mov lvi.imask,LVIF_PARAM
push edi
pop lvi.iItem
mov lvi.iSubItem,0
push edi
pop lvi.lParam
invoke SendMessage,hList1,LVM_INSERTITEM,0,addr lvi

;DRIVE STRING
mov lvi.imask,LVIF_TEXT
mov lvi.iSubItem,0
mov lvi.pszText,offset totalbuffer              ;===================>WRONG IN HERE
invoke SendMessage,hList1,LVM_SETITEM,0,addr lvi

inc edi
invoke szLen,esi
lea esi,[esi+eax+1]
.endw
be the king of accounting programmer world!

elmo

Hi Coma, here is I found the solution to do "OPEN WITH"
from:
http://board.flatassembler.net/topic.php?p=119110
http://www.masm32.com/board/index.php?PHPSESSID=7b5fb053d88fe3dee45b10cac71fee0f&topic=13941.0;prev_next=prev


here is the code that I had modified.
But, when I want to re-compile it with:
ml /c /coff /Cp filename.asm
then
link /SUBSYSTEM:WINDOWS /LIBPATH:C:\masm32\lib filename.obj
in the screen appear,
LINK : fatal error LNK1104: cannot open file "filename.exe"
so, I must rename it with filename2.asm
then I do the same thing, so I get the same result. I must rename it again, and so on.
What wrong with the code? thank you







.DATA


_runas   db 'runas',0
  _notepad db 'notepad.exe',0
  _test    db 'C:\masm32\bin\file1.asm',0


.DATA?
sei      SHELLEXECUTEINFO <>

.CODE

PROGRAM:


    ; Requests the OS to run the executable elevated.
    ; Returns TRUE if successful, or FALSE otherwise.
    ; If FALSE then return error information in edx
   

    INVOKE RtlZeroMemory, ADDR sei, SIZEOF sei
    mov sei.cbSize, SIZEOF SHELLEXECUTEINFO
    mov eax, 0
    mov sei.hwnd, eax
    mov sei.fMask, SEE_MASK_FLAG_DDEWAIT OR SEE_MASK_FLAG_NO_UI
   lea eax,_runas
    mov sei.lpVerb,eax
   lea eax, _notepad
    mov sei.lpFile, eax
    lea eax, _test
    mov sei.lpParameters, eax
    mov sei.nShow, SW_SHOWNORMAL
    INVOKE ShellExecuteEx, ADDR sei
    .IF eax == FALSE
        INVOKE GetLastError
        mov edx, eax
        xor eax, eax
    .ELSE   
        mov eax, 1
    .ENDIF   
    ret


END PROGRAM
be the king of accounting programmer world!

elmo

owh I found the solution. Here we are. But the following code can't show what kind of error.

:dance: :cheekygreen: :toothy :bg :green2

.DATA
   _runas   db 'runas',0
   _notepad db 'notepad.exe',0
   _test    db 'C:\masm32\bin\file1.asm',0


.DATA?
   sei      SHELLEXECUTEINFO <>
   err      db 32 dup(?)
   hModule      db 32 dup(?)
   dwFlags      db 32 dup(?)
   pTmpBuffer   BYTE ?



.CODE


PROGRAM:
call main
ret

main PROC
   LOCAL szBuffer[256]:BYTE

   ;Requests the OS to run the executable elevated.
   ;Returns TRUE if successful, or FALSE otherwise.
   ;If FALSE then return error information in edx
   INVOKE RtlZeroMemory, ADDR sei, SIZEOF sei
   mov sei.cbSize, SIZEOF SHELLEXECUTEINFO
   mov eax, 0
   mov sei.hwnd, eax
   mov sei.fMask, SEE_MASK_FLAG_DDEWAIT OR SEE_MASK_FLAG_NO_UI
   lea eax,_runas
   mov sei.lpVerb,eax
   lea eax, _notepad
   mov sei.lpFile, eax
   lea eax, _test
   mov sei.lpParameters, eax
   mov sei.nShow, SW_SHOWNORMAL
   INVOKE ShellExecuteEx, ADDR sei
   .IF eax == FALSE
      INVOKE GetLastError
      mov edx, eax
      xor eax, eax
   .ELSE
      mov eax, 1
   .ENDIF


   ;GET ERROR MESSAGE
   .IF eax == FALSE
      mov hModule, NULL
      mov pTmpBuffer,NULL
      invoke lstrcpy,addr dwFlags,FORMAT_MESSAGE_ALLOCATE_BUFFER OR FORMAT_MESSAGE_FROM_SYSTEM OR FORMAT_MESSAGE_IGNORE_INSERTS
      .IF edx >= NERR_BASE && edx <= MAX_NERR
         INVOKE LoadLibraryEx,SADD("netmsg.dll"), NULL, LOAD_LIBRARY_AS_DATAFILE
         invoke lstrcpy,addr hModule, eax
         .IF hModule != NULL
            invoke lstrcpy,addr dwFlags,FORMAT_MESSAGE_ALLOCATE_BUFFER OR FORMAT_MESSAGE_FROM_SYSTEM OR FORMAT_MESSAGE_IGNORE_INSERTS or FORMAT_MESSAGE_FROM_HMODULE
         .ENDIF
      .endif
      INVOKE GetUserDefaultLangID
      INVOKE FormatMessage, dwFlags,hModule,edx,eax, ADDR pTmpBuffer, 0, NULL
      .IF eax
         INVOKE lstrcpyn,addr szBuffer, pTmpBuffer, SIZEOF szBuffer-1
         INVOKE LocalFree, pTmpBuffer
         ;mov retv, 0
      .ELSE
         INVOKE GetLastError
         ;mov retv, eax
      .ENDIF
      .IF hModule != NULL
         INVOKE FreeLibrary, hModule
      .ENDIF
      ;mov eax, retv
      INVOKE MessageBox, NULL, ADDR szBuffer, SADD("Error Message"), MB_ICONERROR
   .ENDIF
main ENDP
be the king of accounting programmer world!