DLL - retrieve HWND from EA

 

This is more of a DLL specific question for all of you programming experts out there. In my DLL, I have a few dialogs and want to make the platform the parent window. Obviously, I can use the user32.dll function to get the int value for the hwnd of the platform, but in my DLL, how can I turn the int hwnd into an actual HWND. I have tried some AFX functions such as AfxGetApp(), GetForegroundWindow(), etc. to no no avail. Any suggestions? I have looked at using FindWindow() in my DLL, but what can I use as the class name or window name (or how can I retrieve the window name in mql4 and pass that to my DLL)?

Thanks, Scott

 
TXAggie00:

This is more of a DLL specific question for all of you programming experts out there. In my DLL, I have a few dialogs and want to make the platform the parent window. Obviously, I can use the user32.dll function to get the int value for the hwnd of the platform, but in my DLL, how can I turn the int hwnd into an actual HWND. I have tried some AFX functions such as AfxGetApp(), GetForegroundWindow(), etc. to no no avail. Any suggestions? I have looked at using FindWindow() in my DLL, but what can I use as the class name or window name (or how can I retrieve the window name in mql4 and pass that to my DLL)?

Firstly, because it's not 100% clear whether you already know this, the MT4 WindowHandle() function gives you the HWND of the current chart. You can obviously pass this into the DLL, and you can get the handle of the main MT4 window from the chart window using GetParent() or GetAncestor().

The other thing which isn't clear is why, having got a window handle in int form, you're not just simply casting it to a HWND. For example, there's no problem doing the following in MT4...

#import "whatever.dll"
   void PassTheWindowHandle (int ResultFromWindowHandleFunction);
#import

... and declaring the function in C as:

void PassTheWindowHandle (HWND ResultFromWindowHandleFunction)
 
jjc:

Firstly, because it's not 100% clear whether you already know this, the MT4 WindowHandle() function gives you the HWND of the current chart. You can obviously pass this into the DLL, and you can get the handle of the main MT4 window from the chart window using GetParent() or GetAncestor().

The other thing which isn't clear is why, having got a window handle in int form, you're not just simply casting it to a HWND. For example, there's no problem doing the following in MT4...

... and declaring the function in C as:


Thanks for the reply jjc! I was aware of the WindowHandle() function but wasn't sure if an int could be cast to HWND. I know that an INTPTR could be cast to HWND, but not an int. I will try that out.

Thanks, Scott

Reason: