Download MetaTrader 5

Getting value of Optimization Results ListView

To add comments, please log in or register
VabRus
105
VabRus 2014.01.18 18:37 

I have created two functions for get the value of set in optimization results listview in this case. You can adapt the code in your dll.

proc getOptimizationResult, theBest ; the best pass
 locals
     pid        dd ?
     buffer     rb 128
     fHandle    dd ?
 endl
   invoke GetTopWindow, 0
   .while eax <> 0
      mov [fHandle], eax
      invoke GetClassName, eax, addr buffer, 128
      invoke lstrcmp, addr buffer, 'MetaQuotes::MetaTrader::4.00'
      .if eax = 0
         jmp .break
      .endif
      invoke GetWindow, [fHandle], GW_HWNDNEXT
   .endw
   invoke MessageBox, 0, 'No se ha podido encontrar nada', '', 0
   .break:
   invoke FindWindowEx, [fHandle], 0, 'AfxControlBar110s', 'Terminal'
   .if eax = 0
      invoke MessageBox, 0, 'AfxControlBar110s', 'Terminal', 0
   .else
      invoke FindWindowEx, eax, 0, 0, 'Tester'
      .if eax = 0
         invoke MessageBox, 0, 'Tester', 'NO EXIST', 0
      .else
         invoke FindWindowEx, eax, 0, 'SysListView32', 0
         .if eax = 0
            invoke MessageBox, 0, 'SysListView32', 'NO EXIST', 0
         .else
            stdcall getBestResult, eax, [theBest]
         .endif
      .endif
   .endif
   ret
endp

proc getBestResult, handle, theBest
 locals
    lvi   LVITEM ?
    bPass rb 10
 endl
   invoke Sleep, 2000
   cinvoke wsprintf, addr bPass, '%i', [theBest]
   mov [lvi.mask], LVIF_TEXT
   mov [lvi.cchTextMax], MAX_PATH
   mov [lvi.iSubItem], 0 ; first column you change this for get other values
   invoke LocalAlloc, LPTR, MAX_PATH
   mov [lvi.pszText], eax
   invoke SendMessage, [handle], LVM_GETITEMCOUNT, 0, 0; count of items in listview
   .if eax > 0
       mov edi, eax
       .while edi > 0
          dec edi
          invoke SendMessage, [handle], LVM_GETITEMTEXT, edi, addr lvi ; get the number of pass
          invoke lstrcmp, addr bPass, [lvi.pszText]
          .if eax = 0
             jmp .break
          .endif
       .endw
       invoke MessageBox, 0, 'Don´t found item', 'Error', 0
       jmp .exit
       .break:
       mov [lvi.iSubItem], 7 ; last column (set)
       invoke SendMessage, [handle], LVM_GETITEMTEXT, edi, addr lvi ; get the best set
       invoke MessageBox, 0, [lvi.pszText], 'Best set', 0;
  ;     invoke SendMessage, [handle], 1043h, 0, edi ; select item (not work is testing)
       invoke lstrlen, [writeBuffer]
       push eax
       invoke lstrlen, [lvi.pszText]
       pop ecx
       add eax, ecx
       inc eax
       inc eax
       push eax
       invoke LocalUnlock, [buffer]
       pop eax
       invoke LocalReAlloc, [buffer], eax,\
                            LMEM_MOVEABLE+LMEM_ZEROINIT
       invoke LocalLock, [buffer]
       mov [writeBuffer], eax
       invoke lstrcat, [writeBuffer], [lvi.pszText]
       invoke lstrcat, [writeBuffer], '"'
    .endif
    .exit:
    invoke LocalFree, [lvi.pszText]
   ret
endp
To add comments, please log in or register