The MASM Forum

General => The Campus => Topic started by: 03.jose on July 30, 2012, 09:09:38 AM

Title: select file of the list
Post by: 03.jose on July 30, 2012, 09:09:38 AM
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
Title: Re: select file of the list
Post by: jj2007 on July 30, 2012, 09:22:35 AM
LB_GETTEXT and ShellExecute are your friends, José :t
Title: Re: select file of the list
Post by: 03.jose on August 01, 2012, 01:57:28 AM
can you giveme an example please??
Title: Re: select file of the list
Post by: jj2007 on August 01, 2012, 03:12:27 AM
No, but you can search the forum.
Title: Re: select file of the list
Post by: 03.jose on August 17, 2012, 03:31:19 PM
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?
Title: Re: select file of the list
Post by: jj2007 on August 17, 2012, 04:20:06 PM
Post your code, with comments telling us what you have tried so far, and we'll see :icon14:
Title: Re: select file of the list
Post by: TouEnMasm on August 17, 2012, 05:54:24 PM
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.






Title: Re: select file of the list
Post by: 03.jose on August 18, 2012, 07:38:44 AM
yes, something like that is what I tried. this is how I've been until now the treeview
Title: Re: select file of the list
Post by: jj2007 on August 18, 2012, 08:29:47 AM
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
Title: Re: select file of the list
Post by: 03.jose on August 19, 2012, 12:49:59 PM
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?
Title: Re: select file of the list
Post by: jj2007 on August 19, 2012, 05:55:35 PM
Attached version opens ejemplo.txt in Notepad. Check for badcode in the *.asm source

You are pretty closen now :t
Title: Re: select file of the list
Post by: 03.jose on August 20, 2012, 10:58:07 AM
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
Title: Re: select file of the list
Post by: jj2007 on August 20, 2012, 11:30:23 AM
Just add this somewhere:

; OPT_Assembler   JWasm




Title: Re: select file of the list
Post by: 03.jose on August 20, 2012, 02:50:42 PM
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?
Title: Re: select file of the list
Post by: jj2007 on August 20, 2012, 03:40:16 PM
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...
Title: Re: select file of the list
Post by: 03.jose on August 21, 2012, 07:31:46 AM
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
Title: Re: select file of the list
Post by: jj2007 on August 21, 2012, 08:09:04 PM
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:
Title: Re: select file of the list
Post by: 03.jose on August 22, 2012, 10:54:12 AM
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
Title: Re: select file of the list
Post by: dedndave on August 22, 2012, 11:59:33 AM
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
Title: Re: select file of the list
Post by: jj2007 on August 22, 2012, 10:35:55 PM
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
Title: Re: select file of the list
Post by: 03.jose on August 23, 2012, 07:25:04 AM
You saved me! thanks!! this is what I needed and did not know how to express it in assembler :greenclp:
Title: Re: select file of the list
Post by: jj2007 on August 23, 2012, 08:27:31 AM
Glad I could help - and hopefully you will remain an active member of the forum :icon14: