Codejock Forums Homepage
Forum Home Forum Home > Codejock Products > Visual C++ MFC > Toolkit Pro
  New Posts New Posts RSS Feed - MSAA and application menu
  FAQ FAQ  Forum Search   Events   Register Register  Login Login

MSAA and application menu

 Post Reply Post Reply
Author
Message
yngvedh View Drop Down
Newbie
Newbie
Avatar

Joined: 17 January 2012
Status: Offline
Points: 2
Post Options Post Options   Thanks (0) Thanks(0)   Quote yngvedh Quote  Post ReplyReply Direct Link To This Post Topic: MSAA and application menu
    Posted: 17 January 2012 at 7:04am
Hi,

Reading your support guidelines, I'm not sure whether this is a forum question or a support question. I guess the answer to this helps more people than just me.

Now, to business. We're using MicroSoft Active Accessibility to automate our UI tests. But We're having a hard time identifying menu items. Ideally, I want to identify menu items by their command ID. Trouble is, the command ID is not available from the CXTPMenuBar we're currently using. We could use the name of the menu item, but that makes it more difficult to test localized versions. (we ship 13 languages)

Here's what I got out of the MSAA Inspector tool with our application and a newly created Visual Studio MFC template application (with visual studio style toolbars):

XTreme toolkit menu:
- ChildID = 0
- Most properties return NOT_IMPLEMENTED

New MFC Template Application menu:
- ChildID = Command ID
- All properties return valid values

Is there anything I have to do to enable MSAA? If not, how can I best solve this problem?

Best regards,

Yngve D. Hammersland
Back to Top
grahamf View Drop Down
Groupie
Groupie
Avatar

Joined: 29 October 2009
Location: United States
Status: Offline
Points: 13
Post Options Post Options   Thanks (0) Thanks(0)   Quote grahamf Quote  Post ReplyReply Direct Link To This Post Posted: 17 January 2012 at 1:48pm
We had a similar issue, coming from Stingray Toolkit (which had its own menu peculiarities), however, we use MicroFocus SilkTest, so I cannot be more specific for MSAA. I will describe what I found and did, instead of trying to match that with what you have.

In a nutshell, as far as I can figure out, CodeJock only uses the initial menu load to create a menu bar (CXTPMenuBar) that contain lists of controls. After loading, no menu resource (a la Microsoft menu HMENU) are used, and the menu bar/controls are used for drawing the menus.

To workaround this, we have a dynamically loaded SilkTest extension DLL that is loaded by the application (if not there, no QA so no error). This DLL exposes a function called by SilkTest to initiate a menu. The menu to select is specified by a text string, like:

/File/Do Foo

or

/File/[cmdid]

or

/File/{idx}

where [cmdid] is the command id, and {idx} is the index within the menu.

We then get the CodeJock menu bar controls:
GetCommandBars()->GetMenuBar()->GetControls()

and traverse the controls. At this point, we dump out a key sequence which is used to select the menu (why this is so I explain below). In your case, since it is multi-lingual, you cannot use "/File/Do Foo", but more likely just "[cmdid]". This will need to locate the control in the menu bar controls via FindControl(). I suggest you then go back through the parent control(s) to be able to determine the full key sequence which is used to select the menu.

The reason for using the key sequence is so that the menu will actually display (vs just firing off a PostMessage() with the command id), so that command UI updates and control drawing is performed. It also gives the QA person doing the scripting a chance to see what their script and their menu selection is doing (SilkTest allows you to set the keystroke delay).

What you wind up with is this key sequence (for above example):
<Alt><Down><Down><Down><Enter>

Another like "/Edit/Do Bar" might be:
<Alt><Right><Down><Down><Down><Enter>

which will select the menu. Now for the secret sauce with this - the way the CodeJock menu bar activates is rather weird, and although this key sequence would work if you type it, being sent via send keys does not work. What I found was it was necessary to position the mouse over the first menu bar entry, otherwise the sequence would not work correctly (positioning done by SilkTest TypeKeys function). Code snippet:

    CWnd*            pMainWnd;

    CXTPMenuBar*    pMenuBar;

    CXTPControl*    pControlMenu;

    BString            strKeys;

    RECT            rect;

    POINT            point;

    // retrieve the main window
    pMainWnd = CWnd::FromHandle(hWnd);

    // retrieve the menu bar for the window
    pMenuBar = ((CXTPMDIFrameWnd*)pMainWnd)->GetCommandBars()->GetMenuBar();

    // get the first control
    pControlMenu = pMenuBar->GetControls()->GetAt(0);

    // get the control's bounding rectangle
    rect = pControlMenu->GetRect();

    // set the click point to middle
    point.x = (rect.left + rect.right) / 2;
    point.y = (rect.top + rect.bottom) / 2;

    // convert to window ccordinates
    ::ClientToScreen(pMenuBar->m_hWnd, &point);
    ::ScreenToClient(hWnd, &point);

    // prepend the menu accessor and append the menu select
    strKeys  = KEY_ACCESSMENU;// = <Alt>
    strKeys += pszKeys;
    strKeys += KEY_SELECTMENU;// = <Enter>

    // and pick it
    QAP_TypeKeys(hWnd, (LPTSTR)strKeys.c_str(), &point, EVT_SETFOCUS);

I hope that helps.

Back to Top
yngvedh View Drop Down
Newbie
Newbie
Avatar

Joined: 17 January 2012
Status: Offline
Points: 2
Post Options Post Options   Thanks (0) Thanks(0)   Quote yngvedh Quote  Post ReplyReply Direct Link To This Post Posted: 20 January 2012 at 8:29am
Hi, thanks for the answer, but it is not quite what I'm looking for.
I just want the menu to act as a native menu, even if I have to manually implement it myself.
Back to Top
grahamf View Drop Down
Groupie
Groupie
Avatar

Joined: 29 October 2009
Location: United States
Status: Offline
Points: 13
Post Options Post Options   Thanks (0) Thanks(0)   Quote grahamf Quote  Post ReplyReply Direct Link To This Post Posted: 20 January 2012 at 11:53am
If you want the menu to act as a 'native' menu (HMENU based, and possibly wrapped by CMenu), you will not be able to use the CodeJock command bar/menu bar since they do not use HMENU except when they initially load the menu resource.

Other CodeJock folks chime in to correct me, though I went through this pretty closely Wink

Back to Top
pawesol View Drop Down
Newbie
Newbie


Joined: 08 April 2014
Status: Offline
Points: 1
Post Options Post Options   Thanks (0) Thanks(0)   Quote pawesol Quote  Post ReplyReply Direct Link To This Post Posted: 08 April 2014 at 5:49am
Hi,

I have the same problem as Yngve. I am using TestComplete. Any explanation why ID is not returned and how to work around it?

/Pawel
Back to Top
 Post Reply Post Reply
  Share Topic   

Forum Jump Forum Permissions View Drop Down

Forum Software by Web Wiz Forums® version 12.04
Copyright ©2001-2021 Web Wiz Ltd.

This page was generated in 0.191 seconds.