Download MetaTrader 5

GetParent and WindowHandle can't work well

To add comments, please log in or register
dgarden
10
dgarden  

My mother language is not English,I hope everyone can understand what I'm saying and give me some help.Thank you very much.

I have 12 charts.I want to use  "GetParent(WindowHandle(Symbol(), Period()))" to get the parent hwnd of specific chart and Show it .But sometimes it show,sometimes not.

#import "user32.dll"

int GetParent(int hWnd);

bool ShowWindow(int hWnd2, int nCmdShow);

#import 

……

 

int start(){

 if (Alert_Switch==true && Buffer1[0]>Buffer2[0]  &&  Buffer1[1]<Buffer2[1] && SX!=Time[0])

 { 

...

parent=GetParent(WindowHandle(Symbol(), Period()));

ShowWindow(parent, 3);  

Comment (parent,"",WindowHandle(Symbol(), Period()));

...

 } 


I print both parent and child handle ,and find when the chart shows,parent and child  all have it's value,such as 463256,1446408.

when the chart can't show,parent's value is zero,and child's value is normal,such as  0,1446408.

So sometimes specific chart don't have parent chart,so it can't show.But I use 

...

if (parent!=0)

{

  parent=GetParent(WindowHandle(Symbol(), Period()));

  ShowWindow(parent, 3);  }  

if (parent==0)

{

 ShowWindow(WindowHandle(Symbol(), Period()), 3); 

...

it can't still show the chart all the times.What's the problem is? Thanks a lot.

Carl Schreiber
6777
Carl Schreiber  
You need to track 'n check  the errors of mt4 and Windows!!
dgarden
10
dgarden  
Carl Schreiber:
You need to track 'n check  the errors of mt4 and Windows!!

 I don't know how to track.Please speak a little more,thank you.

And I want to know"https://www.mql5.com/en/forum/55447#comment_1577044

right or wrong? 

"Hi, i've observed that the function int WindowHandle( string symbol, int timeframe) is of no use in MQL4, may be that MQL5 will extend its use.
At the time, a call to int WindowHandle( string symbol, int timeframe) returns an int referencing the window by(system ?) integer. Anyway you don't need it, as any expert have a default value '0' to target the chart window he's running in.
Remember, main window (chart) as default value '0', even if you get an other reference to it, calling WindowHandle( Symbol(),0); the returned value is more than zero, and refers to a subwindow, attached to what, only MQL conceptor knows !
If you try to create an object in the EA chart window, using the return value of WindowHandle( Symbol(),0); you're wrong, it always raise en error. If you try the same using '0' as window integer reference instead of WindowHandle( Symbol(),0) value, you get what you want : your object is drawn on chart.
Thus, before any change in MQL implements, you can't target an other chart window than the one the EA is running in to draw an object."




Window Handles
Window Handles
  • www.mql5.com
MQL5.community traders' Forum
Carl Schreiber
6777
Carl Schreiber  

The mql-errors you find in the editors reference (F1).

The Windows-errors on Windows' site.

Goolge for "Windows user32.dll mql".

But be aware that the all the Windows function ending with an ..A(..) has to be replaced by the one with ..W(..) like (don't) PostMessageA(..) but (do) PostMessageW(..)!

To distinguish between mql-errors and Windows-errors use for

int
     LastError = ::GetLastError(), // mql error
     WinError  = kernel32::GetLastError(); // Windows error;
To add comments, please log in or register