WTL-A wtl window hosting ActiveX Control (IE)

Source: Internet
Author: User
Demonstrate how to accommodate ActiveX controls in the wtl window (Windows built-in IE (webbrowser) Controls ):
 
# Pragma once
 
# Include"Stdafx. h"
 
# Include <exdisp. h>
 
# Include <exdispid. h>
 
 
// ID of webbrowser Control
 
ConstUint id_webbrowser = 1;
 
 
 
TypedefCwintraits <ws_overlappedwindow | ws_clipchildren> cmainwintraits;
ClassCmainwindow:
 
PublicCsf-wimpl <cmainwindow, cwindow, cmainwintraits>,
 
PublicIdispeventimpl <id_webbrowser, cmainwindow>
 
{
Public:
 
Declare_wnd_class (_ T ("Wtl ActiveX host window"))
 
 
 
// Windows message handler
Begin_msg_map (cmainwindow)
 
Msg_wm_create (oncreate)
 
Msg_wm_destroy (ondestroy)
 
Msg_wm_size (onsize)
 
End_msg_map ()
 
 
// Webbrowser control event message handler
 
Begin_sink_map (cmainwindow)
 
Sink_entry (id_webbrowser, dispid_downloadbegin, ondownloadbegin)
Sink_entry (id_webbrowser, dispid_downloadcomplete, ondownloadcomplete)
 
End_sink_map ()
 
 
 
IntOncreate (maid)
 
{
Crect RC;
 
Getclientrect (& rc );
 
 
 
/*
 
// Create the webbrowser control (IE) with progid
Hwnd hwndie = m_ax.create (
 
M_hwnd,
 
RC,
 
_ T ("shell. assumer.2"), // progid of webbrowser Control
 
Ws_child | ws_visible,
0,
 
Id_webbrowser );
 
Atlassert (hwndie );
 
*/
 
 
// Create the webbrowser control (IE) with CLSID
 
Ccomptr <iunknown> spunkwebbrowser;
 
Hresult hR = spunkwebbrowser. cocreateinstance (clsid_webbrowser );
 
Checkhr (HR );
 
 
// Create the ActiveX host window
 
Hwnd hwndwb = m_ax.create (
 
M_hwnd,
 
RC,
Null,
 
Ws_child | ws_visible,
 
0,
 
Id_webbrowser );
 
Atlassert (hwndwb );
 
 
// Attach the webbrowser control to host window
 
Ccomptr <iunknown> spunkcontainer;
 
M_ax.attachcontrol (spunkwebbrowser, & spunkcontainer );
 
 
// Advise sink Map
 
Atladvisesinkmap (This,True);
 
 
 
// Query interface
HR = m_ax.querycontrol (& m_spiwebbrowser );
 
Checkhr (HR );
 
Ccombstr site (_ T ("Http://www.hust.edu.cn"));
 
Ccomvariant V;
HR = m_spiwebbrowser-> navigate (site, & V, & V );
 
Checkhr (HR );
 
 
 
Return0;
 
}
 
 
VoidOndestroy ()
 
{
 
// Unadvise sink Map
Atladvisesinkmap (This,False);
 
Postquitmessage (0 );
 
}
 
 
 
VoidOnsize (uint ntype, csize size)
{
 
Crect RC;
 
Getclientrect (& rc );
 
M_ax.setwindowpos (m_hwnd, & rc, swp_nozorder | swp_noactivate );
 
}
 
 
Void_ Stdcall ondownloadbegin ()
 
{
 
Setwindowtext (_ T ("Download begin:"));
 
}
 
 
Void_ Stdcall ondownloadcomplete ()
 
{
 
Setwindowtext (_ T ("Download completed."));
 
}
 
 
Private:
 
Caxwindow m_ax;
 
Ccomptr <iwebbrowser2> m_spiwebbrowser;
 
};
Effect:

Related Article

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.