Deltoid

I have created an Outlook add on which performs actions when the ItemSend mail event occurs.

I have a confirm dialog box that pops up.

1) If the e-mail message is open on my secondary monitor the messagebox will display on monitor 1.
2) If the e-mail message is open on my primary monitor the messagebox will be displayed BEHIND the message window.

I suspect the problem is that I need to pass the MessageBox the parent window to be displayed in. Just I don't know how to go about doing that. At the moment all I have is:

MessageBox.Show("Hello World");

Thanks.


Re: Visual Studio Tools for Office Outlook Addon - MessageBox not displaying in the current active window.

Mike Morton - MSFT

Did you get this working If not, what version of Visual Studion, VSTO and Outlook are you using

Mike





Re: Visual Studio Tools for Office Outlook Addon - MessageBox not displaying in the current active window.

Deltoid

Hi Mike,

I didn't get this working.

I'm using Visual Studio 2005 (8.0.50727.42) and whatever version of VSTO came with that. As for Office I'm using Office 2003 SP2.

Any help would be appreciated. I suspect the problem is that I'm just doing MessageBox.Show('test'); which would be launching using the addon as the parent object. Whereas really it should be using the email the user currently has open as the parent object.

On the topic of this. My program searches an email for a particular word. I only want it to search the current email (so if a user is forwarding / replying to an email I don't want it to check the original message) do you know an easy way to know what part is the body of the current email and what part is the original message

Thanks






Re: Visual Studio Tools for Office Outlook Addon - MessageBox not displaying in the current active window.

John R. Durant - MSFT

Deltoid,

I recall this question being posed before. Sue's Outlook Code site has a post on this:

http://www.outlookcode.com/codedetail.aspx id=1428

Best,

jrd






Re: Visual Studio Tools for Office Outlook Addon - MessageBox not displaying in the current active window.

Deltoid

Thanks guys. That looks like what I am after. I kind of knew why the problem was happening just didn't have a clue at how to fix it.

I will take a look at that code next week and post back with if it works.

How about the question regarding knowing what is the original message and what is the current message in a reply Do you know a way to do that or should I post up a new thread about it




Re: Visual Studio Tools for Office Outlook Addon - MessageBox not displaying in the current active window.

Deltoid

Hi,

I tried out the code and still not having any luck. My application is in C# so I converted the code to that. Does the code below look about right I call this code from my Outlook Addon saying

Outlook.MailItem mail = (Outlook.MailItem)Item;
MessageBox.Show(MessageBox.Show(new OutlookWin32Window(mail.Application.ActiveWindow()),"test");

class OutlookWin32Window : System.Windows.Forms.IWin32Window
{
private IntPtr _windowsHandle;

[DllImport("user32.dll", SetLastError = true, CharSet = CharSet.Auto)]
private static extern IntPtr FindWindow(string lpClassName, string lpWindowName);

public IntPtr Handle
{
get
{
return _windowsHandle;
}
}

public OutlookWin32Window(Object window)
{
string caption;
caption = window.GetType().InvokeMember("Caption", System.Reflection.BindingFlags.GetProperty, null, window, null).ToString();
_windowsHandle = FindWindow("rctrl_renwnd32", caption);
}
}

My code basically will check the email for a keyword and if it exists popup a message box. Just the message box is always hidden at the moment.

Thanks





Re: Visual Studio Tools for Office Outlook Addon - MessageBox not displaying in the current active window.

Deltoid

anyone able to help




Re: Visual Studio Tools for Office Outlook Addon - MessageBox not displaying in the current active window.

Deltoid

I'm still stuck with this.

I believe the problem is with my call of MessageBox.Show.

At the moment I use this code:
OutlookWin32Window parentWindow = new OutlookWin32Window(this.ActiveInspector());
MessageBox.Show(parentWindow,"Test");

This doesn't work. If I do a simple MessageBox.Show(this.ActiveInspector().Caption); it displays the caption for the mail item.

I'm not sure how to fix this problem.




Re: Visual Studio Tools for Office Outlook Addon - MessageBox not displaying in the current active window.

Deltoid

I got it working. I had to change the OutlookWin32Window classes constructor though.

Application main method:
OutlookWin32Window parentWindow = new OutlookWin32Window(this.ActiveInspector().Caption);

MessageBox.Show(parentWindow,"test");


OutlookWin32WindowClass:
class OutlookWin32Window : System.Windows.Forms.IWin32Window
{
[DllImport("user32")]
private static extern IntPtr FindWindow(string lpClassName, string lpWindowName);

private IntPtr _windowsHandle = IntPtr.Zero;

public IntPtr Handle
{
get
{
return _windowsHandle;
}
}

public OutlookWin32Window(string caption)
{
_windowsHandle = FindWindow(null, caption);
}
}