I have a program that sends information in the background using Outlook. I want to avoid having the user deal with the "Outbox is not empty" message that appears when a user tries to close Outlook when an email is in the outbox. because in most cases the email in the outbox will not be an email they sent themselves. I am able to get a handle to the dialog, but I don't know which command to send to make it close. The only close command I know about will not work for a dialog box.
I must use Outlook to send the email due to security constraints.
I got the code from here which shows you how to trap the window events and sort through the window you want. I have found the window, and it helped me to stop the threads that might be sending email, but the dialog is still hanging there when I'm done.
The following code executes whenever an Explorer window is deactivated (i.e. loses focus)
void ExplorerWrapper_Deactivate()
{
IntPtr hBuiltInDialog = WinApiProvider.FindWindow("#32770", "Microsoft Office Outlook");
if (hBuiltInDialog != IntPtr.Zero)
{
// ok, found one
// let's see what childwindows are there
List<IntPtr> childWindows = WinApiProvider.EnumChildWindows(hBuiltInDialog);
// Let's get a list of captions for the child windows
List<string> childWindowNames = WinApiProvider.GetWindowNames(childWindows);
// now check some criteria to identify the build in dialog..
// here are the three child window names as cut and pasted from the code when debugging
// [0] = "There are unsent messages in your Outbox. To send messages, Outlook must remain running and connected to your e-mail server. Do you want to exit anyway?\r\n\r\nExiting in <0d> seconds"
// [1] = "Exit Without Sending"
// [2] = "Don't Exit"
if ((childWindowNames.Contains("There are unsent messages in your Outbox. To send messages, Outlook must remain running and connected to your e-mail server. Do you want to exit anyway?\r\n\r\nExiting in <0d> seconds")) &&
(childWindowNames.Contains("Exit Without Sending")) &&
(childWindowNames.Contains("Don't Exit")))
{
// at this point, we need to empty the outbox of any IkeNet email, and if the outbox is then empty, close the dialog
// and let outlook close as well
NotifyAdmin.SetShutdownRequested();
/// this close command does not seem to work for this window. supposedly it acts just like pressing
/// the <esc> key, which does nothing to the window when the program is running.
WinApiProvider.SendMessage(hBuiltInDialog,
WinApiProvider.WM_SYSCOMMAND, WinApiProvider.SC_CLOSE, 0);
}
}
}
The WinApiProvider.SC_CLOSE command will not work for this kind of window.
Any suggestions will be appreciated.