IE Launching in windows

This is a discussion on IE Launching in windows within the C++ Programming forums, part of the General Programming Boards category; How do I launch a internet explorer window in windows, that starts out in the URL I specify? BTW: I ...

  1. #1
    Banned frenchfry164's Avatar
    Join Date
    Oct 2001
    Posts
    1,552

    IE Launching in windows

    How do I launch a internet explorer window in windows, that starts out in the URL I specify?

    BTW: I am using allegro, so some things I can't include (allegro likes to overdo windows stuff)

  2. #2
    Unregistered
    Guest
    I think this works. Ok well it might work, I didn't compile it. But is should work on VC, and maybe it also works on other compilers.
    I dunno, try it.

    #include <windows.h>
    // Internet Explorer's IID
    IID const IID_IWebBrowserApp={0x0002DF05,0x0000,0x0000,0xC0, 0x00,0x00,0x00,0x00,0x00,0x00,0x46};

    void InternetExplorerNav(CString & str)
    {
    HRESULT hResult;
    IWebBrowserApp* pBrowser;
    VARIANT vFlags = {0};
    VARIANT vTargetFrameName = {0};
    VARIANT vPostData = {0};
    VARIANT vHeaders = {0};

    BSTR pURL = str.AllocSysString();

    if (FAILED(hResult=CoInitialize(NULL)))
    { // failure message
    }

    if (FAILED(hResult = CoCreateInstance(
    CLSID_InternetExplorer, NULL, CLSCTX_SERVER,
    IID_IWebBrowserApp, (LPVOID*)&pBrowser)))
    { // some error messag
    }

    if (FAILED(pBrowser->Navigate(pURL,&vFlags, &vTargetFrameName, &vPostData, &vHeaders)))
    {
    // failure message
    }


    if ( pBrowser ) pBrowser->Release();

    CoUninitialize();

  3. #3
    Banned frenchfry164's Avatar
    Join Date
    Oct 2001
    Posts
    1,552
    I can't include windows.h, it conflicts with allegro.h

  4. #4
    Registered User Dual-Catfish's Avatar
    Join Date
    Sep 2001
    Posts
    802
    Use CreateProcess()
    But then again, that's defined in windows.h

    Try using system("iexplore.exe -o webpage");
    and remember to include stdlib.h

  5. #5
    Registered User
    Join Date
    Feb 2002
    Posts
    98

    IE Launching in windows

    Code:
    // ex08bView.cpp : implementation of the CEx08bView class
    //
    
    #include "stdafx.h"
    #include "ex08b.h"
    
    #include "ex08bDoc.h"
    #include "ex08bView.h"
    
    #ifdef _DEBUG
    #define new DEBUG_NEW
    #undef THIS_FILE
    static char THIS_FILE[] = __FILE__;
    #endif
    
    /////////////////////////////////////////////////////////////////////////////
    // CEx08bView
    
    const char CEx08bView::s_engineGoogle[] =
    	"http://Google.com/";
    
    IMPLEMENT_DYNCREATE(CEx08bView, CView)
    
    BEGIN_MESSAGE_MAP(CEx08bView, CView)
    	//{{AFX_MSG_MAP(CEx08bView)
    	ON_WM_CREATE()
    	ON_WM_SIZE()
    	//}}AFX_MSG_MAP
    END_MESSAGE_MAP()
    
    /////////////////////////////////////////////////////////////////////////////
    // CEx08bView construction/destruction
    
    CEx08bView::CEx08bView()
    {
    	// TODO: add construction code here
    
    }
    
    CEx08bView::~CEx08bView()
    {
    }
    
    BOOL CEx08bView::PreCreateWindow(CREATESTRUCT& cs)
    {
    	// TODO: Modify the Window class or styles here by modifying
    	//  the CREATESTRUCT cs
    
    	return CView::PreCreateWindow(cs);
    }
    
    /////////////////////////////////////////////////////////////////////////////
    // CEx08bView drawing
    
    void CEx08bView::OnDraw(CDC* pDC)
    {
    	CEx08bDoc* pDoc = GetDocument();
    	ASSERT_VALID(pDoc);
    
    	// TODO: add draw code for native data here
    }
    
    /////////////////////////////////////////////////////////////////////////////
    // CEx08bView diagnostics
    
    #ifdef _DEBUG
    void CEx08bView::AssertValid() const
    {
    	CView::AssertValid();
    }
    
    void CEx08bView::Dump(CDumpContext& dc) const
    {
    	CView::Dump(dc);
    }
    
    CEx08bDoc* CEx08bView::GetDocument() // non-debug version is inline
    {
    	ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CEx08bDoc)));
    	return (CEx08bDoc*)m_pDocument;
    }
    #endif //_DEBUG
    
    /////////////////////////////////////////////////////////////////////////////
    // CEx08bView message handlers
    
    int CEx08bView::OnCreate(LPCREATESTRUCT lpCreateStruct) 
    {
    	if (CView::OnCreate(lpCreateStruct) == -1)
    		return -1;
    	
    	DWORD dwStyle = WS_VISIBLE | WS_CHILD;	
    	if (m_search.Create(NULL, dwStyle, CRect(0, 0, 100, 100),
    	                    this, ID_BROWSER_SEARCH) == 0) {
    		AfxMessageBox("Unable to create search control!\n");
    		return -1;
    	}
    	m_search.Navigate(s_engineGoogle, NULL, NULL, NULL, NULL);
    
    	if (m_target.Create(NULL, dwStyle, CRect(0, 0, 100, 100),
    	                    this, ID_BROWSER_TARGET) == 0) {
    		AfxMessageBox("Unable to create target control!\n");
    		return -1;
    	}
    	m_target.GoHome(); // as defined in IE3 options
    
    	return 0;
    }
    
    void CEx08bView::OnSize(UINT nType, int cx, int cy) 
    {
    	CView::OnSize(nType, cx, cy);
    
    	CRect rectClient;
    	GetClientRect(rectClient);
    	CRect rectBrowse(rectClient);
    	rectBrowse.right = rectClient.right / 2;
    	CRect rectSearch(rectClient);
    	rectSearch.left = rectClient.right / 2;
    
    	m_target.SetWidth(rectBrowse.right - rectBrowse.left);
    	m_target.SetHeight(rectBrowse.bottom - rectBrowse.top);
    	m_target.UpdateWindow();
    
    	m_search.SetLeft(rectSearch.left);
    	m_search.SetWidth(rectSearch.right - rectSearch.left);
    	m_search.SetHeight(rectSearch.bottom - rectSearch.top);
    	m_search.UpdateWindow();
    }
    
    BEGIN_EVENTSINK_MAP(CEx08bView, CView)
    	ON_EVENT(CEx08bView, ID_BROWSER_SEARCH, 100, OnBeforeNavigateExplorer1, VTS_BSTR VTS_I4 VTS_BSTR VTS_PVARIANT VTS_BSTR VTS_PBOOL)
    	ON_EVENT(CEx08bView, ID_BROWSER_TARGET, 113, OnTitleChangeExplorer2, VTS_BSTR)
    END_EVENTSINK_MAP()
    
    void CEx08bView::OnBeforeNavigateExplorer1(LPCTSTR URL,
    	long Flags, LPCTSTR TargetFrameName,
    	VARIANT FAR* PostData, LPCTSTR Headers, BOOL FAR* Cancel)
    {
    	TRACE("CEx08bView::OnBeforeNavigateExplorer1 -- URL = %s\n", URL);
    
    	if (!strnicmp(URL, s_engineGoogle, strlen(s_engineGoogle))) {
    		return;
    	}
    	m_target.Navigate(URL, NULL, NULL, PostData, NULL);
    	*Cancel = TRUE;
    }
    
    void CEx08bView::OnTitleChangeExplorer2(LPCTSTR Text)
    {
    	// Careful!  Event could fire before we're ready.
    	CWnd* pWnd = AfxGetApp()->m_pMainWnd;
    	if (pWnd != NULL) {
    		if (::IsWindow(pWnd->m_hWnd)) {
    			pWnd->SetWindowText(Text);
    		}
    	}
    }
    Code:
    // ex08bView.h : interface of the CEx08bView class
    //
    /////////////////////////////////////////////////////////////////////////////
    
    #if !defined(AFX_EX08BVIEW_H__13D86A41_5BC8_11D0_8FD1_00C04FC2A0C2__INCLUDED_)
    #define AFX_EX08BVIEW_H__13D86A41_5BC8_11D0_8FD1_00C04FC2A0C2__INCLUDED_
    
    #include "webbrowser.h"	// Added by ClassView
    class CEx08bView : public CView
    {
    private:
    	static const char s_engineGoogle[];
    
    protected: // create from serialization only
    	CEx08bView();
    	DECLARE_DYNCREATE(CEx08bView)
    
    // Attributes
    public:
    	CEx08bDoc* GetDocument();
    
    // Operations
    public:
    
    // Overrides
    	// ClassWizard generated virtual function overrides
    	//{{AFX_VIRTUAL(CEx08bView)
    	public:
    	virtual void OnDraw(CDC* pDC);  // overridden to draw this view
    	virtual BOOL PreCreateWindow(CREATESTRUCT& cs);
    	protected:
    	//}}AFX_VIRTUAL
    
    // Implementation
    public:
    	virtual ~CEx08bView();
    #ifdef _DEBUG
    	virtual void AssertValid() const;
    	virtual void Dump(CDumpContext& dc) const;
    #endif
    
    protected:
    
    // Generated message map functions
    protected:
    	//{{AFX_MSG(CEx08bView)
    	afx_msg int OnCreate(LPCREATESTRUCT lpCreateStruct);
    	afx_msg void OnSize(UINT nType, int cx, int cy);
    	//}}AFX_MSG
    	DECLARE_MESSAGE_MAP()
    
    protected:
    	afx_msg void OnBeforeNavigateExplorer1(LPCTSTR URL,
    		long Flags, LPCTSTR TargetFrameName,
    		VARIANT FAR* PostData, LPCTSTR Headers, BOOL FAR* Cancel);
    	afx_msg void OnTitleChangeExplorer2(LPCTSTR Text);
    	DECLARE_EVENTSINK_MAP()
    
    private:
    	CWebBrowser m_target;
    	CWebBrowser m_search;
    };
    
    #ifndef _DEBUG  // debug version in ex08bView.cpp
    inline CEx08bDoc* CEx08bView::GetDocument()
       { return (CEx08bDoc*)m_pDocument; }
    #endif
    
    /////////////////////////////////////////////////////////////////////////////
    
    //{{AFX_INSERT_LOCATION}}
    // Microsoft Developer Studio will insert additional declarations immediately before the previous line.
    
    #endif // !defined(AFX_EX08BVIEW_H__13D86A41_5BC8_11D0_8FD1_00C04FC2A0C2__INCLUDED_)

    i didnt know what files to show here, so i put the view.cpp and the view.h code.this opens a window with a slitter bar in the middle,search engine on the right, when you search, it shows it on the left, but you can change the default opening page to whatever you want it to be.im using msvc++ 6, and i have to include webbrowser.h to get this to work

  6. #6
    &TH of undefined behavior Fordy's Avatar
    Join Date
    Aug 2001
    Posts
    5,789
    Whoopee!!!! Its one of those competitions for finding the most painfull ways of doing a rather mundane task.......

    Not having much time to play....here's my submission

    Code:
    #include <Shellapi.h>
    //Dont forget Shell32.lib
    
    
    int WINAPI WinMain(HINSTANCE hThisInstance,
                       HINSTANCE hPrevInstance,
                       LPSTR lpszArgument,
                       int nShowState)
    {
        ShellExecute(HWND_DESKTOP, 
                     "OPEN",
                     "http://www.cprogramming.com",
                     NULL,
                     NULL,
                     SW_SHOWNORMAL);  
      return 0;
    }
    Not as cool as the COM and MFC examples, but hell!!!!....I'm busy

  7. #7
    Banned frenchfry164's Avatar
    Join Date
    Oct 2001
    Posts
    1,552
    you can use system() in windows? It's defined in dos.h, so I don't think you can.

  8. #8
    Banned frenchfry164's Avatar
    Join Date
    Oct 2001
    Posts
    1,552
    the system() method did not work, as I thought it wouldn't. It just minimizes my game. I used both dos.h and stdlib.h system()'s and it didn't work.

    I need a simple way to do this. I just want to make it to where if you click the logo in the main menu of my game it opens up IE and goes to http://frenchfry164.tripod.com

  9. #9
    &TH of undefined behavior Fordy's Avatar
    Join Date
    Aug 2001
    Posts
    5,789
    Er....did you try the ShellExecute() method??

  10. #10
    Banned frenchfry164's Avatar
    Join Date
    Oct 2001
    Posts
    1,552
    what's that?

  11. #11
    &TH of undefined behavior Fordy's Avatar
    Join Date
    Aug 2001
    Posts
    5,789
    Originally posted by frenchfry164
    what's that?
    Jeez....

    Read my previous post

  12. #12
    Banned frenchfry164's Avatar
    Join Date
    Oct 2001
    Posts
    1,552
    well I don't have Shell32.lib because I use Dev-C++, and it doesn't come with ANY .lib files.

  13. #13
    &TH of undefined behavior Fordy's Avatar
    Join Date
    Aug 2001
    Posts
    5,789
    ...

    Try libshell32.a

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Anyone using Windows 7?
    By Sharke in forum General Discussions
    Replies: 60
    Last Post: 07-12-2009, 09:05 AM
  2. Dialog Box Problems
    By Morgul in forum Windows Programming
    Replies: 21
    Last Post: 05-31-2005, 06:48 PM
  3. dual boot Win XP, win 2000
    By Micko in forum Tech Board
    Replies: 6
    Last Post: 05-30-2005, 03:55 PM
  4. SDL and Windows
    By nickname_changed in forum Windows Programming
    Replies: 14
    Last Post: 10-24-2003, 01:19 AM
  5. IE 6 status bar
    By DavidP in forum Tech Board
    Replies: 15
    Last Post: 10-23-2002, 06:31 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21