VSTO Outlook: Avoid closing custom task pane - outlook

I have a custom task pane and now I am trying to catch the close event of the custom task pane. I have seen that there is no such event, instead there is the VisibleChanged event with does exactly the same, it is raised when visibility changes or it is closed.
When user clicks on close button or select close from the context menu, I would like to display a messagebox saying it is not permitted to close it and not allow user to close it.
I have seen an approach here or this user a thread but this is causing flickering when showing it again (you can see that it is hidden and then make visible again quickly). Is there any other way to achieve this? Also where is the best place in those approaches to show the messagebox?

Custom task panes don't provide any event which is fired when the pane is about to close. There is no trivial way to get the job done, you need to implement workarounds described on forum threads. Also you may consider using Advanced Outlook view and form regions instead.
Note, Outlook form regions provide the following events out of the box:
Event
Description
FormRegionInitializing
Occurs before the form region is initialized. You can check conditions in this event handler to determine whether Outlook should display the form region. For more information, see How to: Prevent Outlook from displaying a form region.
FormRegionShowing
Occurs after an instance of the form region is created but before the form region appears.
FormRegionClosed
Occurs before the form region is closed.

Related

How to prevent mouse click event on Windows

I record the mouse events on windows by using robotgo package. Package provides to get bitmap of clicked area but the latency of having bitmap is super sensitive situation here.
For example:
If I click any checkbox which is unchecked on the screen, provided bitmap must contains the state of unchecked but it provides me checked state and cannot simulate it with robotgo or cannot trigger click by using bitmap.
Solution to this scenario is that I need to prevent windows mouse click event until bitmap provided by the package (or adding some delay for click event) then trigger the click event on windows.
I made some research online but couldn't find a proper solution. How prevent click event on Windows in Go? Is it possible or is there any other way to make it happen?
A low-level mouse hook can eat mouse events. SendInput can generate mouse input events.
You would have to set a flag somewhere so you don't eat your own fake input events.
Keep in mind that SendInput is not perfect (can be detected by other hooks) and playing with the input system like this is usually not the best solution. Adding 500ms (or some other delay) to every mouse click is going to be very annoying for your users.
It is better to use UI Automation to get information about UI element states in other applications...

Delphi - How to programmatically make a modal dialog react like an event similar clicking on the background form

In our application, a modal dialog is shown that the user needs to confirm/close before other interaction is possible/allowed. This dialog is a self-implemented form, so can be adjusted to our needs.
An external event (in our case: a scan from a manual barcode scanner) provides input for the application. When the dialog is in front of the application, I would like to inform the user the scan/input is not processed. An idea is to simulate the behaviour that happens when clicking the form in the background of the modal dialog. By default, Windows then lets the dialog borders 'flash' and a sound is heard ('bonk' sound as described here: Delphi - How do you generate an event when a user clicks outside modal dialog?).
My question is:
Is it possible to programmatically simulate that behaviour, in order
to let user know the dialog has to be closed first?
Additional question: is this proper UI handling or should the dialog itself display an additional info text (e.g. as a footer text) instead of just 'flash'. I like to avoid displaying another modal dialog on top of the first one; to me that not seem best practice as well.
Thank you for any feedback/solution.
Use the FlashWindow or FlashWindowEx functions to achieve this.

Controlling the "Open in ..." button in the Quick Look (preview) panel

The QLPreviewPanel window has a button that will allow the user to open the quick look document they are currently previewing by launching its original application.
Is it possible to (a) disable this button for some documents and (b) learn if the user has clicked that button.
My problem is that some of the QLPreviewItem objects I'm passing to QLPreviewPanel are actually placeholders that aren't intended to be opened, while others are temporary documents that get created spontaneously.
In the later case, I normally delete these when the preview is done, but obviously I don't want to do this if the user has opened them in an application.
I've looked at the API for QLPreviewItem, QLPreviewPanel, and QLPreviewPanelDelegate and don't see any notifications or messages that occur when the user opens an item.
If there's no API, I might just try to hack the UI by searching the QLPreviewPanel for an NSButton and hooking its action, but I don't like hacks and I'm sure this would be a fragile one.

CustomTaskPane Visibility in Outlook

I have a custom TaskPane in Outlook. When the user toggles the visibility, I record it in the settings object so that the next time Outlook starts it will be shown/hidden as the user left it.
CustomTaskPane.VisibleChanged is raised in each of the following scenarios
The user clicks the X in the top right corner of the task pane
TaskPane.Visible is set in response to the user pressing a toggle button in the ribbon
The user presses the File menu button on the top left
The first two ways, the user clearly meant to hide the task pane. The third way the user was just trying to go to the menu screen (perhaps on their way to hit the Exit button).
Question
Is there anyway to determine that the event was raised because of the File Menu? Any way to programatically determine if the File Menu is currently open?
Here's what I mean by the File Menu Screen:
The Backstage UI provides two callbacks that can be used for tracking when the File menu is open and closed:
onShow - The Backstage view is displayed which triggers the OnShow callback procedure.
onHide - when the Backstage view is not longer visible.
The onShow attribute and the onHide attribute of the element can point to code that performs that kind of action.
<backstage onShow="OnShow">
See Customizing the Office 2010 Backstage View for Developers for more information.

Enable interaction with NSWindow when sheet is opened

I'm creating an app that calls a sheet, however, the interaction with the window must stay enabled while the sheet is open. Here's a mock-up:
The user must be able to use the play and record buttons. Does anyone knows a way to keep it enabled?
This seems a slightly questionable UI. But if you really want to do it, think the only solution will be to either:
Subclass NSWindow to force handling of the events
Run the event loop for that window while the sheet is visible, and dispatch desired events yourself
Sheets are intentionally designed to block interaction with the window they're attached to. If you don't want that behavior, you shouldn't be using a sheet.

Resources