Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

C# BrowserControl Woes ... Again!!

10 views
Skip to first unread message

Harsha Ramesh

unread,
Oct 19, 2011, 6:43:44 AM10/19/11
to
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 launch a 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);

[/code]


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

Harsha Ramesh

unread,
Oct 19, 2011, 6:47:20 AM10/19/11
to
Forgot to add this one point too.

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

Harsha Ramesh

unread,
Oct 24, 2011, 11:25:22 AM10/24/11
to
Ok .. I pieced together a solution based on the information available in this group. Now my .NET component works very well, thank you :)

DH

unread,
Nov 8, 2011, 4:18:13 AM11/8/11
to

Would you please share your solution?

Thanks,
DH

--

______________________________________
Posted from http://outlook-center.com
Outlook forums, articles, tips.

Harsha Ramesh

unread,
Nov 16, 2011, 3:32:05 AM11/16/11
to
Sure thing. Will do .. Give me a few days and I shall publish the solution.
0 new messages