Is it possible to create a windowless mfc c++ app that would consist of transparent browser component?

686 Views Asked by At

Is it possible to create a windowless mfc c++ app (that would run on xp) that would consist of transparent browser component (with background by default transparent) and a button (that wold for example close that app)?

4

There are 4 best solutions below

0
On

Have you tried capturing the background of your window, and adding it as a background of the browser component? Of course it will only work if you want to display an HTML document created by yourself(/your team), but if it is not the case, the whole question would be pointless.

I never tried to do so whit an embedded browser, but I did it in to some other controls (like memo boxes), and it worked. If you choose this solution, you should still be aware of that you have to recapture the background of your window whenever it is moved or resized.

You can use a solution of your choice to display the background in the embedded browser, but imho the best option is to use a CSS-defined background, which will be replaced with yours. (Don't forget to forge a simple javascript to refresh the background on form resize/move to avoid unintentional reloads of the whole document.)

More information of partial screen capture can be found here.

0
On

I don't think you can do that with standard WebBrowser (embedded IE engine), because it does not know anything about your transparency wishes and will always draw a background.

It is possible with alternative html engine, e.g. HTMLayout. Though it is not very good as internet browser (no javascript etc), but for web-style UI it is much better than WebBrowser (faster, uses less memory, supports gradients, animations, advanced layout). If all you need is “web UI” with images, controls, links, animations and buttons, and you're using MFC, WTL or pure WinAPI, this is a good option.

1
On

No. There's no problem in hosting a WebBrowser component in an MFC app, and painting just a single close button in the Non-Client area, but the WebBrowser component itself will render a background.

0
On

You can try the following code, but there still will be artefacts when selecting or resizing:

    private void WebCtrl_Loaded(object sender, RoutedEventArgs e)
    {
        var hRef = new HandleRef(null, WebCtrl.Handle);

        int style = GetWindowLong(hRef, GWL_EXSTYLE);
        if ((style & WS_EX_TRANSPARENT) == 0)
            SetWindowLong(hRef, GWL_EXSTYLE, style | WS_EX_TRANSPARENT);

        style = GetWindowLong(hRef, GWL_STYLE);
        if ((style & WS_CLIPCHILDREN) == 0)
            SetWindowLong(hRef, GWL_STYLE, style | WS_CLIPCHILDREN);
    }

    IntPtr WebCtrl_MessageHook(IntPtr hwnd, int msg, IntPtr wParam, IntPtr lParam, ref bool handled)
    {
        if (msg == WM_ERASEBKGND)
            handled = true;
        return IntPtr.Zero;
    }