C# BrowserControl Woes ... Again!!

H

Harsha Ramesh

Hi All,

I have gone through the various postings all over the web and this group and still cant find a solution to my problem. May be because I do not understand C++ / COM programming properly. Please help me out here.

..NET 3.5 / VS 2008 / Outlook 2007 / VSTO Add-in
-----------------------------------------------

I have setup a menu item in Outlook. On clicking on the menu item, I launcha new WebBrowserControl embedded inside Outlook and hide the "messages" window. The following code snippet shows how I am embedding the control. I believe something is either not right, or I am just looking at the wrong places .. Additionally, I am not sure how the TranslateMessage / DispatchMessage needs to be invoked on the control.


Code:
Outlook.Explorer explorerWnd; // Handle to the Outlook explorer window
IntPtr olMainWndHnd; // This is the handle to the main window that contains the messages window
IntPtr olMsgWndHnd; // This is the handle to the messages window in outlook
 
// FindOutlookMessagesWindow
String caption = explorerWnd.GetType().InvokeMember("Caption", System.Reflection.BindingFlags.GetProperty, null, explorerWnd, null).ToString();
 
olMainWndHnd = User32.FindWindow(OUTLOOK_WINDOW_CLASS, caption);
if (olMainWndHnd != IntPtr.Zero)
{
olMsgWndHnd = User32.FindWindowEx(olMainWndHnd, IntPtr.Zero, OUTLOOK_WINDOW_CLASS, null);
}
 
// create a subclassed window for managing outlook resize events.
SubclassedWindow mSubClassedWindow = new SubclassedWindow();
mSubClassedWindow.AssignHandle(olMsgWndHnd);
mSubClassedWindow.SizeChanged += new EventHandler(SubClassedWindowSizeChanged);
 
// Create a new instance of the webbrowser control. This is a user control that just embeds a WebBrowser within it.
WebbrowserControl mEmbeddedContainer = new WebbrowserControl();
 
// Set the parent of the webbrowser to be outlook window.
// I am not sure if this needs to be done or not.
User32.SetParent(mEmbeddedContainer.Handle, olMainWndHnd);


Now based on what I have been reading, I understand that I can setup a keyboard hook (also coded in .NET). I have done that and I am able to trap the keyboard events of interest.

Here is where things are bouncing off my head. Everyone talks about TranslateMessage & DispatchMessage .. I understand that these are methods defined in some COM Interface. But how do I associate them with the browser control?

Secondly, when I trap the keyevents, I have the keycode with me. How do I pass this information across to the browser (everyone talks about passing a message, but I am not sure on how to construct this message object).

Really looking forward to your expert guidance.

Thanks,
Harsha
 
H

Harsha Ramesh

Forgot to add this one point too.

Everytime I need to show the control, I just toggle the visibility of the WebbrowserControl.
 
H

Harsha Ramesh

Ok .. I pieced together a solution based on the information available in this group. Now my .NET component works very well, thank you :)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top