CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    May 2004
    Posts
    72

    navigate internet explorer

    I have a simple little app that runs in the background, and runs a timer to set the Address Bar of internet explorer to a certian url, then it sends the messages WM_KEYDOWN and WM_KEYUP for VK_RETURN.

    The only problem is that when it sends the enter key, IE gets focus, and must be minimized. So I added a little bit of code, right before it sends the enter key, it gets the foregroundwindow, then sets that window to the foreground after it sends the enter key.

    That didn't solve the problem entirely, because now the window 'flashes' over the current window, and is annoying if typing, since 1 or 2 characters get intercepted when IE is the foreground window.

    Is there a simpler way to navigate the page of a current IE window (without opening new windows) so that IE does not get focus?

    Sorry for my ignorance, I am still new to C++ :-/
    Thanks for any help!

  2. #2
    Join Date
    May 2005
    Posts
    4,954

    Re: navigate internet explorer

    yes you can use OLE automation look at the IWebBrowser2 interface.
    and look at the function navigate(..)

    Cheers
    If a post helped you dont forget to "Rate This Post"

    My Article: Capturing Windows Regardless of Their Z-Order

    Cheers

  3. #3
    Join Date
    May 2004
    Location
    Michigan, United States
    Posts
    457

    Re: navigate internet explorer

    Here's a complete program that loads IE and navigates to a certain website (google, in this case). If you don't mind using COM, it sounds like it would work well for you, with what you're trying to accomplish:
    Code:
    #include <windows.h>
    #include <ExDisp.h>
    #include <ExDispID.h>
    
    int main()
    {
    	CoInitialize(NULL);
    
    	HRESULT hr;
    	IWebBrowser2* pWebBrowser = NULL;
    	hr = CoCreateInstance (CLSID_InternetExplorer, NULL, CLSCTX_SERVER, IID_IWebBrowser2, (LPVOID*)&pWebBrowser);
    	
    	if (SUCCEEDED (hr) && (pWebBrowser != NULL))
    	{
    		VARIANT vDummy = {0};
    		VARIANT vUrl;
    
    		vUrl.vt = VT_BSTR;
    		vUrl.bstrVal = SysAllocString(L"http://www.google.com");
    		pWebBrowser->Navigate2(&vUrl, &vDummy, &vDummy,&vDummy, &vDummy);
    		VariantClear(&vUrl);
    
    		// If you want to display the IE window...
    		pWebBrowser->put_Visible(VARIANT_TRUE);
    	}
    	else
    	{
    		if (pWebBrowser)
    			pWebBrowser->Release();
    	}
    
    	CoUninitialize();
    
    	return 0;
    }
    Programming today is a race between software engineers striving to build bigger and better idiot-proof programs and the Universe trying to produce bigger and better idiots. So far, the Universe is winning.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured