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

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.
be the king of accounting programmer world!

dedndave

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


elmo

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
be the king of accounting programmer world!

elmo

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

be the king of accounting programmer world!

elmo

Owh, I just forgot to put this line:

            INVOKE SendMessage, hList1, LVM_DELETEALLITEMS, 0, 0

The problem solved.
:dance: :cheekygreen: :bg
be the king of accounting programmer world!

xandaz

   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. :)

xandaz

   Ooops. This is so me. Forgot the attachment. There's a great chance that other things could be missing. Possibly my head.
   Bye.

dedndave

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

xandaz

   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

xandaz

   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

elmo

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?
be the king of accounting programmer world!

xandaz

    You can just use DeleteFile.
invoke SetCurrentDirectory,szPathFrom
invoke DeleteFile,addr FileName

elmo

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
be the king of accounting programmer world!

xandaz

   I'm checking it out elmo. I'll report in later. Thanks all for the help and oppurtunities to do so. Ty and bye.

xandaz

   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