Messagebox Bug...

 
I have 'searched' the forum but cannot find this mentioned - if it has been addressed, apologies.

Attach an EA that uses 'Messagebox' in the Init function to a chart and it works fine - but only once! Even removing and re-attaching the EA to the chart fails to get the Messagebox to open a menu box. The only thing that 'works' is to close the chart, re-open and re-attach the EA.

A bug?
 
Does it work if the box is in the start() function?

bool firstRun;

init(){
     firstRun = true;
}

start(){
     if(firstRun == true) {
          MessageBox();
          firstRun = false;
     }

     ..... Do Stuff...
  
 
omelette,
I couldn't reproduce the problem.
I added a line as shown below.

int init()
  {
//----
MessageBox("Hello, World");
   
//----
   return(0);
  }



and it worked fine every time I attached, changed timeframe, or recompiled.

 
I am sorry if the answer to this question would appear rather obvious, but do you click off the MessageBox at all?
Could you share the surrounding code of the portion of your code that calls the MessageBox, so that we can have a better look at what type of functions you are calling.
What OS are you running?
What happens if you replace the MessageBox with an Alert function?
What happens if you add an Alert function before/after the MessageBox?

I have 'searched' the forum but cannot find this mentioned - if it has been addressed, apologies.

Attach an EA that uses 'Messagebox' in the Init function to a chart and it works fine - but only once! Even removing and re-attaching the EA to the chart fails to get the Messagebox to open a menu box. The only thing that 'works' is to close the chart, re-open and re-attach the EA.

A bug?
 
I am sorry if the answer to this question would appear rather obvious, but do you click off the MessageBox at all?
Could you share the surrounding code of the portion of your code that calls the MessageBox, so that we can have a better look at what type of functions you are calling.
What OS are you running?
What happens if you replace the MessageBox with an Alert function?
What happens if you add an Alert function before/after the MessageBox?


Yes, that would have been a stinker - thankfully not the case!

This sample EA is the original code copied+pasted to illustrates the problem. I should also say that this is MT v208. I stand by to ritually disembowel myself if the problem is with my code :D:D:D

//+------------------------------------------------------------------+
//|                                            Possible_Messagebox_Bug.mq4 |
//|                      Copyright © 2007, MetaQuotes Software Corp. |
//|                                        http://www.metaquotes.net |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2007, MetaQuotes Software Corp."
#property link      "http://www.metaquotes.net"
#include <WinUser32.mqh>

extern bool AutoPlaceOrders_On = false;

//+------------------------------------------------------------------+
//| expert initialization function                                   |
//+------------------------------------------------------------------+
int init()
  {
//----
   if (!AutoPlaceOrders_On)
     int temp = MessageBox("A Message...","*** A Heading ***",MB_YESNO|MB_ICONQUESTION);
    else temp = 0;
    
    if (AutoPlaceOrders_On || temp == IDYES)
     Print("Placing Orders...");
    else Print("Not Allowed...");
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| expert deinitialization function                                 |
//+------------------------------------------------------------------+
int deinit()
  {
//----
   
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| expert start function                                            |
//+------------------------------------------------------------------+
int start()
  {
//----
   Print("Main Sub...");
//----
   return(0);
  }
//+------------------------------------------------------------------+
 
What the build and date?
Try to use latest build from our site.
 
What the build and date?
Try to use latest build from our site.


The version is v208 21 August 2007.

Sorry I cannot use the latest version - it keeps freezing on my Pro Duo system. In addition of course to it taking twice as long backtesting stuff due to Metaquotes 'Recalculate' travesty!
 
Hi, Omelette,

For whatever reason, the MQL4 library's function MessageBox fails (returns 0) the second time you try to run it, as in your case, under MT4 Build 208. That is - it runs fine once, but then it returns 0 (meaning, it failed). I don't have time to fully debug it, but at first glance it does look like the function is actually called (and, alas, returns 0), even though it does not display the box.

I imported the MessageBoxA function from user32.dll, and tried it again - it worked fine under Build 208.

Here's the modified code of your original EA:


//+------------------------------------------------------------------+
//|                                            Possible_Messagebox_Bug.mq4 |
//|                      Copyright © 2007, MetaQuotes Software Corp. |
//|                                        http://www.metaquotes.net |
//+------------------------------------------------------------------+

#property copyright "Copyright © 2007, MetaQuotes Software Corp."
#property link      "http://www.metaquotes.net"
#include <WinUser32.mqh>

#import "user32.dll"
  int     MessageBoxA(int hWnd ,string szText,string szCaption,int nType);

extern bool AutoPlaceOrders_On = false;

//+------------------------------------------------------------------+
//| expert initialization function                                   |
//+------------------------------------------------------------------+
int init()
  {
//----
   if (!AutoPlaceOrders_On)
   {
     //int temp = MessageBox("A Message...","*** A Heading ***",MB_YESNO|MB_ICONQUESTION);
     
     int temp = MessageBoxA(0, "A Message...","*** A Heading ***",MB_YESNO|MB_ICONQUESTION);
     
     Alert(temp);
   }
    else temp = 0;
    
    if (AutoPlaceOrders_On || temp == IDYES)
     Print("Placing Orders...");
    else Print("Not Allowed...");
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| expert deinitialization function                                 |
//+------------------------------------------------------------------+
int deinit()
  {
//----
   
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| expert start function                                            |
//+------------------------------------------------------------------+
int start()
  {
//----
   Print("Main Sub...");
//----
   return(0);
  }
//+------------------------------------------------------------------+



Try it, and let me know how it goes...

 
Hi, Omelette,

For whatever reason, the MQL4 library's function MessageBox fails (returns 0) the second time you try to run it, as in your case, under MT4 Build 208. That is - it runs fine once, but then it returns 0 (meaning, it failed). I don't have time to fully debug it, but at first glance it does look like the function is actually called (and, alas, returns 0), even though it does not display the box.

I imported the MessageBoxA function from user32.dll, and tried it again - it worked fine under Build 208.




Green, thanks, nice to know that I was not at fault for once :)

Never knew 'MessageBoxA' existed either, another gem!

Maybe you might also know if it's possible to alter the displayed text in the MessageBox buttons or get the 'fourth' button (HELP) to return a value, as it is pretty useless otherwise - I don't think either of these are but confirmation would be nice! I tried altering the text in the 'WinUser32.mqh' file but this does not have any effect.
 
A lot of DLL functions exist, that can be quite useful in an EA :-)
Yes, you can customize the MessageBoxA function.
I don't know what your coding level is, but here's an example:

http://www.codeguru.com/cpp/w-p/win32/messagebox/article.php/c10873/


Hi, Omelette,

For whatever reason, the MQL4 library's function MessageBox fails (returns 0) the second time you try to run it, as in your case, under MT4 Build 208. That is - it runs fine once, but then it returns 0 (meaning, it failed). I don't have time to fully debug it, but at first glance it does look like the function is actually called (and, alas, returns 0), even though it does not display the box.

I imported the MessageBoxA function from user32.dll, and tried it again - it worked fine under Build 208.




Green, thanks, nice to know that I was not at fault for once :)

Never knew 'MessageBoxA' existed either, another gem!

Maybe you might also know if it's possible to alter the displayed text in the MessageBox buttons or get the 'fourth' button (HELP) to return a value, as it is pretty useless otherwise - I don't think either of these are but confirmation would be nice! I tried altering the text in the 'WinUser32.mqh' file but this does not have any effect.
 
A lot of DLL functions exist, that can be quite useful in an EA :-)
Yes, you can customize the MessageBoxA function.
I don't know what your coding level is, but here's an example:

http://www.codeguru.com/cpp/w-p/win32/messagebox/article.php/c10873/



A pretty low-level but I muddle through :D

Thanks again, much appreciated.
Reason: