Click here to Skip to main content
13,348,874 members (76,641 online)
Click here to Skip to main content
Add your own
alternative version


85 bookmarked
Posted 14 Mar 2003

Using ActiveX Controls Example: Insert Internet Explorer into your Dialogs

, 14 Mar 2003
Rate this:
Please Sign up or sign in to vote.
Inserting an ActiveX control (Internet Explorer) into your dialogs and handling relevant events.

Sample Image - WebBrowser1.png


This article is intended for newbies to the ActiveX world. In a Step-By-Step approach, it demonstrates inserting and handling the Microsoft Internet Explorer as an ActiveX control. The article shows how to insert the control, how to handle events and how to pass data to it. This article may also help you, if you want to use any other ActiveX control.

Inserting the ActiveX control

  1. On the dialog which you want to add the ActiveX control, right click the mouse to get the pop-up menu. From the pop-up menu, select Insert ActiveX Control.

    You will get a menu, scroll down and select Microsoft Web Browser as shown in the next image, then press OK.

    Sample screenshot

    All the other items in this menu are ActiveX controls which you can use. You may want to try out a couple of these later on, I am sure you will find a few of them interesting.

  2. After you have finished step 1, you will notice that a new control has appeared on screen. The ID for this control is IDC_EXPLORER1. You should at this stage stretch this controller as much as you can because you will need the space. Click the mouse on this control to highlight it, then press Ctrl and W to start the MFC Class Wizard.
  3. Click on the second tab, titled Member Variables. Then click on the ID of our new controller IDC_EXPLORER1 to highlight it. Afterwards, click on button Add Variable. This should open a dialog that informs you that MS Dev. Studio wants to generate a C++ wrapper class for our ActiveX control. Press OK (twice), and let MS Studio do its work.
  4. After MS Studio is done creating the class, a menu titled Add Member Variable will pop up asking you to name the variable. Give the variable a name like m_WebBrowserCtrl.
  5. You will now see the member variable next to the ID of our controller. MAKE SURE YOU PRESS "OK" NOW, otherwise all the previous changes will be rolled back by MS Studio.
  6. On the dialog, double click the button OK, and create a member function OnOK. We are going to use this button to test our new control. There are many functions that we can use in the new ActiveX control, I will explain a bunch of them later on in this article, but for now we are concerned with the command that allows the Web Browsing component to browse to a (any) webpage. The function is Navigate.
    void Navigate(LPCSTR URL, VARIANT *Flags, 
      VARIANT * TargetFrameName, VARIANT *PostData, VARIANT *Headers)

    Don't worry about all the variables, if you simply want your new web component to browse to a web page, all you have to do is the following:

                  NULL, NULL, NULL, NULL); 

    Delete the old contents of the OnOK function and add the previous line in its place. Thus the OnOk function will look like this:

    void CWebBrowserDlg::OnOK() 
                               NULL, NULL, NULL, NULL);

    Now would be a good time to test your application. Once your dialog is opened, click on OK, this should browse into the Code Project main web page.

More functions

Let's now explore a few functions for this ActiveX control:

void Navigate2(VARIANT * URL, VARIANT *Flags, VARIANT * TargetFrameName, 
                                        VARIANT *PostData, VARIANT *Headers) 

The same as Navigate, only this function also allows you to load files.

void GoBack()
void GoForward()

These two functions can be used to go forward and backward between browsed pages. Obviously, each has to have its own button on the dialog.

void GoHome()

This function will browse to the web page selected as the User Homepage, in the User Options for Internet Explorer.

void GoSearch()

This function will go to the Microsoft Internet search website.

void Refresh()

This function will refresh the current webpage.

void Stop()

This function stops loading the current page.

CString GetLocationName()

This function gets the name of the location, which is the string that is shown at the title bar of the normal Internet Explorer instance.

CString GetLocationURL()

This function gets the URL or the web address of the current web page.

There are other functions which you can use, you can find them all in MSDN under CHtmlView.

Events and messages

This component offers a wide range of events. To access the events, you can use the class wizard. Click the ActiveX control on the dialog, then press Ctrl and W, or right click on the control and select Events.... You will see a list of possible events you may want to use. Here are a few of them to get you started:


This event is fired before a navigation process to a URL starts.


This event is fired after a navigation process to a URL is done, and the page is loaded.

You can check all the other events, and use them in your applications as you might need, or see fit.

I hope this was as much fun to read as it was to write :)


For the animated images in the demo project, I used the article by Oleg Bykov. It is available on Code Project: Add GIF-animation to your MFC and ATL projects with the help of CPictureEx and CPictureExWnd .


This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


About the Author

Hazem Nasereddin
Product Manager
Jordan Jordan
Graduated in 1999 with a Bachelors Degree (Computer Engineering) from McGill University in Montreal, Canada. Participated in the development of The McGill Intelligent Classroom ( 2000 Joined Hummingbird Communications ( and worked in the development of HostExplorer and FTP-explorer. 2001 moved from Canada to Jordan. Worked at SigmaSoft, developing MFC-ObjectARX applications for AutoCAD and other AutoDesk products, as well as other MFC\COM applications. Worked for MECA developing their Instant Messenger. Now working for Esense Software developing Applications for cellular phones among many other things.

You may also be interested in...


Comments and Discussions

QuestionHow to refresh the content. Pin
NIKHIL788 Agrawal28-Dec-12 8:17
memberNIKHIL788 Agrawal28-Dec-12 8:17 
GeneralGet the URL content after Insert Internet Explorer into Dialogs Pin
littlecheer15-Jul-08 23:57
memberlittlecheer15-Jul-08 23:57 
QuestionWhat is Offline Browsing Pin
Vikrant for VC++13-Nov-06 5:42
memberVikrant for VC++13-Nov-06 5:42 
QuestionHow to Save the WebPage Pin
Vikrant for VC++13-Nov-06 5:40
memberVikrant for VC++13-Nov-06 5:40 
GeneralUsing Activex control in com/DLL Pin
Avikram28-Dec-05 1:40
memberAvikram28-Dec-05 1:40 
GeneralRe: Using Activex control in com/DLL Pin
priyanka s31-Aug-06 22:38
memberpriyanka s31-Aug-06 22:38 
register your active x control on that pc.without registring it will not work on any pc
GeneralRe: Using Activex control in com/DLL Pin
Mr.SeYeu13-Jul-08 21:31
memberMr.SeYeu13-Jul-08 21:31 
GeneralRe: Using Activex control in com/DLL Pin
Shailendra Sason31-Aug-08 22:18
memberShailendra Sason31-Aug-08 22:18 
GeneralSearching in current webpage Pin
piet3107825-Dec-05 22:50
memberpiet3107825-Dec-05 22:50 
GeneralAn active x control on this page might be unsafe... Pin
cristraum@yahoo.com7-Jun-05 7:37
susscristraum@yahoo.com7-Jun-05 7:37 
GeneralRe: An active x control on this page might be unsafe... Pin
Vikrant for VC++13-Nov-06 5:38
memberVikrant for VC++13-Nov-06 5:38 
GeneralCreating activeX control for own database Pin
sansanhtwe13-May-05 18:48
membersansanhtwe13-May-05 18:48 
Generalactivex for web [ urgent help needed ] Pin
rajiv mathew3-Mar-05 5:41
memberrajiv mathew3-Mar-05 5:41 
GeneralTo get History from IE Pin
Dhaval_p1-Feb-05 23:01
memberDhaval_p1-Feb-05 23:01 
GeneralResize Pin
BlackDragon23-Dec-04 11:17
memberBlackDragon23-Dec-04 11:17 
GeneralEmbed this dialog into a dll Pin
Qinsheng Lai16-May-04 15:10
memberQinsheng Lai16-May-04 15:10 
General.VB not VC Pin
dazza0007-May-04 16:46
memberdazza0007-May-04 16:46 
QuestionHow to create a dll which supports for web Pin
Anonymous2-May-04 21:51
sussAnonymous2-May-04 21:51 
QuestionCan Any 1 suggest me Pin
Rajeshkumar17-Apr-04 9:51
memberRajeshkumar17-Apr-04 9:51 
QuestionStay in one instance ??? Pin
iosens17-Mar-04 13:33
memberiosens17-Mar-04 13:33 
techmiss1-Mar-04 1:40
membertechmiss1-Mar-04 1:40 
QuestionHow de we scroll the page automatically? Pin
Anonymous22-Nov-03 9:32
sussAnonymous22-Nov-03 9:32 
GeneralUsing frames Pin
trudy_la_fee10-Sep-03 1:27
membertrudy_la_fee10-Sep-03 1:27 
QuestionCan help me? Pin
kyoshiro20-Apr-03 0:16
memberkyoshiro20-Apr-03 0:16 
AnswerRe: Can help me? Pin
Hazem Nasereddin20-Apr-03 3:29
memberHazem Nasereddin20-Apr-03 3:29 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web03 | 2.8.180111.1 | Last Updated 15 Mar 2003
Article Copyright 2003 by Hazem Nasereddin
Everything else Copyright © CodeProject, 1999-2018
Layout: fixed | fluid