Click on a submenu item in windows - windows

all.
I'm trying to do the following, using standard windows menus. I have a menu with a sub menu attached to it. I need to perform different actions when user clicks the menu item that opens a submenu, and user hovers over the menu item and submenu opens without a click.
As far as I could see WM_MENUCOMMAND is only sent when user clicks on a menu item that does not have a submenu attached. Also no mouse click messages are sent when I actually click an item that contains submenu.
So is this even possible?
Thanks.

I believe you can tell when the mouse moves over an item by watching for WM_MENUSELECT. You would then have to start a timer, and if the timer expires before the cursor moves again, you'd have to manually pop open the submenu. I'm not sure how to accomplish the second part.
And it's pretty non-standard behavior that might confuse users. What are you trying to accomplish? And how do you expect it to work for users with only keyboard access?

Related

Programmatically obtaining a Windows application's tray menu items

I have an application with a tray menu and I'm trying to automate some tests that involve the tray menu. Basically I need obtain the tray menu's items and do stuff with them.
However, I've only been able to find ways to programmatically obtain menu items for within the application. But my automation tests are going to be an external application, so that doesn't help me.
How can I obtain an external application's tray menu items programmatically?
There are ways to enumerate/access the tray icons themselves (usually involving hooking into the notification tray itself, or using UI Automation), but there is no way to access a popup menu that appears when a tray icon is clicked on. The reason is because the icon's owning application receives a message when the click occurs and then acts accordingly, which usually involves displaying its own popup menu. There is no menu associated with the icon itself.
For what you are attempting, you would have to enumerate the icons and figure out which icon belongs to the app you are interested in (not a trivial task on its own), then simulate a click on the icon so the app displays its popup menu. See the following question for some details:
Finding and simulating a click on a system tray icon?
Interacting with the popup menu once it is displayed will be more difficult. You won't have access to the menu itself. You will likely have to resort to just issuing mouse events via mouse_event() or SendInput() to move the mouse cursor over the menu and click its items (assuming they appear in predictable locations relative to the icon).
If you can obtain the icon's HWND+ID or GUID (by hooking the notification tray itself), you can use Shell_NotifyIconGetRect() to get the icon's coordinates, at least.
How can I obtain an external application's tray menu items programmatically?
You cannot. There is no public API that provides access to notification icons.
Depending on what sort of assumptions you find acceptable, you can programmatically interact with the taskbar button's menu once it's visible. The image below shows the Inspect SDK tool reporting properties on the OneNote clipping tool button's menu. (And the menu items say they support the UIA Invoke Patten, so they should be programmatically invokable by UIA client code.)
If you want to invoke your tray button's menu items, you might consider the following steps using UIA. You may feel the assumptions that I make here are unacceptable for your situation.
Find the element with a class name "NotifyIconOverflowWindow", that's a direct child of the root menu. I'm assuming the button is in the overflow area.
Enumerate the children of the overflow element, looking for a button with the name of your button. This assumes the UI language is known and accounted for.
Get the bounding rect of the button and simulate a mouse right-click on the button. The click simulation is necessary because I'll bet the UI doesn't support IUIAutomationElement3::ShowContextMenu(), (but you could always try it).
Once the context menu's up, find the element with a ControlType a Menu, a Name of "Context", that's a direct child of the root element.
Once you have the menu, enumerate the child elements in the menu to find the items, and do what you want with them. Eg get the menu item's Invoke pattern and invoke it.

Swift - NSMenu closes when clicking outside of menu

so i have a simple NSMenu. It is attached to a Status Item Button.
When i click the Button it pops Open.
Now my Problem is that as soon as i click outside of the NSMenu, it closes. How can i avoid that ?
I did try many things but cant get that to work.
The reason i need that is that when the user clicks something in the NSMenu, another window opens, and while this window is open i also want the NSMenu to stay open. But it just does not work.
I feel like its impossible.
Many Thanks in advance.
I believe you have to create a custom view that pops up but something that could be done natively with just NSMenu.

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.

Rgui - disable right click on plot window?

I've written a routine whereby a user is displayed an image (using grid.raster) and they click on it to define a region of interest (grid.locator).
I added in support for the user to right-click on the plot instead of left-click, which would undo their previously-clicked point.
This works by testing whether grid.locator() returns NULL (from the help file: "If the user did not click mouse button 1, the function (invisibly) returns NULL).
This works fine on Linux, but in Windows using Rgui, right-clicking the plot window brings up a context menu with 'Stop' and 'Continue' and continues waiting for you to click (i.e. the right click is not detected by grid.locator() since it's intercepted for the context menu first).
Is there some way to disable the right click context menu for the plot window in Rgui?
(The user is only going to use Rgui. For the moment I can tell them to use the middle click button to undo instead of right click and this works, but it is moot if they don't have a button with a scroll wheel/middle click button. Alternatively if there's some way I can listen for a keyboard event without having to load a UI package like gtk or tcltk I'm happy for that to happen too).

How can I get to the menu bar in my app in interface builder

XCode works in mysterious ways (at least to me).
I simply want to create a Preference pane in my app. When I run my app, the stock menu bar comes up (Apple, MyApp, File, Edit...) and the "Preferences" menu item is grayed out. It makes sense since I haven't started playing with it.
How on earth do I add/remove/activate/inactivate menu items? I'm not talking about adding anything new, simply using what should be there.
Thanks in advance.
NSMenu has "Auto Enable Items" enabled by default. That means if the menu item does not have it's action message hooked up, it will appear grayed out. So in your case, you would simply set the Preferences menu item's "Sent Action" to whatever action shows your preferences window. This can be hooked to some sort of showPreferencesWindow: method of your AppDelegate, or directly to the showWindow: method of a window controller.
To dynamically enable/disable menu items the best way is to implement the NSUserInterfaceItemValidation protocol which is excellently documented here
Edit: Your app's menu bar items live in the MainMenu.xib file. The menu bar appears as a "Main Menu" object on the left hand side (if you're using Xcode 4) Simply click on the items to modify them, and you can Ctrl+drag connections to and from them like any UI object.

Resources