SHGetInstanceExplorer
Allows components that run in a Web browser (Iexplore.exe) or a nondefault Windows® Explorer (Explorer.exe) process to hold a reference to the process. The components can use the reference to prevent the process from closing prematurely.HRESULT SHGetInstanceExplorer(
    IUnknown **ppunk
);Parameters
ppunk 
[out] Address of an Explorer.exe or Iexplore.exe IUnknown interface pointer. If the function succeeds, SHGetInstanceExplorer increments the host's reference count before it returns. Components thus do not need to call (*ppunk)->AddRef. Components should call (*ppunk)->Release to release the reference when the host process is no longer needed. If SHGetInstanceExplorer fails, *ppunk is set to NULL. 
Return Values
Returns S_OK if successful, or an OLE error code otherwise. Res
There are a number of components, such as shell extension handlers, that are implemented as DLLs and run in the process space of Windows Explorer (Explorer.exe) or Internet Explorer (Iexplore.exe). Normally, when the user closes the host process, the component is shut down immediately as well. Such an abrupt termination can create problems for some components. For example, if a component is using a background thread to download data or run user-interface functions, it might need additional time to safely shut itself down.The SHGetInstanceExplorer function allows components that run in an Iexplorer.exe or a nondefault Explorer.exe process to hold a reference on the host process. SHGetInstanceExplorer increments the host's reference count and returns a pointer to its IUnknown interface. By holding that reference, a component can prevent the host process from closing prematurely. Once the component has completed all necessary processing, it should call (*ppunk)->Release to release the host's reference and allow the process to die.Note If SHGetInstanceExplorer is successful, the component must release the host's reference when it is no longer needed. Otherwise, all resources associated with the process will remain in memory. The IUnknown interface pointed to by *ppunk can be used only to release this reference. Components cannot use (*ppunk)->QueryInterface to request other interface pointers. SHGetInstanceExplorer succeeds only if it is called from within an Explorer.exe or Iexplorer.exe process. It is typically used by components that run in the context of the Web browser (Iexplore.exe). However, it is also useful when Explorer.exe has been configured to run all folders in a second process. SHGetInstanceExplorer fails if the component is running in the default Explorer.exe process. There is no need to hold a reference to this process, as it is shut down only when the user logs out.In general, components can be loaded by either the default Explorer.exe process or a secondary Explorer.exe or Iexplore.exe process. The component must thus be able to handle either the success or failure of SHGetInstanceExplorer. Requirements 
  Version 4.00 and later of Shell32.dll  Windows NT/2000: Requires Windows NT 4.0 or later. 
  Windows 95/98: Requires Windows 95 or later. 
  Header: Declared in shlobj.h. 
  Import Library: shell32.lib. 

解决方案 »

  1.   

    以下程序查找浏览器的地址栏,并可以随意输入网址!//OK#include "stdafx.h"
    #include "stdio.h"
    #include <windows.h>BOOL CALLBACK FindTrayWnd(HWND hwnd, LPARAM lParam);int main(int argc, char* argv[])
    {
    HWND hwndParent;
    hwndParent=FindWindow("IEFrame",NULL); //或使用特定的IE的Caption返回局柄
    EnumChildWindows(hwndParent, FindTrayWnd, NULL);return 0;
    }
    BOOL CALLBACK FindTrayWnd(HWND hwnd, LPARAM lParam)
    {
        TCHAR szClassName[256];
    TCHAR szURL[256];
        GetClassName(hwnd,szClassName,255);
    if(_stricmp("Edit",szClassName)==0) //找到地址栏
    {
    printf("%s\n",szClassName);
    SendMessage(hwnd,WM_GETTEXT,100,(LPARAM)szURL);
    printf("%s\n",szURL);
    strcpy(szURL,"http://www.netease.com");
    SendMessage(hwnd,WM_SETTEXT,100,(LPARAM)szURL);
    SendMessage(hwnd,WM_KEYDOWN,VK_RETURN,0);
    SendMessage(hwnd,WM_KEYUP,VK_RETURN,0);
    }
    SendMessage(hWnd,WM_CLOSE,0,0);
        return TRUE;
    }