Send a Mail from Word für windows 2007 via MAPI

  • Thread starter Thread starter thomas
  • Start date Start date
T

thomas

HI,

i want to send a mail from winword 2007. when i klick
send as attachment the outlook dilog opens as a modal window.
ich want to close the dialog with a develop addin. but
the dialog don´t closed. the status ist a ghost window.

when i test the addin without mapi in outlook it runs
without problems.

my questions:
1) can i closed the ghost window?
2) can i open the mapisendmessage windows from winword a a non-modal window?

regards
Thomas Lauer
 
A Simple MAPI window (Send To) is always opened modally, you cannot change
that.

Calling Close() on that window as you've discovered will often lead to a
"ghost" Inspector that can only be closed from the UI.

To close that window completely you would need to get the hWnd of that
window using the Win32 API function FindWindow(), and then send or post a
message to that window using a WM_CLOSE Win32 API message.
 
Hi Ken,

thanks for your help.

i try to use the following code for close the ghost window:

uint WM_CLOSE = 0x0010;
whnd = WinApiProvider.FindWindow(null, wtxttw.ToString() );
Console.WriteLine("Handle: {0}", whnd);
WinApiProvider.SendMessage(whnd, WM_CLOSE, 0, 0);

The FindWindo find the ghost window i check the handle with spy++
but the sendmessage don´t close the ghost window.

regadrs
Thomas
 
Make sure that you are declaring "whnd" as IntPtr, and supply the final 2
arguments to SendMessage() as IntPtr.Zero. Also try using "rctrl_renwnd32"
as the window class name.

In addition, I have no idea if this would make any difference, but I usually
call PostMessage() rather than using SendMessage().

I declare PostMessage() this way:

[DllImport("user32", SetLastError = true)]

[return: MarshalAs(UnmanagedType.Bool)]

internal static extern bool PostMessage(IntPtr hWnd, uint wMsg, IntPtr
wParam, IntPtr lParam);

I put the call to PostMessage() in the Inspector.Close() event handler.
 
Back
Top