Add browser action button in internet explorer BHO

后端 未结 4 1901
深忆病人
深忆病人 2020-12-04 19:34

So. I\'m working on a BHO in IE and I want to add a browser action like this:

\"enter<

4条回答
  •  天涯浪人
    2020-12-04 20:08

    Dll injection is the answer, buddy.

    Here you go.

    Edit:

    Sure. It seems you don't have to do DLL injection, BHO's got access from the inside of the IE process. So then it's a lot easier.

    Basicly, you need to find the window first. So by modifying the function to suit your needs, it will look like this:

    BOOL FindFavoritesAndToolsBar(HWND mainWnd, HWND* addressBarWnd, HWND* cmdTargetWnd)
    {
      mainWnd = ::FindWindowEx( mainWnd, NULL, TEXT( "WorkerW" ), NULL );
      mainWnd = ::FindWindowEx( mainWnd, NULL, TEXT( "ReBarWindow32" ), NULL );
    
      *cmdTargetWnd = ::FindWindowEx
      mainWnd, NULL, TEXT( "ControlBandClass" ), NULL );
    
      if( *cmdTargetWnd  )
          *addressBarWnd = ::FindWindowEx(
          *cmdTargetWnd, NULL, TEXT( "ToolbarWindow32" ), L"Favorites and Tools Bar" );
    
      return cmdTargetWnd != NULL;
    }
    

    I used Spy++ to find it.

    The rest of the logic is the same as the article I linked. You subclass to intercept the message loop, and add your own event handlers for your own button.

    Another approach is to just create a button as a popup window, set IE window as the parent, find the position of the "Favorities and tools bar", and position the button adjacent to it. Even easier, but less elegant of course.

    Edit 2: Sorry, I just saw I echoed some of Oliver's answer. However, if you do what I wrote above inside the BHO, the button will behave as any of IE's own buttons and you have full control over it.

提交回复
热议问题