VSTO Outlook 2010 Cancel Inspector Close - c#

I have seen other posts regarding Outlook 2007 stating that you can't cancel an inspector close event. Is this still true in Outlook 2010 or 2013? If it is possible, how do I do this?
Also, if I can't cancel the close, can I cancel the save?
I am not asking for any logic pertaining to a specific application. I just want to know if there is a line of code that I can pass a bool into or a property that I can set to false to cancel the close event/save event.
Edit: For some clarification, I want to cancel the contact page's close event.

MailItem.Close event passes the Cancel parameter which you can set to true.
To prevent an inspector from being closed, you can drop down to the Windows API level and override the Inspector's window proc. You can then intercept (and discard) WM_CLOSE and WM_SYSCOMMNAND Windows messages.

Related

How to get save confirmation dialog result of outlook

I don't know how to get result of save confirmation dialog of outlook (in C#).
This confirmation box is opened up by following:
Open mail in outlook
Made some changes in content
Close the mail
Please refer this image
I want to get this opened save confirm box and its result.
Thanks in advance.
Track the MailItem.Close / Write / AfterWrite events - Close will fire immediately before the prompt is shown, Write fires before the message is saved, AfterWrite immediately afterward.
There is no trivial way of getting such information. But you may track the sequence of events fired for the item and realize the answer following that way.
First, to handle item-level events you may develop a wrapper for an Outlook item like described in the Implement a wrapper for inspectors and track item-level events in each inspector article.
The MailItem.Close event is fired when the inspector associated with an item (which is an instance of the parent object) is being closed.
The MailItem.Write event is fired when an instance of the parent object is saved, either explicitly (for example, using the Save or SaveAs methods) or implicitly (for example, in response to a prompt when closing the item's inspector).
So, if you have got Close fired following by the Write event - that is your case!

Windows Phone 7 Dialog

How can I show a dialog message, similar to MessageBox, which have just the "Cancel" button and can be closed by the application.
The idea is to show the dialog while the application retrieves data from a server, allowing the user to cancel this request, and closing the dialog once the request is completed.
I recall having a very similar problem in the past. I don't think there is a dialog message "out of the box" that works like that. The way I solved this was by writing a class that modeled this sort of behavior in a window and having the application spawn an instance of the window.
The silverlight message box blocks code execution while it is open so it is not possible to close it. However you can use an XNA messagebox in Silverlight which is asynchronous
This explains its use in depth
You can probably then call EndShowMessageBox for your purposes.
if your intention is to let the user know that something is loading and that they should wait. you should use a progressbar instead.
How to: Create a Custom Indeterminate Progress Bar

Capture Modal Dialog object using MSHTML/IExplorer

I'm using C#, MSHTML and InternetExplorer objects to run through a webpage, but I'm snagged on an issue.
Basically, I've noticed that in IE7 or earlier, when window.showModalDialog is called, then the NewWindow3 event is triggered.
In IE8 and IE9, NewWindow3 is never triggered. As MSDN writes: "The NewWindow3 event is only fired when a new instance of Internet Explorer is about to be created. Calling showModalDialog or showModelessDialog does not trigger an event because they are not new instances of Internet Explorer. They are implemented as MSHTML host windows, which allows them to render and display HTML content but not hyperlinks between documents."
(http://msdn.microsoft.com/en-us/library/aa768337(v=VS.85).aspx)
The only way I've been able to come close to capturing the modal dialog being triggered - but I have no access to the actual modal object - is using the WindowStateChanged event. This event is routinely called, yet I've noticed that when dwFlags == 1 and dwValidFlagsMask==3, this is usually when the browser is deactivated due to a modal dialog...
Now, all I need to know is how to get that modal dialog object. Any help would be greatly appreciated
Turns out it all depends on your Windows UAC settings. For security reasons, when your UAC is set to medium or higher, UAC prevents access of modal dialogs. Lowering these settings allows full access to the modal dialog, through the NewWindow event

Can not create CommandBar when Outlook is run minimized (Outlook 2007 Add-In)

Original post:
When Outlook is launched, the Add-In is loaded and adds a toolbar with some buttons.
toolBar = OutlookApp.ActiveExplorer().CommandBars.Add(MENU_TAG, MsoBarPosition.msoBarTop, false, true);
Everything was working fine, but now one user has his Outlook shortcut set to launch Outlook minimized.
And then OutlookApp.ActiveExplorer() return null.
Is there some event I can use to catch when there is an ActiveExplorer and then add the commandbar?
OutlookApp.Explorers.NewExplorer doesn't work.
Also, when I show a messagebox before I add the CommandBar: everything works fine, even with Outlook minimized... Why?
edit:
Accessing the Explorers proprerty directly did work, as someone said in the answers. So this solves the problem for a minimized outlook... But...
One of the users does not have Outlook run minimized, and still the plugin loads before any gui is available. There are not even 1 explorer in the Explorers collection :( How is this possible?
edit 2:
I tried using a timer as suggested by 76mel, checking ActiveExplorer for null every 100ms. This adds the buttons as expected, but I can set the Picture property of the button.
I get this exception:
Catastrophic failure (Exception from HRESULT: 0x8000FFFF (E_UNEXPECTED))
If there is no UI = no explorer :(
Try waiting until the Explorers.NewExplorer event fires to be able to get a CommandBars object.
Update:
Yes it looks like a timer will do the trick ok a bit hacky.
So wire up a timer when you have a null ActiveExplorer and check for the ActiveExplorer onTick. Once the user pops outlook you get you active explorer and you can then add you tool bars.
I'm not familiar with managed addins, but I found this answer.
If there is no ActiveExplorer, try to access the Explorers collections directly, like in Explorers[1].
I had the same problem in my ECE and solved it by waiting for OnObjectChange callback that would be called when the user changes a folder in Outlook, and then I try to recreate the toolbar. This might roughly correspond to the FolderSwitch event in the Outlook object model.
Just my 2c.

Check if a drag&drop is in progress

Is there any way to check if a drag and drop is in progress? Some method or win32 api which can be checked? I know I can set AllowDrop and use events but it doesn't work in this case. Basically i want to check, with code, if any drag&drop is in progress.
I had a similar question which I answered myself (after some hours messing about) See - How do I tell if a Drag Drop has ended in Winforms?.
Basically if you do as earwicker suggests you need to set the flag when the drag drop begins near the DoDragDrop call. You will need to unset the flag in both the DragDrop event and in the QueryContinueDrag if the QueryContinueDragEventArgs indicate a drop or a cancel.
The GetCapture API function might be a good start. Basically, when a drag operation starts, the source window "captures" the mouse, which means that it will still receive all mouse events even if the mouse leaves the window.
However, applications can also capture the mouse for other reasons, so this is not 100% reliable. You can try it and see how well it works for you. And with applications doing their own drag&drop handling, there's no way to be sure what is going on anyway.
What about QueryContinueDrag event handler http://msdn.microsoft.com/en-us/library/system.windows.forms.control.querycontinuedrag.aspx ?
You can hook a handler to any control and check if there is a ongoing drag&drop operation and then cancel it if you want to.
Ooops, sorry, I just saw that the guy before me already mentioned that. Me bad.
Assuming it's in the context of just your own code, you could identify all the places in your code where a drag/drop happens, and set a global boolean flag to true for the duration of the operation, then back to false after it finishes.
So the next question is, how are drag/drop operations being started in your application?

Categories