VSTO Outlook: Opening Outlook from a mailto link does not create custom task pane - outlook

I have an VSTO Outlook Addin which shows always an Outlook custom task pane in all windows, explorers and inspectors. This is working perfectly, I mean, custom task pane is always show, except one particular use case, e.g. when you open outlook by clicking in a mailto link in a web page for example. In this case no explorer is open, instead only one knspector window is open, in this case the reply/compose window. So I need to handle when outlook is open through a mailto link and show my custom task pane in the reply/compose window, so which event do i need to handle? It looks like in this case i am not calling the logic to show my custom task pane when there are 0 explorers opened. I want to handle that event , check if numbers of explorers opened are 0 and then in this case show my ctp. Any help please?

If you are using Inspectors.NewInspector event, it won't fire for the mailto links. What you can do, is create a timer (use the Timer object from the Form namespace - it fires on the same thread) that checks the Application.Inspectors collection periodically and verifies that your task pane has been added to that inspector. You can create an Inspector wrapper class that handles Inspector.Close to remove itself from the parent list maintained by your code as well as contains a pointer to your task pane. When looping through the Outlook's inspectors collection, you can match OOM's Inspector object to your wrapper by comparing the HWND of an Inspector object to that stored by your wrapper. The window handle (HWND) can be retrieved using the IOleWindow interface - cast the Inspector object to IOleWindow and call IOleWindow.GetWindow

Related

Outlook Add in not properly initialised when called from "Send to" Windows contextual menu

I work on an Outlook 2016 add-in (C# visual studio 2017 on Windows 10).
The add-in do its job perfectly when a new message is created and then sent from the "Write new message" window launched from the Outlook main menu (or toolbar) : the add-in displays its own ribbon with some radiobuttons to configure the message to be sent and that's all.
But when a new message window is created from the Windows contextual menu "Send to" on a file (to be sent as an attachement), the add-in is ignored : the radio buttons, even if they trigger their respective callbacks and so configure the underlying model, let the new message unchanged :-(
The main difference observed under debugger is :
from the outlook menu : the "ThisAddIn" class seems to retrieve a wrapper for the new message window and so the configuration is taken into account when the message is sent :-)
from the Windows contextual menu : only a "GetCustomUI" callback is triggered and so the message is sent unchanged when the "Send" button is clicked :-(
Any help (examples, documentation, howto, ...) appreciated ...
JF
Not all event handlers are triggered when users try to send files using the context menu Send To.
If the GetCustomUI is triggered when a user sends files from a folder (using a context menu) you can add a custom ribbon UI with your radio buttons to configure the message to be sent. I suppose that is all what your add-in does.
You just need to use Ribbon XML to create a custom UI and use the GetCustomUI function to return it back. Read more about that in the Walkthrough: Create a custom tab by using Ribbon XML article.
In the ribbon event handlers you need to make sure you get access to the item through the Context passed as an argument. For example, the onAction callback has the following signature:
C#: void OnAction(IRibbonControl control)
VBA: Sub OnAction(control As IRibbonControl)
C++: HRESULT OnAction([in] IRibbonControl *pControl)
Visual Basic: Sub OnAction(control As IRibbonControl)
The IRibbonControl interface instance provides the Context property which represents the active window containing the Ribbon user interface that triggers a callback procedure. So, you may cast it to the Inspector or Explorer for retrieving the actual mail item you have to deal with.

OWA Addin code written gives a pane within the mail, but i need it to pop a window and display the webpage in default browser

FormSettings>
Form xsi:type="ItemRead">
DesktopSettings>
SourceLocation DefaultValue="https://www.google.com"/>
RequestedWidth>800/RequestedWidth>
RequestedHeight>800/RequestedHeight>
/DesktopSettings>
/Form>
/FormSettings>
what has to be used in order to get a pop up browser on clicking that hyperlink
If you also want the task pane to open, you can start with an add-in command that only executes a JavaScript function. See an overview and an example.
Then either call the displayDialogAsync API to open a window that can communicate with the add-in (the kind of window depends on the client), or call window.open to open an external web page in the default browser.
When the add-in's JavaScript has finished executing, remember to call event.completed() per the first example to stop the add-in.

UFT: Unable to identify Object's parent window though it is being added in Object Repository

I'm working on Calypso windows application where I have to click on a tab within a window. When I was executing the script, I see error message saying that "Cannot find the object's parent window" . I have verified that window properties don't change and no other window is opened with same title.
Please suggest how I can click the tab in the window.
call JavaWindow("Back Office Window for").Activate
JavaWindow("Back Office Window for").JavaTab("Pay Role").Select ("Postings")
THE Window Title is dynamic and keeps changing as shown below
Back Office Window for Trade 4562213 (User: polaris_bouser1)
Try
JavaWindow("title:=Back Office Window for Trade.*").Activate
If this helps, use the same statement in your object repository, using the button next to the property . check the regular expression checkbox.... use this link to quickly go through how to use regular expression youtube.com/watch?v=IdIBhl0p6Fo –

How to disable copy/paste commands in the Windows edit control context menu?

How can I disable those 3 standard cut/copy/paste commands in the context menu of the native Windows OS edit control?
I also need to disable the equivalent clipboard-related commands like CTRL+C/CTRL+V.
Is there a special edit control style or anything else we can use to disable all copy/paste operations with one easy setting?
Typically, when a control displays a popup menu, a WM_INITPOPUPMENU message is generated which "allows an application to modify the menu before it is displayed, without changing the entire menu."
Unfortunately, a standard Win32 Edit control does not generate that message for its default popup menu, as confirmed in a November 2000 article of MSDN Magazine (the link on MSDN itself is dead, but this link is from the Internet Archive):
MSDN Magazine, November 2000, C++ Q&A:
Q: Why isn't a WM_INITMENUPOPUP message generated when you right-click an edit control?
A: I can't tell you why there isn't one, but I can confirm it's true ... edit controls don't send WM_INITMENUPOPUP. The edit control must be calling TrackPopupMenu with a null HWND handle and/or TPM_NONOTIFY, which tells the menu not to send notifications. It's possible (and again I'm only guessing) that the authors were trying to improve performance by reducing message traffic ... In any case, suppose you want to add your own menu items to the edit control context menu. How do you do it? Alas, you have no choice but to reinvent the wheel
So the only option available is to subclass the edit control and handle the WM_CONTEXTMENU message instead, creating and displaying your own custom popup menu as needed. Which means you have to manually duplicate the functionality of any standard menu items that you want to appear in your custom menu.
Update: there is a way to access and modify the edit control's standard popup menu after all (I just tested it and it worked). TecMan provided a link to a VBForums discussion that talks about it, however it gets a few details wrong. I got the correct details from a PureBasic forum discussion.
The correct approach is as follows:
subclass the edit control to intercept the WM_CONTEXTMENU message. Either SetWindowSubClass() or SetWindowLongPtr(GWL_WNDPROC) can be used, though the first is preferred.
when the WM_CONTEXTMENU message is received, call SetWindowsHookEx() to install a thread-local hook (use 0 for the hMod parameter and GetCurrentThreadId() for the dwThreadId parameter). Either a WH_CBT or WH_CALLWNDPROC hook can be used. Then dispatch WM_CONTENTMENU to the default message handler via DefSubclassProc() or CallWindowProc() to invoke the standard popup menu.
inside the hook procedure, when a HCBT_CREATEWND (WH_CBT hook) or WM_CREATE (WH_CALLWNDPROC hook) notification is received, pass the provided HWND to GetClassName(). If the class name is #32768 (the standard window class name for menus, as documented on MSDN), post (very important!) a custom window message using PostMessage(), specifying the menu window's HWND in the message's WPARAM or LPARAM parameter, to any HWND that you control, such as your main window, or even the edit control itself (since it is already subclassed). You will need the menu's HWND in the next step. You can optionally now uninstall the hook at this time, or wait for DefSubclassProc()/CallWindowProc() to exit (it will exit after the menu has been dismissed). You need to use PostMessage() because the menu window has not created its HMENU yet at this time. PostMessage() delays the next step until after the HMENU is ready.
when the custom window message is received, send a MN_GETMENU message via SendMessage() to the menu's HWND that you obtained from the hook. You now have the menu's HMENU and can do whatever you want with it.
to disable the Cut, Copy, and Paste menu items, call EnableMenuItem(). Their menu item identifiers are the same values as the WM_CUT, WM_COPY and WM_PASTE messages, respectively (this is not documented by Microsoft, but is consistent across Windows versions).
Update: I just found a much simpler solution (which also worked when I tested it).
subclass the edit control to intercept WM_CONTEXTMENU, as described above.
when the message is received, call SetWinEventHook() to install a thread-local event hook (set the hmodWinEventProc parameter to 0, the idProcess parameter to GetCurrentProcessId(), the idThread parameter to GetCurrentThreadId(), and the dwFlags parameter to 0 - not WINEVENT_INCONTEXT!). Set the eventMin and eventMax parameters both to EVENT_SYSTEM_MENUPOPUPSTART so that it is the only event you receive. Then dispatch the message to the default handler to invoke the popup menu.
when your event callback is called, the menu has already been fully initialized, so you can send the MN_GETMENU message to the provided HWND, which will be the menu's window (the callback's idObject parameter will be OBJID_CLIENT and the idChild parameter will be 0).
manipulate the HMENU as needed.
unhook the event hook when done using it, as described above.
As you can see here, this does work.
Before modifying the menu:
After disabling the menu items:
Even deleting the menu items:
You could leave the options visible but lock the clipboard from usage.
If this solution suits you all you need to do is make a program that opens the clipboard by calling OpenClipboard(NULL). In order to release the clipboard call CloseClipboard().
One approach (similar to hypmir's idea but not quite as intrusive) is to simply overwrite the clipboard with "DATA REMOVED BY TecMan" whenever it is updated. You could do this as a registered clipboard viewer.
Open the clipboard, clear all formats, add CF_TEXT with the notice, close it.
I would use a short delay (maybe a timer callback) so that you make your update AFTER the first update has been processed by any other registered clipboard viewers on the system.
Your mileage may vary.
Abusing the clipboard like this is never a good idea.
I found one interesting idea of how to get the handle of the edit control's context menu on vbforums.com:
http://www.vbforums.com/showthread.php?776385-RESOLVED-Modify-right-click-context-menu-in-standard-controls
It demonstrates how to add custom context menu items to the standard OS context menu. I think, this idea can be used to modify the menu too. Theoretically I need to enumerate the menu items and disable the items related to the copy/paste commands. The question is how to know whether a menu item is related to copy/paste? Getting the menu item text is a bad idea ;)
Another problem of that code is that it is based on some Windows features that are not documented. I've checked the solution, it still works in Windows 10, but who knows how the edit control context menu may be changed in the future updates of the OS...

How do you display a dialog from a hidden window application?

I have developed a COM component (dll) that implements an Edit() method displaying a WTL modal dialog.
The complete interface to this COM component corresponds to a software standard used in the chemical process industry (CAPE-OPEN) and as a result this COM component is supposed to be usable by a range of 3rd party executables that are out of my control.
My component works as expected in many of these EXEs, but for one in particular the Edit() method just hangs without the dialog appearing.
However, if I make a call to ::MessageBox() immediately before DoModal() the dialog displays and behaves correctly after first showing the MessageBox.
I have a suspicion that the problem may be something to do with this particular EXE running as a 'hidden window application'.
I have tried using both NULL and the return value from ::GetConsoleWindow() as the dialog's parent, neither have worked.
The dialog itself is an ATL/WTL CPropertySheetImpl.
The parent application (EXE) in question is out of my control as it is developed by a (mildly hostile) 3rd party.
I do know that I can successfully call ::MessageBox() or display the standard Windows File Dialog from my COM component, and that after doing so I am then able to display my custom dialog. I'm just unable to display my custom dialog without first displaying a 'standard' dialog.
Can anyone suggest how I might get it to display the dialog without first showing an unnecessary MessageBox? I know it is possible because I've seen this EXE display the dialogs from other COM components corresponding to the same interface.
Are you using a parent for the Dialog? e.g.
MyDialog dialog(pParent);
dialog.DoModal();
If you are, try removing the parent. Especially if the parent is the desktop window.
Depending on how the "hidden window" application works, it might not be able to display a window. For example, services don't have a "main message loop", and thus are not able to process messages sent to windows in the process. i.e, the application displaying the window should have something like this:
while(GetMessage(&msg, NULL, 0, 0))
{
if(!TranslateAccelerator(msg.hwnd, hAccelTable, &msg))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
}
in WinMain.
This isn't supposed to be reliable - but try ::GetDesktopWindow() as the parent (it returns a HWND).
Be warned - if your app crashes, it will bring down the desktop with it. But i'd be interested to see if it works.
It turns out I was mistaken:
If I create my dialog with a NULL parent then it is not displayed, and hangs the parent application
However if I create my dialog with ::GetConsoleWindow() as the parent then the dialog is displayed; it just fooled me because it was displayed behind the window of the application that launched the parent application
So now I just have to find out how to bring my dialog to the front.
Thanks for the answers ;-)
Whatever you do, do not use the desktop window as the parent for your modal dialog box.
See here for explanation: http://blogs.msdn.com/b/oldnewthing/archive/2004/02/24/79212.aspx
To quote the rationale:
Put this together: If the owner of a
modal dialog is the desktop, then the
desktop becomes disabled, which
disables all of its descendants. In
other words, it disables every window
in the system. Even the one you're
trying to display!

Resources