I want to use a winform inside MT4, which I know is possible. Metatrader4 has its own c++ flavored language, which can import .DLL-s, but we can only use stdcall
CallingConvention.
I am using C# in Visual Studio 2015 to create the .DLL
My approach here is this:
From Metatrader 4 Terminal, I call a function in the .DLL to start the winform, I also pass the window handle as use it as an ID to track what chart just called the .DLL
I am storing the panel objects using a key, value dictionary.
Below is the process which loads the form.
// key,value dictionary holding forms
private static Dictionary<int, TradePanelForm> panels = new Dictionary<int, TradePanelForm>();
// start panel assosicated by window handle
[DllExport("OpenPanel", CallingConvention.StdCall)]
public static void OpenPanel(int inMT4hwnd)
{
if (!panels.ContainsKey(inMT4hwnd))
{
// add the panel object to the dictionary list
panels.Add(inMT4hwnd, new TradePanelForm(inMT4hwnd));
}
Application.Run(panels[inMT4hwnd]);
// panels[inMT4hwnd].Show();
}
If I use
Application.Run(panels[inMT4hwnd]);
the form will open, but it seems to be 'in focus' and Metatrader 4 Terminal seems to become unresponsive until I close the panel.
If I load the panel this way
panels[inMT4hwnd].Show();
the panel partially loads, with the buttons whited out, and the both the panel, and Metatrader 4 Terminal hangs.
Q1: What is the correct way to be doing this?
Q2: Is there some special winAPI stuff I need to dance around to make the form work properly within the metatrader process?
I've looked up threads, tasks, async stuff. Could somebody usher me towards the right direction here.
It would be nice if I could get the form to load 'inside' Metatrader's window as like a child window.