0

I would like to add a child window to Metatrader4's chart window which always stays on top, without blinking, just statically there all the time upon eveything (in parent window). I am doing this from a DLL (C++).

I call this method from the mql side:

MT4_EXPFUNC int __stdcall testWindow(HWND hwnd) {
    prnt_hWnd = hwnd;
    CreateThread(0, NULL, ThreadProc, (LPVOID)L"Window Title", NULL, NULL);
    return 0;
}

The parent window's (chart) handle is given as a parameter.

DWORD WINAPI ThreadProc( LPVOID lpParam )
{
    MSG messages;
    /*
    ... in createWindowClass:


        WNDCLASSEX wc;
        wc.hInstance =  GetModuleHandle(NULL);
        wc.lpszClassName = (LPCWSTR)L"MyClass";
        wc.lpszClassName = (LPCWSTR)szClassName;
        wc.lpfnWndProc = DLLWindowProc;
        wc.style = CS_HREDRAW | CS_VREDRAW | CS_DBLCLKS;
        ...
    */
    CreateWindowClass(L"MyClass");
    HWND hwnd = CreateWindowEx (0, L"MyClass", NULL, WS_VISIBLE | WS_CHILD , CW_USEDEFAULT, CW_USEDEFAULT, 400, 300, prnt_hWnd, NULL, GetModuleHandle(NULL), NULL );
    ShowWindow (hwnd, SW_SHOWNORMAL);
    while (GetMessage (&messages, NULL, 0, 0))
    {
        TranslateMessage(&messages);
        DispatchMessage(&messages);
    }
    return 1;
}

I handle window's messages this way:

LRESULT CALLBACK DLLWindowProc (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
    switch (message) {
        case WM_PAINT: {
             PAINTSTRUCT ps;
             BeginPaint( hwnd, &ps );
             EndPaint( hwnd, &ps );
             return 0;
           }
        case WM_COMMAND:
              /* */                   
               break;
        case WM_DESTROY:
            PostQuitMessage (0);
            break;
        default:
            return DefWindowProc (hwnd, message, wParam, lParam);
    }
    return 0;
}

My child window at the begining appears, then after (I guess) the parent window is getting being redrawn, suddenly it disappears, then it is just blinking (fastly appears-disappear).

My goal is to have a child window on that chart statically, so always topmost, without blinking. I could achieve this only without the WS_CHILD property. But then my child window is not ON the parent.

rdanee
  • 109
  • 1
  • 1
  • 9

1 Answers1

0

Try adding the WS_CLIPCHILDREN style to the chart window. I would pass the handle on the MQL4 side in init() via some MT4 export function. For example, SetChartWnd( HWND hChartWnd ) and passing WindowHandle( Symbol(), Period() ) as the parameter. Then inside that function, I would try doing something like the following:

if ( ::IsWindow( hChartWnd ) ) {
    DWORD style = GetWindowLong( hChartWnd, GWL_STYLE );
    style |= WS_CLIPCHILDREN;
    SetWindowLong( hChartWnd, GWL_STYLE, style );
  }
}
Paul
  • 265
  • 1
  • 2
  • 10