PC Review


Reply
Thread Tools Rate Thread

C# BrowserControl Woes ... Again!!

 
 
Harsha Ramesh
Guest
Posts: n/a
 
      19th Oct 2011
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
 
Reply With Quote
 
 
 
 
Harsha Ramesh
Guest
Posts: n/a
 
      19th Oct 2011
Forgot to add this one point too.

Everytime I need to show the control, I just toggle the visibility of the WebbrowserControl.
 
Reply With Quote
 
Harsha Ramesh
Guest
Posts: n/a
 
      24th Oct 2011
Ok .. I pieced together a solution based on the information available in this group. Now my .NET component works very well, thank you
 
Reply With Quote
 
Harsha Ramesh
Guest
Posts: n/a
 
      16th Nov 2011
Sure thing. Will do .. Give me a few days and I shall publish the solution.
 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off



Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 10:25 AM.