Search code examples
c

How to remove WS_EX_TOPMOST style from window?


I try to create Window for video by using following syntax:

hwnd=CreateWindow("Video Window", "Video window", 
                    WS_OVERLAPPEDWINDOW | WS_VISIBLE,
        CW_USEDEFAULT, CW_USEDEFAULT, rect.right-rect.left,rect.bottom-rect.top,        NULL, NULL, hInstance, NULL);

All works as expected but the issue is that the window always on top. It means that I see this window even if I switch to other application.

From Window directive program I found additional style: WS_EX_TOPMOST

enter image description here

How can I remove It programmatically or do I need override it somehow?

I tried SetWindowPos:

SetWindowPos(hwnd, HWND_NOTOPMOST, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE);

or to use instead CreateWindow at CreateWindowEx:

hwnd=CreateWindowEx(WS_EX_LEFT | WS_EX_LTRREADING | WS_EX_RIGHTSCROLLBAR | WS_EX_WINDOWEDGE,
                    "Video Window","Video Window",
                    WS_OVERLAPPEDWINDOW  | WS_VISIBLE ,
                    CW_USEDEFAULT,
                    CW_USEDEFAULT,
                    rect.right-rect.left,
                    rect.bottom-rect.top,
                    NULL,
                    NULL,
                    hInstance,
                    NULL);

but still get flag WS_EX_TOPMOST

Thanks,


Solution

  • One way of going about it is to query the window for it's current extended-style, before clearing the bits that correspond to WS_EX_TOPMOST and setting the new extended style.

    Something like this:

    long dwExStyle = GetWindowLong(hwnd, GWL_EXSTYLE);
    dwExStyle &= ~WS_EX_TOPMOST;
    SetWindowLong(hwnd, GWL_EXSTYLE, dwExStyle);