muanis

I've coded a small BHO wich I can enable or disable trhough a button in the main toolbar.

The button uses the same class of the bho, and implements IOleCommandTarget, in Exec method I save a registry value to keep state of the bho, pretty much like skype plugin.

But I'm having problems to keep the button state (pressed or not) when the browser starts. I can get a handle to the main browser window when the DocumentComplet event fires (it fire even with about:blankWink. But I can't manage to have access to my toolbar button to press it.

Someone can point me for some docs I've already search a lot in the forums and google.

Thanks in advance!

Jose Muanis




Re: Internet Explorer Extension Development Keeping buton state when browser starts

Appxweb

Hi Jose,

You can set the state of the button when it is first created using the fsState flag of the TBButton structure. Once the button is created you can change any of the button's properties programmatically using the SetButtonInfo() method of CCommandBarCtrlBase, which your toolbar is derived from. The trick is that you use the command id of the button, not the button's index with this method. For example

TBBUTTON tbb;

m_pYourCmdBar->GetButton (nButtonIndex, &tbb);

TBBUTTONINFO tbbi = { 0 };

tbbi.cbSize = sizeof(TBBUTTONINFO);
tbbi.dwMask = TBIF_STATE;

tbbi.fsState = TBSTATE_ENABLED; // or TBSTATE_INDETERMINATE

m_pYourCmdBar->SetButtonInfo(tbb.idCommand, &tbbi);

Kind Regards

Ian Hart






Re: Internet Explorer Extension Development Keeping buton state when browser starts

muanis

First of all, thanks a lot Ian!

Thats great, but it's not "my" toolbar, it's Internet Explorer's default toolbar wich I eventually added my button (through customize etc). I'm a native java programmer (don't blame me please) in the (for me) dangerous jungle of c++/atl/com :-) In my world I would get some kind of iterator on the childs of the main explorer window. But in windows programming I'm kinda lost.

In my code, I used the following to get the handler to the main internet explorer window.

HWND hwnd;
browserRef->get_HWND((LONG_PTR*)&hwnd);

note: browserRef implements IWebBrowser2

I know that I must use some message to obtain the toolbar reference, but I'm stuck on it.


Anyway, thanks a lot for your help. I'll continue to dig the apis and look for some more info.

And you may be asking why a java programmer is playing with windows programming. Maybe it's because you're never too old to grow a little more.

Best,

Jose Muanis




Re: Internet Explorer Extension Development Keeping buton state when browser starts

Appxweb

Hi Jose,

Here is another approach. I will qualify this by saying 1) this is untested - I am currently at work using IE6 and 2) there probably a much easier way of doing this via a some registry magic. With regards to the latter someone like Rob- IECUSTOMIZER, who posts to this forum may have some ideas.

Step 1 - Get the handle to the browser window. (which you already have) Call this hWndBrowser

Step 2 - Iterate through the band objects of the browser window looking for a match for the toolbar (band) you are interested in. The difficult part here is the match criteria as the same class name "ToolbarWindow32" is used by different IE toolbar/bands eg 1)the standard button toolbar 2) address bar and 3) links toolbar. It is probably easiest to to brute force it, iterating through the buttons on each toolbar looking for your button.

int nCount = (int)SendMessage(hWndBrowser, RB_GETBANDCOUNT, 0, 0L);
for(int i = 0; i < nCount; i++)
{
// Set the band info
REBARBANDINFO rbbi = { sizeof(REBARBANDINFO), RBBIM_CHILD | RBBIM_BACKGROUND };
SendMessage(hWndBrowser, RB_GETBANDINFO, i, (LPARAM)&rbbi);

TCHAR szClass{MAX_PATH] = {0};

GetClassName(rbbi.hwndChild , szClass, MAX_PATH);

if(lstrcmpi(szClass, __TEXT("ToolbarWindow32")) // First level of match criteria

{

int iButtonsCount = SendMessage(rbbi.hwndChild, TB_BUTTONCOUNT, 0, 0);

for( int x= 0; x<iButtonsCount ; x++)

{

TBBUTTON tbb;

SendMessage(rbbi.hwndChild, TB_GETBUTTON, x, &tbb);

// Do what you need to here to check that you have your button

if (match found)

{

TBBUTTONINFO tbbi = { 0 };

tbbi.cbSize = sizeof(TBBUTTONINFO);
tbbi.dwMask = TBIF_STATE;

tbbi.fsState = TBSTATE_ENABLED; // or TBSTATE_INDETERMINATE

SendMessage( TB_SETBUTTONINFO, tbb.idCommand, &tbbi);

// Note you could use TB_SETSTATE instead of TB_SETBUTTONINFO but from memory I have //had trouble making this work in the past

}

}

}

}

}

Finally have a look at this article at the Code Project which appears to be solving a similar type of problem but for tray icons - http://www.codeproject.com/shell/ctrayiconposition.asp. I am not sure whether the process issues discussed about in this article apply and need to be taken into account - I suspect they do in which case you would need to make changes to the above code. Its is starting to get messy and is probably simpler if you already have a BHO to add your own toolbar and add a button to it.

Kind Regards

Ian Hart






Re: Internet Explorer Extension Development Keeping buton state when browser starts

IECUSTOMIZER

Hi Muanis,

The Command Bar button state is handled automatically. When you create the registry entries for the button you include the CLSID of your Toolbar or Explorer Bar COM CLSID value in the BANDCLSID value. This does not work for BHO's!

The trouble with your approach is that... ok... the user disables your bho by pressing the Command Bar button. The next time your user starts the browser, your BHO has been disabled (does this mean that it is not loaded by IE or you just exit its methods ) and there is no hook into IE to redraw the Command Bar button with he disabled state icon.

Aworkaround, possibley is to set the default icon for the active state to the disabled icon, when you BHO loads in the Active state it redraws the icon as the toolbar is rendered to the enabled icon.

This way, when your BHO is disabled, the disabled icon will be displayed.

Users can disable all their Toolbars and BHO's - Advanced tab "Enable third-party browser extensions", so also when a user choses this setting your Command Bar button icon will display the disabled state.

Regards.






Re: Internet Explorer Extension Development Keeping buton state when browser starts

muanis

Hello you all, I've been away from the code for the last few days. I got back to it and discovered that I'm getting the browser window (the one where de IWebBrowser2 is attached). I'm trying since then get the topmost internet explorer window handler.

I've used iSpy and I know that I have two more windows, the one where the Browser is, another one holds the Toolbars, and a third one is the holder of these 2.

I'll post any progress wich I have.

Thanks!