Reading from the Log File in Real Time - page 2

 
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 ?
 
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.

 

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);
   }
 

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.

 
Wow, it is so difficult to understand for me. I hope some experts will look into and give advises.
 
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:

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.

   Can you show us the rest of the code so that we can try it?

   I am also experiencing problems with -  PostMessageW(hwnd,WM_COMMAND,35435,0) - as suggested above.

   Not opening the Expert Log Folder (and not flushing the Expert Log).

   Thank you.

Reason: