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
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
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
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.
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
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
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 !
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
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?
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.
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
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.
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
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
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
In my PC, I had installed visualStudio.NET
So, I have 2 options if i want to open .asm file
with Notepad or with VisualStudio.NET
this thing can be done by change:
;_notepad db 'C:\windows\notepad.exe',0
with
_notepad db "C:\Program Files\Microsoft Visual Studio .NET 2003\Common7\IDE\devenv.exe",0
my problem now is:
I want to open .asm file with MicrosoftWord, I must find the path of msword.exe first
how to know the directory of msword.exe without look it on WindowsEplorer?
Are there any kind of API who can do this?
sory for my bad english.
as far as i know, it's in the same directory for all versions of office
C:\Program Files\Microsoft Office\Office
some versions call it winword.exe - some call it word.exe
you could look in the registry...
[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Office\8.0\Word\InstallRoot]
"Path"="\"C:\\Program Files\\Microsoft Office\\Office\""
but, the version will change - 8.0 in my case - lol
a better way would be to look at which programs open a DOC file
it's a bit involved to do it that way, but it would work on all machines
I had try to delete a file from my listview with the following code.
szPath contain a full path of that file.
But, in the screen appear:
cannot delete file:cannot read from the source file or disk
what's wrong?
http://www.masm32.com/board/index.php?PHPSESSID=45161102b7e9b36e503418a4d40f36ce&action=printpage;topic=10083.0
invoke GetCurrentDirectory,lengthof szPath,ADDR szPath
invoke PathAddBackslash,ADDR szPath ;only adds Backslash if missed
invoke lstrcat,addr szPath,addr szFileName
mov fo.hwnd, NULL
mov fo.wFunc, FO_DELETE
lea eax,szPath
mov fo.pFrom,eax
mov fo.pTo, NULL
mov fo.fFlags,FOF_ALLOWUNDO
invoke SHFileOperation,ADDR fo
Now, I have new problem.
Example: I list all of the file from directory C:\myfolder\*.* in mylistview
It works good. in my listview, it show:
.
..
folder1
file1.doc
file2.exe
Then, in my listview, I do double click on folder1, so the directory will be C:\myfolder\folder1 and will show the file from that directory:
.
..
file3.asm
file4.sys
But when I want to back to directory C:\myfolder\
In my listview, it show
..
folder1
file1.doc
file2.exe
.
..
file3.asm
file4.sys
So it is also show all of the file from previous directory.
This is my code. The following code has that problem.
Would you like to help me to solve this problem?
Thank you...
invoke SetCurrentDirectory,SADD("..")
;GET BACK DIRECTORY
INVOKE GetCurrentDirectory,lengthof szPath, addr szPath ;CURRENT DIRECTORY STORE TO szPath ;IN HERE WE GET C:\masm32
invoke MessageBox,0,addr szPath,SADD("Path after back"),0
invoke szTrim,ADDR szPath ;GET FILE TYPE
invoke szLen,ecx
.if eax==3
;ROOT DIRECTORY, EXAMPLE= C:\
.else
INVOKE lstrcat, addr szPath,SADD("\")
invoke lstrcpy, addr szPathTo,ADDR szPath
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
;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
;FILE ICON+FILE NAME
mov lvi.imask,LVIF_TEXT or LVIF_IMAGE
mov lvi.iSubItem,0
INVOKE lstrcpy, addr szPath,ADDR szPathTo
invoke lstrcat,addr szPath,addr FindData.cFileName
invoke SHGetFileInfo,ADDR szPath,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 ;ICON INDEX
mov lvi.iImage,eax
invoke SendMessage,hList1,LVM_SETITEM,0,addr lvi
invoke lstrcpy,addr szPath,SADD(" ")
;FILE TYPE
mov lvi.imask,LVIF_TEXT
inc lvi.iSubItem
INVOKE lstrcpy, addr szPath,ADDR szPathTo
invoke lstrcat,addr szPath,addr FindData.cFileName
invoke SHGetFileInfo,ADDR szPath, NULL, addr sfi, sizeof sfi, SHGFI_ICON+SHGFI_LARGEICON+SHGFI_ICONLOCATION+SHGFI_TYPENAME
lea eax,sfi.szTypeName
mov lvi.pszText,eax
invoke SendMessage,hList1,LVM_SETITEM,0,addr lvi
invoke lstrcpy,addr szPath,SADD(" ")
;FILE DIRECTORY
mov lvi.imask,LVIF_TEXT
inc lvi.iSubItem
INVOKE lstrcpy, addr szPath,ADDR szPathTo
lea eax,szPath
mov lvi.pszText,eax
invoke SendMessage,hList1,LVM_SETITEM,0,addr lvi
invoke lstrcpy,addr szPath,SADD(" ")
;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(" ")
;FILE SIZE
mov lvi.imask,LVIF_TEXT
inc lvi.iSubItem
INVOKE lstrcpy, addr szPath,ADDR szPathTo
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
invoke lstrcpy,addr szPath,SADD(" ")
;FILE TIME
mov lvi.imask,LVIF_TEXT
inc lvi.iSubItem
INVOKE lstrcpy, addr szPath,ADDR szPathTo
invoke lstrcat,addr szPath,ADDR FindData.cFileName
invoke CreateFile,
ADDR szPath,
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
invoke lstrcpy,addr szPath,SADD(" ")
INVOKE FindNextFile, hFind, addr FindData
inc edi
.endw
invoke FindClose,hFind
.endif
mov edi,0
invoke MessageBox,0,addr szPathTo,SADD("Path after looping"),0
invoke lstrcpy, addr szPathTo,SADD(" ")
invoke lstrcpy, addr szPath,SADD(" ")
invoke lstrcpy, addr STRFileName,SADD(" ")
invoke lstrcpy, addr STRFileType,SADD(" ")
.endif
Owh, I just forgot to put this line:
INVOKE SendMessage, hList1, LVM_DELETEALLITEMS, 0, 0
The problem solved.
:dance: :cheekygreen: :bg
Hey guys. I made this explorer type kinda program and i'm posting it so you can check it out. The source looks a bit messy and also i didnt use GetDriveStrings and the ListView control doesnt sort and so it doesnt do much but it looks good i think. I'm going to work a bit more on it and in some days i'll post a final example file.
Ty guys for all and bye. :)
Ooops. This is so me. Forgot the attachment. There's a great chance that other things could be missing. Possibly my head.
Bye.
that's pretty cool :U
win explorer (the GUI part) seems like such a simple thing - i bet it isn't all that simple to write :P
Yeah, it wasnt the easiest thing to do. Some changes need to be made tho. Especially in tree view items insertion. I Should use IShellFolder::GetAttributesOf and build the tree progressivelly as the user clicks the items. Takes to long to fill the whole tree at once. I Shall also sort the listview ....
Ty DednDave.
Bye
Things area bit more complex than i thought. I guess i should just check for any subdolder under the current directory's folder to enforce the treeview's cChildren member. Bye
Hi Xandaz, thank you for your attached file. It's good. Whoaaa.
I can show files from drive C:\ in my ListView.
2 weeks, I had tried to find how to delete a file in HDD from the selected file in that ListView.
I use API SHFileOperation:
mov fo.hwnd,NULL
mov fo.wFunc, FO_DELETE
m2m fo.pFrom,offset szPathFrom ;szPathFrom contain the full path of the selected table in ListView (Example: C:\file1.txt)
mov fo.pTo,NULL
mov fo.fFlags,FOF_ALLOWUNDO
invoke SHFileOperation,ADDR fo
I select file1.txt in my ListView. Then, I click menu delete in my program.
It will check the path of file1.txt (C:\file1.txt)
The above code must delete file1.txt from C:\file1.txt
But it fail, it always show warning:
"cannot delete file:cannot read from the source disk or file"
Could you help me how to do delete file in HDD from selected file in ListView?
You can just use DeleteFile.
invoke SetCurrentDirectory,szPathFrom
invoke DeleteFile,addr FileName
Hi xandaz, firstly, thank you for the advice.. :U
OK this is the code. This code must delete file1.txt from C:\
I think I had done it correctly.
But, if I use SHFileOperation, It still show the same warning:
"cannot delete file:cannot read from the source disk or file"
if I use DeleteFile, It show:
"delete fail"
Would you like to repair the following code?
Thank you
;STEP1. GET FILE NAME FROM THE LIST VIEW
INVOKE SendMessage, hList1, LVM_GETNEXTITEM, -1, LVNI_FOCUSED ;GET ROW ID
mov lvi.iItem, eax
mov lvi.iSubItem, 0
mov lvi.imask, LVIF_TEXT
lea eax, szFileName ;THIS IS CONTAIN file1.txt
mov lvi.pszText, eax
mov lvi.cchTextMax, 256
INVOKE SendMessage, hList1, LVM_GETITEM, 0, addr lvi
;STEP2.GET CURRENT FILE PATH
invoke SetCurrentDirectory,SADD("C:\")
invoke lstrcat,ADDR szPath,addr szFileName ;IN HERE, szPath WILL CONTAIN C:\file1.txt
;STEP3.DO DELETE
;mov fo.hwnd,NULL
;mov fo.wFunc, FO_DELETE
;lea eax,szPath
;mov fo.pFrom,eax
;mov fo.pTo,NULL
;mov fo.fFlags,FOF_ALLOWUNDO
;invoke SHFileOperation,ADDR fo
invoke szTrim,addr szFileName
invoke DeleteFile,ecx
.if eax==1
invoke MessageBox,0,SADD("delete ok"),SADD("delete"),0
.else
invoke MessageBox,0,SADD("delete failed"),SADD("delete"),0
.endif
I'm checking it out elmo. I'll report in later. Thanks all for the help and oppurtunities to do so. Ty and bye.
here it goes elmo. It's working tho at first i gave me som errors because i used drive c and it appeared to protected. You might want to change some of the paramneters to get it working on your machine. Also i didn't have time see why LVM_DELETEITEM gave error.- I just commented it. It doesnt delete through a menu command. You just ahve to select a list view item. It will ask for confirmation. Bye elmo
i think the prolblem may be that you're szFileName has path and filename, but you're already on the path since you set the current directory. pFrom should only contain the filename no path included. See if its like this. Bye elmo and guys.