hello I wanted to ask if anyone knows how to open a file you select from a list, the file has extention txt or asm. other than FileName db "\problemas\ ejemplo2.txt", 0 as it is very static, I want something more dynamic because I know the name of the file will be called
attached the file I am where I am working
LB_GETTEXT and ShellExecute are your friends, José :t
can you giveme an example please??
No, but you can search the forum.
hello I still have the same problem ... I think I not understand LB_GETTEXT use, the problem is that I could not pass (send) the file path to open (display contents), could help me please?
Post your code, with comments telling us what you have tried so far, and we'll see :icon14:
To open a file you use this function:
Quote
;----------------------------
; open a file for read
;----------------------------
invoke CreateFile,addr pathopenfile,GENERIC_READ,NULL,\
NULL,OPEN_EXISTING,FILE_ATTRIBUTE_NORMAL,0
.if eax==INVALID_HANDLE_VALUE
mov retour,eax
jmp somewhere
.endif
mov hFile,eax
If you are on a treeview,read the nod.This one can use a short path(only the name),you need the fool path (directory + name) to open it.
Search this name in a list of full path (you have to made this one) and pass the full path to the createfile function.
yes, something like that is what I tried. this is how I've been until now the treeview
Your filename is no good - this reserves one single byte:
FileName DB ?
This works (hola mundo) but it's a bit clumsy because I extract the true filename from mbp.lpszText:
mov eax, mbp.lpszText
.Repeat
inc eax
.Until byte ptr [eax]=="=" ; get start of filename
.Repeat
inc eax
.Until byte ptr [eax]>" " ; without whitespace
.data?
pFile dd ?
.code
mov pFile, eax ; store begin of filename
.Repeat
inc eax
.Until byte ptr [eax]<=" " ; find whitespace (won't work if your filename has spaces!!!)
mov byte ptr [eax], 0 ; delimit filename
;mov FileName, mbp.lpszText
invoke CreateFile,pFile,\
GENERIC_READ or GENERIC_WRITE ,\
FILE_SHARE_READ,\
NULL,OPEN_EXISTING,FILE_ATTRIBUTE_ARCHIVE,\
NULL
hello, thanks for the help they give me.
Now what I'm trying to do is to work the code you gave me when you select a file to asm these are in the "soluciones (asm)", not because it does not.
the other thing I wanted to ask is because EjecutarExe calls to run an exe file, and to probe the function separately (ShellExecute) and worked, not because here it does not, what is it I am doing wrong so that do not call?
Attached version opens ejemplo.txt in Notepad. Check for badcode in the *.asm source
You are pretty closen now :t
excuse me, i have a problem with RichMasm
You cannot use the MasmBasic library with ml.exe version 6.14, sorry - try JWasm or ml 6.15
##########################
\masm32\MasmBasic\MasmBasic.inc(176) : error A2052: forced error
TestMasmVersion(7): Macro Called From
\masm32\MasmBasic\MasmBasic.inc(176): Include File
*** Assembly Error ***
but i copy the JWasm in the \masm32\bin
the ml.exe version 6.15 i not found
Just add this somewhere:
; OPT_Assembler JWasm
you were right, I forgot to add the line told me.
but still not open asm files or run exe files, why is if you have the instructions?
another question: why did not you show me icons similarly if the user already has?
Hi,
I have no idea, but you can find out:
- in line 3, set useMB=1
- in line 581, insert this (see here for help (http://www.webalice.it/jj2006/MasmBasicQuickReference.htm#Mb1017)):
deb 1, "Line 580", eax, ebx, $tvi.pszText
You will see that tvi.pszText is always on ejemplo1.txt, so the error is before this line. Use the deb macro to find out where...
this is what I showed in result:
--in RichMasm:** RichMasm warning: Exit code 'still active' **
--in the windows:
Line 580
eax 1
ebx 6820384 (this data is variable)
$tvi.pszText ejemplo1.txt
CreateFile soluciones
$pFile2 problemas\ejemplo1.txt
eax 416 (this data is variable)
CreateFile ShellExecute with pFile
ecx 42
$eax [problemas\ejemplo1.txt]
i try with the seccion soluciones but showed the same data
So you see that whatever you select, you always get ejemplo1.txt, i.e. the first item on the list. That is not working. You need the correct item, and that can be done with a WM_NOTIFY handler that sets a global variable lastItem (you can use another name):
.elseif eax == WM_NOTIFY
cmp wParam, TV_OPTIONS
jne PassThrough
mov esi, lParam
mov ecx, [esi.NMHDR.code]
.if ecx==TVN_SELCHANGED
mov eax, [esi.NM_TREEVIEW.itemNew.hItem]
.data?
lastItem dd ?
.code
mov lastItem, eax
.endif
cmp ecx, TVN_SELCHANGING
jne PassThrough
Then, you can use lastItem here:
;##### mira si fue seleccionado
lea ecx, TempBuffer
mov byte ptr [ecx], 0
mov tvi.imask, TVIF_TEXT or TVIF_HANDLE
mov edi, lastItem
mov tvi.hItem, edi
mov tvi.pszText, ecx
mov tvi.cchTextMax, TempBufSize
invoke SendMessage, hTVOptions, TVM_GETITEM, 0, addr tvi
xchg eax, ebx
deb 1, "File A, GETITEM", eax, tvi.hItem, $tvi.pszText, tvi.imask
I hope this helps :icon14:
this is great!! now sends the correct filename ... but now I have the problem that for some reason I do not open the file txt / asm or run the exe
I guess the problem is when you send or receive the address of the file to open / run
I've attached the file so you can see as I have
thanks for the help
we get spoiled using the GetOpenFilename and GetSaveFilename dialogs - lol
with a listview, you may have to convert a name to a fully qualified path
With lastItem, everything becomes a lot simpler...:
ShowSelected proc uses ebx esi edi
LOCAL tvi:TVITEM, SmallBuffer[30]:BYTE, BigBuffer[60]:BYTE
lea esi, SmallBuffer
lea edi, BigBuffer
mov tvi.imask, TVIF_TEXT or TVIF_HANDLE
m2m tvi.hItem, lastItem
mov tvi.pszText, esi
mov tvi.cchTextMax, sizeof SmallBuffer
invoke SendMessage, hTVOptions, TVM_GETITEM, 0, addr tvi
mov ecx, len(esi) ; len is Masm32, Len is MasmBasic
mov eax, [esi+ecx-4] ; get the extension
or eax, 20202000h ; make all lowercase
.if eax=="txt." ; .txt
invoke lstrcpy, edi, chr$("problemas\")
invoke lstrcat, edi, esi
invoke ShellExecute, 0, 0, edi, 0, 0, SW_NORMAL
; deb 4, "Txt file", eax, $esi, $edi
.elseif eax=="msa." ; .asm
invoke lstrcpy, edi, chr$("soluciones\")
invoke lstrcat, edi, esi
invoke ShellExecute, 0, 0, edi, 0, 0, SW_NORMAL
; deb 4, "Asm file", eax, $esi, $edi
.elseif eax=="exe." ; .exe
invoke lstrcpy, edi, chr$("ejecutables\")
invoke lstrcat, edi, esi
invoke WinExec, edi, SW_NORMAL
; deb 4, "Exe file", eax, $esi
.else
MsgBox 0, esi, "ERROR: Unknown file", MB_OK
.endif
ret
ShowSelected endp
You saved me! thanks!! this is what I needed and did not know how to express it in assembler :greenclp:
Glad I could help - and hopefully you will remain an active member of the forum :icon14: