-6

Every single windows computer has ie installed by default so i want to make a program that uses ie to show a web page! I want the program to be just a simple window without adressbar! Also i want to add a close , maximize and minimize buttons to the program. Also i want to add icon for the program to! Any idea how can i do that?

Kdforf
  • 41
  • 1
  • 2
  • 1
    dup: http://stackoverflow.com/questions/9051817/embedding-an-internet-explorer-control-c-winapi or at least lack of effort searching... – Caribou Jan 10 '13 at 16:03
  • Those didnt work for me! I searched alot! I dont want the full ie ijust want itto show a page in my program withoud adressbar and toolbars! – Kdforf Jan 10 '13 at 16:12
  • 3
    Good thing you want so much things. I want a Ferrari. I guess we'll both have to [**work**](http://mattgemmell.com/2008/12/08/what-have-you-tried/) for it. – ereOn Jan 10 '13 at 16:15
  • 1
    it's an embedded control in "your" program : clicking on one of the links in that answer gives this page with a picture of IE in a users app... http://www.codeproject.com/Articles/3919/Using-the-WebBrowser-control-simplified – Caribou Jan 10 '13 at 16:17

1 Answers1

4

Assuming you use MFC, this is fairly trivial. Create an MFC application with the AppWizard. In the first page of the AppWizard options, change the "Application Style" to "MFC Standard" and (probably) change it to a "Single Document" program. In the last page, change the base class for your view from CView to CFormView.

Go to the project's resource view, and edit the IDD_<project_name>_FORM dialog. It'll initially contain a static control saying something about "insert controls here". Delete that static control, then right-click on the form and select "Insert ActiveX Control...". That'll pop up a list of ActiveX controls. Choose "Microsoft Web Browser" from the list.

That'll put a (small) web browser in your window (you probably want to stretch it to fill the window). Right click on the control, and select "Add variable...". That'll bring up a dialog where you need to fill in the name for the variable (e.g., you could name it "browser").

Then switch to the class view and choose your view class. In the lower pane, double click on "OnInitialUpdate". After the code that's already present for that function, add a line like:

browser.Navigate("http://www.google.com", NULL, NULL, NULL, NULL);

[obviously replacing "http://www.google.com" with the URL of the web site you want to display].

Compile and run, and (assuming your computer is connected to the Internet, etc.) it should open the chosen web page at startup.

You probably also want to add a handler for WM_SIZE in your view, and have it resize the control to fill the window when/if the user resizes the window. This is a tiny bit more complicated, because your window will receive WM_SIZE messages before your control is entirely initialized. As such, you normally want to add a bool variable named something like "control_valid". Initailize it to "false" in the view's constructor. In the OnInitialUpdate code after the "Navigate" call, add "valid = true;". Then in the WM_SIZE handler, only resize the control if (valid), something like:

void Cbrowse_fixedView::OnSize(UINT nType, int cx, int cy)
{
    CFormView::OnSize(nType, cx, cy); 

    // This is the block of code we added:
    if(valid) {
        CRect rect;
        GetClientRect(&rect);
        m_browser.MoveWindow(&rect);
    }
}

With that, When the user resizes the application's window, the browser control will be resized to fill the window at all times.

Jerry Coffin
  • 476,176
  • 80
  • 629
  • 1,111
  • 1
    @Kdforf: On this site you normally express your approval of an answer by up-voting and/or accepting it (by clicking on the check-mark below the number on the left). – Jerry Coffin Jan 11 '13 at 18:58