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.
- 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 );
}
- 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;
}
- 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 );
}