Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / .NET Framework / Interop / February 2008

Tip: Looking for answers? Try searching our database.

Browser Helper Object (BHO) in C#.

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
GoldTree@nospam.nospam - 29 Feb 2008 00:41 GMT
Hello All!

In the project I need to use Browser Helper Object (BHO) technology to
customize the ContextMenu events in the IE.

I have successfully written all the necessary logic to implement
IObjectWithSite and other required interfaces.

How to attach to Browser Helper Object (BHO) with C# in two minutes
http://www.codeproject.com/KB/cs/Attach_BHO_with_C_.aspx

I was wondering what to do next to load and customize (in C#) the standard
context menu and capture the event as suggested in article: "Adding Entries
to the Standard Context Menu"
http://msdn2.microsoft.com/en-us/library/aa753589.aspx

Thanks all in advance,

GoldTree
Steven Cheng - 29 Feb 2008 07:35 GMT
Hi GoldTree,

regarding on IE BHO and context menu customization, here is a forum thread
also mentions some suggestion:

#BHO & context menu customization
http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=1159435&SiteID=1

Also, I've performed some further research, here is some other information
found so far:

========================
For all IE versions up to IE6.0, the best we can do is replace the context
menu by sinking document events, cancellling the oncontextmenu event and
drawing our own context menu. The CreateMenu(), Append/InsertMenuItem() and
TrackPopupMenu() Win32 API calls are required to do this from C++.

One can override the context menu and display a custom one by implementing
IDocHostUIHandler interface in the host application. One problem is that
even if you build the same menu as IE's, there are no CMDID's to invoke
default implementation of IE for all of those commands using
IOleCommandTarget.

1. With IE 4.x one can subclass IE's window(one customer did this in
IDocHostUIHandler::OnContextMenu) and watch for the WM_INITPOPUPMENU
message and wait for the WM_COMMAND message sent when the user selects a
menu item. But with IE 5 onwards, IE calls TrackPopupMenu, gets the command
ID of the item selected and invokes the appropriate functionality using
IOleCommandTarget without generating a WM_COMMAND message. So developers
can no longer rely on this technique from IE 5 onwards.

2. On some occasions, developers may be doing this to prevent the user from
invoking certain menu items (eg: View Source) In this case, it's easier to
disable the menu item. Subclass the webbrowser control window, watch for
WM_INITPOPUPMENU. You will get the HMenu from this which you can
use to go disable/grey out items using the EnableMenuItem or
SetMenuItemInfo methods. Remember to return 0 after processing this message.

* Note that there is still no way to prevent script on the page from
invoking the same commands.
* For menu items that have accelerator keys, you can watch for these
keystrokes in IDocHostUIHandler::TranslateAccelerator.

Some customers tried to watch for WM_MENUSELECT messages and figure out the
last one moused over to determine which was selected. Since there are a lot
of scenarios that will need to be taken care of eg: user dismiised the menu
by clicking outside the context menu, pressed escape or selected using
mouse or keyboard, strongly advise them against using this technique

===========================================

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead



==================================================

Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
ications.



Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscriptions/support/default.aspx.

==================================================
   

This posting is provided "AS IS" with no warranties, and confers no rights.

--------------------
>From: <GoldTree@nospam.nospam>
>Subject: Browser Helper Object (BHO) in C#.
[quoted text clipped - 19 lines]
>
>GoldTree

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.