У меня есть программа, которая отправляет информацию в фоновом режиме с помощью Outlook. Я хочу, чтобы пользователь не имел дело с сообщением «Исходящие не пусто», которое появляется, когда пользователь пытается закрыть Outlook, когда электронное письмо находится в папке «Исходящие». потому что в большинстве случаев электронная почта в папке «Исходящие» не будет электронной почтой, которую они отправили сами. Я могу получить дескриптор диалогового окна, но я не знаю, какую команду отправить, чтобы закрыть его. Единственная известная мне команда закрытия не будет работать для диалогового окна.
Я должен использовать Outlook для отправки электронной почты из-за ограничений безопасности.
Я получил код из здесь, который показывает, как перехватывать события окна и отсортируйте окно, которое вы хотите. Я нашел окно, и оно помогло мне остановить потоки, которые могли отправлять электронную почту, но диалоговое окно все еще висит там, когда я закончу.
Следующий код выполняется всякий раз, когда окно проводника деактивируется (т. е. теряет фокус).
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);
}
}
}
Команда WinApiProvider.SC_CLOSE не будет работать для этого типа окна.
Любые предложения будут оценены.