#define's for known commands that can be used for PostMessageA()

 

I thought this might be helpful. I found the original somewhere on the net and expanded on it.

It should be noted that many of these commands should not be used because the MQL4 language provides better, cleaner, alternatives. Occasionally though, you find you need to accomplish a particular task and there is just no other way.

A good example would be that you need to write an EA, because you want it to stay on the chart when timeframe or symbol are changed, but you also want it to remove itself from the chart (like a script does) once a certain task is done. In this case, the EA could send a message to its chart window to have itself removed.

There are two attachments
- aswincmd.mqh contains the numeric codes and mostly defines for those commands I could find out about so far.
- cmd.mq4 is a script that will, potentially, let you find more commands by simply trying out all possible commands in a loop.

Files:
aswincmd.mqh  10 kb
cmd.mq4  1 kb
 
This is indeed the first time I have seen all this in one file. Thanks.
 
  1. https://www.mql5.com/en/forum/128554
    #include <WinUser32.mqh>
    #import "user32.dll"
      int GetForegroundWindow();
    #import
    void PauseTest(){
            if (IsTesting() && IsVisualMode()){
                    int hmain = GetForegroundWindow();
                    PostMessageA(hmain, WM_COMMAND, 0x57a, 0);      }       // 1402
    }
    

  2. #define MT4_WMCMD_UPDATE_DATA 33324 /* This doesn't cause experts start() to run */
This comment conflicts with the Period Converter/range bars
   if(hwnd == 0) {
      //trying to detect the chart window for updating
      hwnd = WindowHandle(Symbol(), NewPeriod);
   }
   if(hwnd!= 0) {
      if (IsDllsAllowed() == false) {
         //DLL calls must be allowed
         DebugMsg("Dll calls must be allowed");
         return (-1);
      }
      if (PostMessageA(hwnd,WM_COMMAND,0x33324,0) == 0) {
         //PostMessage failed, chart window closed
         hwnd = 0;
      } else {
         //PostMessage succeed
         return (0);
      }
   }
 
In the above don't want forgroundWindow. Also it takes sometime before the GUI reacts. Update:
#include <WinUser32.mqh>
#import "user32.dll"
  int GetAncestor(int, int);
#import
void PauseTest(){   datetime now = TimeCurrent();   static datetime oncePerTick;
    if (IsTesting() && IsVisualMode() && IsDllsAllowed() && oncePerTick != now){
        oncePerTick = now;
        for(int i=0; i<200000; i++){        // Delay required for speed=32 (max)
            int main = GetAncestor(WindowHandle(Symbol(), Period()), 2/*GA_ROOT*/);
            if (i==0) PostMessageA(main, WM_COMMAND, 0x57a, 0); // 1402. Pause
    }   }
}
 
In aswincmd.mqh above lists 33020 as unknown. According to this it's Ctrl+E (toggle Experts)
 
#define MT4_WMCMD_PERIOD_H1 33135
https://www.mql5.com/en/forum/128744
 

push it up :)

Thanks to WHRoeder && dabbler.

Any other WM Commands beside PostMessage guys ?

How about mouse clicks ?

 

#define MT4_WMCMD_PROFILE_LOAD 34100 /* 34100-34199 load nth profile */

 

WHRoeder post these somewhere I forget the links :(

33 058 - All History

33 057 - Last 3 Months

33 063 - Last Month

Have fun :)

 
For weekend developing!
Good idea! Here is my variation (script):
Files:
Reason: