This project is read-only.

How to get at the Start Menu?

Sep 1, 2010 at 1:14 PM

I'm trying to access items in the Start Menu.  So far I've been able to open it, but even that is slightly non-obvious.  In other windows I can say something like window.Get<Button>("Button Name") to get a reference to the button, but for the taskbar I have to say Desktop.Instance.Get<Button>(SearchCriteria.ByText("Button Name")) instead, merely giving the string will not find the button.  Why is this?

Then, how do I find the items in the Start Menu?  I have tried with Desktop.Instance.Get<Window>(SearchCriteria.ByText("Start Menu")), but that does not seem to be able to find it.  Is it even a window?


Sep 2, 2010 at 10:36 AM

Yes, I got the Start Menu as a Panel.  And from there I could get at the "All Programs" button, but even though I get a reference to the button and can confirm it has the right name, neither focussing nor clicking on it seems to do anything, the Start Menu just closes instead of popping up the programs menu.  Any ideas?

Sep 3, 2010 at 4:40 PM

OK, I finally got it to work, by figuring out that there actually isn't a cascading menu with items you can click, there are a set of panes being opened by the mouse hovering over the menu items.  Furthermore, after the first window expansion, processing becomes amazingly slow.  I would really appreciate some help and hints.  This is the code I came up with (yeah, I know it could be cleaned up, but as a first try):

           Desktop desktop = Desktop.Instance;
            // For some reason it's not sufficient to just give a string argument to Get below, it has to be a search criterion

            Panel startMenu = desktop.Get<Panel>(SearchCriteria.ByText("Start Menu"));
            Button b = startMenu.Get<Button>(SearchCriteria.ByText("All Programs"));
            Mouse.Instance.Location = b.ClickablePoint;
            Point p = b.ClickablePoint;
            p.Offset(startMenu.Bounds.Width * 0.6, 0);
            Mouse.Instance.Location = p;

            Panel sm = desktop.Get<Panel>(SearchCriteria.ByAutomationId("StartMenu"));
            Menu menu = sm.Get<Menu>(SearchCriteria.ByText("Accessories"));
            Mouse.Instance.Location = menu.ClickablePoint;
            p = menu.ClickablePoint;
            p.Offset(sm.Bounds.Width * 0.6, 0);
            Mouse.Instance.Location = p;

            // From here on, execution takes a minute or two per mouse movement
            Panel sm2 = desktop.Get<Panel>(SearchCriteria.ByAutomationId("StartMenu").AndIndex(1));
            Menu menu2 = sm2.Get<Menu>(SearchCriteria.ByText("Accessibility"));
            Mouse.Instance.Location = menu2.ClickablePoint;
            p = menu2.ClickablePoint;
            p.Offset(sm2.Bounds.Width * 0.6, 0);
            Mouse.Instance.Location = p;

            Panel sm3 = desktop.Get<Panel>(SearchCriteria.ByAutomationId("StartMenu").AndIndex(2));
            Menu menu3 = sm3.Get<Menu>(SearchCriteria.ByText("Magnifier"));
            Mouse.Instance.Location = menu3.ClickablePoint;