Welcome Forex EA downloads & MT4/MT5 auto-trading resources — EAs, Gold EAs, quant tools and real-world automation.
Sign In Sign Up

Use MetaTrader 4 scripts to get pop-up alerts for MT4 messages | Trading script downloads - MetaTrader 4 resources

author EAcpu | 3 reads | 0 comments |

This is a small script using an external DLL "user32.dll".

1. Import Dll and its functions

 #define WM_GETTEXTLENGTH 0xE
#define WM_GETTEXT 0xD

#Import "user32.dll" integer search window W ( string lp class name, string lp window name);
Integer search window ExW( integer hWnd1, integer hWnd2, string lpsz1, string lpsz2);
Integer send message A ( integer um, integer w message, integer w parameter, integer l parameter);
Integer send message A ( integer um, integer w message, integer w parameter, character & l parameter []); //Edit lParam receive value return
#import //+------

2 Get the handle of the alert dialog box (parent window)

Use FindWindowW to get to a specific parent window handle

 Integer CHwnd = 0 ; //Parent window handle Integer CHwnd = 0 ; //Text box handle  
   Hwnd = Find Window W( "#32770" , "Alert" ); //Replace mql4's FindWindowA with FindWindowW

3. Get the handle of the text box (or label) in the Dialog (child window)

Use FindWindowExW to specify the child window handle

 //Get the handle of the text box in the dialog box CHwnd = FindWindowExW(Hwnd, 0 , "Edit" , invalid ); //Find all controls with the class name "Edit"

3. Get the message content from the text box

3.1 You need to specify the length of the string:

 //Get the content of the Message in the text box //Get the length of the message string integer text length = SendMessageA(CHwnd, WM_GETTEXTLENGTH, 0 , 0 );

3.2 Get content

 string content message = "" ;
character ch[ 540 ];
for ( integer i = 0 ; i < array size (ch); i++) ch[i] = 0x000 ;
  
ArrayInit (channel, 0x000 );
  
Integer length = SendMessageA(CHwnd, WM_GETTEXT, textLength + 1 , ch);
  
for ( integer i = 0 ; i < length; i++) content message += character to string (ch[i]);
  
print ( __function__ , "--> content message = " + content message);

Get more information on tutorial videos:


Attachment download

📎 catchmeifyoucan.mq4 (2.34 KB)

📎 script_alert_messenger.mq4 (1.29 KB)

Source: MQL5 #41986

Verification code Refresh