Reading from the Log File in Real Time - page 2

To add comments, please log in or register
Alain Verleyen
38519
Alain Verleyen  
Hao Tan:

I have met the same problem too. So i come to give my thanks to all the authors above!

Besides, i have made a little adjustment to the EA log refreshing codes. complete version is below:

this method may not be the best, though, it is practicable.

Can you enlighten me and provide your used case needing to read the log file ?
Cromo
248
Cromo  
Marco vd Heijden:

Of course.

But why.

Yes, I want to place order reading log file.

Like,, if MT4 journal shows indicator buy signal, I want to order because some indicator has no buffers.

Easy Trade
16
Easy Trade  

Getting the directory handle does not work smoothly

Because the window title is not logs

Findwindow requires the window title to correspond exactly

So I modified this part as follows

Close by looking up the class name of the window, although this will also close other directory windows

In addition, I made changes to while to avoid an infinite loop.

After not finding it for a  period of time, continue to open the directory next time.


#include <WinUser32.mqh>

#import "user32.dll"
  int GetAncestor(int hWnd, int gaFlags);
#import


void updatelog()
{
  int hwnd = GetAncestor(WindowHandle(Symbol(),Period()),2); // find the Terminal handle no.
  PostMessageW(hwnd,WM_COMMAND ,33101,0); // open the folder contains the log files 

  //-----
  bool find=false;
  for(int i=0;i<20;i++)
    {
     Sleep(100);
     int LogHandle= FindIfDirOpened();
     if(LogHandle!=0)
       {
           find=true;
           PostMessageW(FindIfDirOpened(), WM_CLOSE, 0, 0); //close the folder
       }
       else if(find)
              {
               break;
              }
    }


}

int FindIfDirOpened()
   {
   // string log = "logs";
   string classname="CabinetWClass";
   int handle = FindWindowW(classname ,NULL);

   return(handle);
   }
Easy Trade
16
Easy Trade  

The latest progress, I found a better way with spy++

Use the right-click menu to view instead of open, which will open the log detail window inside MT4

This operation will also update the  log file.

The advantage of this is  the  view window is a sub-window belonging to MT4 and can be executed in the background.

The only thing I need to solve is to find the child window command using FindWindowEx instead of FindWindowW.


However, in actual use, I encountered another problem. My imported FindWindowEx reported an error at runtime:

 Unresolved import function call

 Cannot find 'FindWindowEX' in 'user32.dll'

Here is my code:

 #import  "user32.dll" 
   int GetAncestor( int hWnd, int gaFlags);
   int FindWindowEx( int hwndParent, int hwndChild, string lpszClass, string lpszTitle);
 #import



    string log = "\\Logs" ;
   string i;
   //string classname="CabinetWClass";   // use for open log folder 
   int handle = FindWindowEx(hwndParent, 0 , i , log );

Can someone explain why?

After solving it, I can send the complete code.

Because it is not working properly now, so I didn’t send it all.

But the method is ok, I have implemented it in C#, the effect is very good.

Cromo
248
Cromo  
Wow, it is so difficult to understand for me. I hope some experts will look into and give advises.
12
To add comments, please log in or register