ButtonDemo - Refresh and Drop-down toolbar button handling in BHO
-
Sunday, February 17, 2008 11:11 PMSorry for the delay, i was busy with the arrival of my new son and subsequent catchup at work.. As promised find links to sample code that demonstrates adding almost perfect (AFAICT
) page-refresh support and a simplified drop down menu implementation for BHOs.
The code should be self explanatory - hopefully... and you can find it at
http://code.google.com/p/pricegoblin/wiki/DemoButton
There are 2 minor issues that i am aware of that i've not got around to fixing as they don't impact the day to day use but if anyone wants to post a solution i'll happily use it
1 - If you interrupt a page with a refresh before it has completed loading, the refresh handler isn't setup.
2 - The menu doesn't completely emulate IEs drop-down buttons in that if you roll of the menu onto another button the menu stays and the other button isn't highlighted - This is because i've used the built in drop-down menu function in windows, if you implemented your own menu code with message handler, you could detect this...
any way enjoy and let me have any feedback..
All Replies
-
Friday, February 22, 2008 12:09 PM
Thanks a lot! This is by far the most simple and best solution i have seen for the refresh issue so far.
-
Wednesday, April 16, 2008 4:39 AM
I was able to compile the source code, registered the DLL, and did demo without problem. However, when I was closing the Internet Explorer, it crashed. following is error detail:
Error signature:
AppName: iexplore.exe AppVer: 6.0.2800.1106 ModName: shdocvw.dll
ModVer: 6.0.2800.1692 Offset: 00032a7b
This was on a Windows 2000 PC with IE6.0. Please advise.
Thanks,
Lark
-
Wednesday, April 16, 2008 9:21 AMTry running it in the debugger and shutting down IE. I suspect that i'm either not releasing a COM object or (probably) releasing one twice. Debugging should help show which object is causing the problem although i have only tested it on XP and upwards..
-
Wednesday, April 30, 2008 7:22 AM
Great code, work like a charm, even better then the original since you have separate handling for clicking on the button and on the arrow.
If I want to disable the button click and instead when clicking on the button to always open the menu, how do do it?
-
Wednesday, April 30, 2008 9:19 AMOne of 2 ways:
the easiest way is to intercept WM_COMMAND in CRebarHandler which is called when the button is pressed,
Alternatively separate out the menu code from CRebarHandler and call that in the button Exec method as well as from the OnNotifyDropdown. -
Sunday, May 04, 2008 1:19 PM
Tn'x I tried the first suggestion and its work almost perfect, I intercept WM_COMMAND and call to onNotifyDropDown function, the problem I have now is to send the correct coordinates of the pNMTOOLBAR->rcButton.left & right.
Also I noticed another small problem: after selecting one of the options in the menu, if the IE window not lose its focus the menu don't collapse itself. -
Sunday, May 04, 2008 2:31 PMUnfortunately i used the function to save time which doesn't behave exactly as IE does - as you point out it waits for a selection before disappearing. Also if you move the mouse across the toolbar the other menus disappear as the button looses focus. You could implement your own pop up menu if you want to emulate IE completley. Also be aware that this breaks in IE8 (with protected mode on and also maybe off) as you can't easily subclass the command bar any more
-
Sunday, May 04, 2008 2:31 PMUnfortunately as i used the TrackPopupMenu function to save time which doesn't behave exactly as IE does - as you point out it waits for a selection before disappearing. Also if you move the mouse across the toolbar the other menus disappear as the button looses focus. You could implement your own pop up menu if you want to emulate IE completley. Also be aware that this breaks in IE8 (with protected mode on and also maybe off) as you can't easily subclass the command bar any more
-
Friday, September 26, 2008 9:47 AMHi.
Your sources is not available now. I always get the following error:
Forbidden
Your client does not have permission to get URL /p/pricegoblin/wiki/DemoButton from this server.
Could you please reshare it on Google?
Thanks. -
Friday, September 26, 2008 10:20 AMReinstated.
-
Tuesday, December 02, 2008 7:35 PMCould you please reshare it on Google?
Thanks. -
Monday, March 30, 2009 6:21 AMCan ButtonDemo work with IE8? The Demo button shows up on the IE8 command bar. However, there is no drop-down menu.
Thanks. -
Thursday, April 30, 2009 11:36 AMPlease reshare your solution on Google once again.
Or mail the code to "petuschak [at] gmail.com".
Thanks in advance for your help! -
Tuesday, June 02, 2009 1:03 PMYes, please reshare your solution. This refresh-issue is horribly annoying.
-
Saturday, July 04, 2009 9:08 AMHi John,I am trying to accomplish the (almost impossible?) task of catching a refresh event on IE from a toolbar (BHO). I'm wrtining in C#, and I'm having some trouble understanding how to port your C++ code to C#.You use an event sink to handle the onload event of the page. I tried using the following code in C# to do the same without the connection point stuff:HTMLDocument doc = this.engine.Explorer.Document as HTMLDocument;if (doc != null){IHTMLWindow2 tmpWindow = doc.parentWindow;if (tmpWindow != null){m_events = (tmpWindow as HTMLWindowEvents2_Event);try{m_events.onload -= new HTMLWindowEvents2_onloadEventHandler(RefreshHandler);}catch { }m_events.onload += new HTMLWindowEvents2_onloadEventHandler(RefreshHandler);}}as suggested by someone on this thread: http://social.msdn.microsoft.com/forums/en-US/ieextensiondevelopment/thread/7a3a8d96-52f5-4ec0-a395-222c3dffa4b2/.As mentioned, this doesn't always work, as some sites (such as Facebook) do not fire onload events (look like they are using some hook on that event). On the other hand, your ButtonDemo does detect the refresh on Facebook. So what's the difference?Any suggestions to how can I implement a robust solution are welcome :)Thanks,Shlomi Fruchter
-
Tuesday, September 01, 2009 6:48 AMHi Joseph,
U got any solution for IE8?
I am also trying to find out thw reason for absence of dropdown arrow in IE8.
After debugging found that subclassing function (subclass() from RebarHandler )gets called but onNotifyCustomDraw message handler is not getting invoked and hence button style is not getting set. -
Tuesday, October 20, 2009 1:01 PM
Can ButtonDemo work with IE8? The Demo button shows up on the IE8 command bar. However, there is no drop-down menu.
Unfortunately the example won't work with IE8 in its default state as it has a separate process for the controls to the BHOs, etc. In fact the default is to have a separate process for each tab (up to a limit)
Thanks.
to get this to work, you would need to hook into the IE8 "control" process and subclass, etc from there.. You then need to cross process call back to your bho, etc when the menu is selected. I have seen a working example, but it had problems. Also not sure how the vista /win7 UAC would stop you doing this as well..
If any one does implement it, please post, alternatively please hassle microsoft to change the way buttons work to add the option of dropdowns. It wouldn't be that hard to implement.. -
Tuesday, October 20, 2009 1:02 PMHi Shlomi, the only difference i can see is that i hook into the low level com events, whereas the calls you make work in the same way as the javascript event handlers, it is entirely possible facebook don't bubble the call onto your code...
-
Wednesday, October 21, 2009 10:02 AMHi John
Your piece of code worked like a charm in IE7 (and hope it should work on IE6 too).
But unfortunately its NOT working with IE8...
Issue 1# First the dropdown (small black down arrow) image does not come and only shows as a command button
Issue 2# When we close the browser tab/window, the browser CRASHES :( (Abort, Retry, Ignore)
I wonder is there anyway we can implement a drop-down toolbar button with different menu options which will work on IE6, IE7 and IE8.
Please share your comments and guide me further.
Thank you. -
Wednesday, October 21, 2009 11:05 AMIssue 1 - My code won't work in IE8 because I subclass the rebar control in the toolbar and intercept/modify the messages to add the drop down arrow. IE8 runs in "LCIE" mode see http://blogs.msdn.com/ie/archive/2008/03/11/ie8-and-loosely-coupled-ie-lcie.aspx for a description. Because of this it usually starts a separate process for the controls. Subclassing only works in the current process. You can use windows hooks to load your code into the main IE8 process and from there try and subclass the rebar control.
I've seen a sample of this working, but don't have the code, but it still had some minor issues. I haven't tried to attempt this due to lack of time, but it may be possible. Beware that UAC will cause problems as you'll need to hook into a higher level process, secondly IE8 has different LCIE modes which means that tabs may share a process so you'll have to detect and deal with that, etc along with multiple windows, etc...
Also note that the other samples that send messages to the rebar control, etc also fail because they can't cross the UAC boundary into the main process.
Issue 2 - This is a bug in my implementation, i make assumptions about how IE is structured internally which IE8 breaks. When you close a tab/window it tries to delete an object that has already been deleted/not created. look in the IEWindow class. Again this is because of the separate processes involved.
Feel free to modify the code and i'd be grateful if you could share it if you get it working.
Thanks

