J'ai un programme qui envoie des informations en arrière-plan en utilisant Outlook. Je souhaite éviter que l'utilisateur traite le message "Boîte d'envoi n'est pas vide" qui s'affiche lorsqu'un utilisateur tente de fermer Outlook lorsqu'un e-mail est dans la boîte d'envoi. car dans la plupart des cas, l'e-mail dans la boîte d'envoi ne sera pas un e-mail qu'ils ont eux-mêmes envoyé. Je suis capable de gérer la boîte de dialogue, mais je ne sais pas quelle commande envoyer pour la fermer. La seule commande de fermeture que je connais ne fonctionnera pas pour une boîte de dialogue.C# fermer Outlook Le dialogue "Boîte d'envoi n'est pas vide" par programme
Je dois utiliser Outlook pour envoyer l'e-mail en raison de contraintes de sécurité.
J'ai obtenu le code de here qui vous montre comment piéger les événements de fenêtre et trier à travers la fenêtre que vous voulez. J'ai trouvé la fenêtre, et cela m'a aidé à arrêter les threads qui pourraient envoyer des emails, mais la boîte de dialogue est toujours là quand j'ai terminé.
Le code suivant exécute chaque fois qu'une fenêtre Explorer est désactivé (ce désélectionné)
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);
}
}
}
La commande WinApiProvider.SC_CLOSE ne fonctionnera pas pour ce genre de fenêtre.
Toutes les suggestions seront appréciées.