Author Topic: select file of the list  (Read 5493 times)

03.jose

  • Guest
Re: select file of the list
« Reply #15 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

jj2007

  • Member
  • *****
  • Posts: 7554
  • Assembler is fun ;-)
    • MasmBasic
Re: select file of the list
« Reply #16 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:

03.jose

  • Guest
Re: select file of the list
« Reply #17 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

dedndave

  • Member
  • *****
  • Posts: 8734
  • Still using Abacus 2.0
    • DednDave
Re: select file of the list
« Reply #18 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

jj2007

  • Member
  • *****
  • Posts: 7554
  • Assembler is fun ;-)
    • MasmBasic
Re: select file of the list
« Reply #19 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

03.jose

  • Guest
Re: select file of the list
« Reply #20 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:

jj2007

  • Member
  • *****
  • Posts: 7554
  • Assembler is fun ;-)
    • MasmBasic
Re: select file of the list
« Reply #21 on: August 23, 2012, 08:27:31 AM »
Glad I could help - and hopefully you will remain an active member of the forum :icon14: