Repainting of browser controls

Source: Internet
Author: User

 

 

In some cases, browser controls embedded in Windows cannot be re-painted in time. For example, we create a "message Prompt window" and use browser controls to display the message content. When we use the animatewindow for animation display, the browser control will display a blank area. Next we will discuss the redrawing of browser controls.

  1. Reproduce the scenario.

    // Generate a window (omitted)
    Hwnd = Window handle.

    // Embedded browser controls.
    : Atlaxcreatecontrolex (L "about: blank", hwnd, null, null, (iunknown **) & punkcontrol );

    ...

    // Window animation.
    // For program compatibility, the traditional showwindow must be called when the animatewindow fails.
    If (! : Animatewindow (hwnd, 200, aw_slide | aw_ver_negative ))
    ...{
    : Showwindow (hwnd, sw_show );
    }

  2. Redraw target.

    The window level of a browser control is as follows: -- shell embedding
    ---- Shell docobject View
    ------ Internet assumer_server

    We need to re-paint the window handle with the class name "Internet assumer_server. To support the latest Vista system, the window handle cannot be obtained simply through iwebbrowser2-> get_hwnd. Next, we get "shell embedding" Through punkcontrol returned by atlaxcreatecontrolex, and then get "Internet assumer_server ".

    Obtain "shell embedding": hwnd;
    If (punkcontrol! = NULL)
    ...{
    Ccomptr <iwebbrowser2> pwebbrowser2;
    Punkcontrol-> QueryInterface (iid_iwebbrowser2, (void **) & pwebbrowser2 );
    If (pwebbrowser2! = NULL)
    ...{
    /** // The Code fails in Vista.
    // HR = pwebbrowser2-> get_hwnd (shandle_ptr *) & hwnd );

    /** // You can directly obtain the hwnd for this code, but it does not have any formal instructions.
    // Ccomptr <iolewindow> POW;
    // Pwebbrowser2-> QueryInterface (iid_iolewindow, (void **) & POW );
    // If (pow! = NULL)
    //{
    // Pow-> getwindow (& hwnd );
    //}

    // Use the pass method.
    Ccomptr <iserviceprovider> PSP;
    Pwebbrowser2-> QueryInterface (iid_iserviceprovider, (void **) & PSP );
    If (PSP! = NULL)
    ...{
    Ccomptr <iolewindow> POW;
    PSP-> queryservice (sid_sshellbrowser, iid_iolewindow, (void **) & POW );
    If (pow! = NULL)
    ...{
    // This is "shell embedding ".
    Pow-> getwindow (& hwnd );
    }
    }
    }
    }

    Obtain "Internet assumer_server ":

    Hwnd _ getwebbrowserhwnd (hwnd hwndshell)
    ...{
    //
    If (hwndshell = NULL)
    Return NULL;

    // Loop
    Tchar szclassname [max_path];
    Hwnd = hwndshell;
    While (true)
    ...{
    //
    : Getclassname (hwnd, szclassname, max_path );
    If (: _ wcsicmp (L "Internet assumer_server", szclassname) = 0)
    ...{
    Return hwnd;
    }

    //
    Hwnd =: getwindow (hwnd, gw_child );
    If (hwnd = NULL)
    Break;
    }

    Return NULL;
    }

  3. The time of re-painting.
    Window animation will be executed for a specified period of time. You need to see the final page content, so you do not need to start re-painting during the animation process, but after the animation is complete. So how can we know that the animation window is over? Fortunately, animatewindow uses synchronous return (which is different from the popular asynchronous call idea in Ajax .). That is, after the animation is executed, the animation window is returned. Therefore, the re-painting time is after the animatewindow. // Redraw the web page.
    Hwnd =__ getwebbrowserhwnd (hwndshell );

    //
    If (hwnd! = NULL)
    ...{
    : Invalidaterect (hwnd, null, true );
    : Updatewindow (hwnd );
    }

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.