Empty SubMenu names

Class library usage, coding and language questions.
mweilbacher
Posts: 3
Joined: Fri Jan 19, 2007 6:19 am

Empty SubMenu names

Post by mweilbacher » Fri Jan 19, 2007 8:18 am

I can get to the menu bar without a problem, but I can't see any names of the menu in the sub menus.

If I use the DumpElementTree technique, all the submenus are there, but they don't have their names either. The menu bar is bases on wtWidgets, but it just wrappers the interface of Win API.

I can't test with RanorexSpy because I can't bring up the submenus and use the drag feature at the same time. Maybe, adding an "always on" feature in Spy would be helpful to help debug this.

Any advice?

admin
Site Admin
Site Admin
Posts: 350
Joined: Wed Jul 05, 2006 7:44 pm

Post by admin » Mon Jan 22, 2007 12:39 am

There are a lot of menu implementations from Microsoft and from other companies. Ranorex also has more possibilities to access menu items, please give us the following information:

Is your application a .NET2003, .NET2005 or an older application?
Has your menu bar a control name?
Which Ranorex menu functions do you use?

Can you send us a small sample application with the same menu bar?

Jenö Herget
Ranorex Team

mweilbacher
Posts: 3
Joined: Fri Jan 19, 2007 6:19 am

Post by mweilbacher » Mon Jan 22, 2007 12:54 am

The applicaition is Visual 2003, but uses WxWidgets. http://www.wxwidgets.org

What I want to do is:

Code: Select all

     ret = RxMenuSelectItemText (form, "View","Fullscreen");

The code below is just me iterating seeing that the name of the menu is not valid.

Code: Select all

#include "stdafx.h"
#include "RanorexCore.h"

void DumpElementTree(ElementStruct* pElement, int level, HMENU menu=NULL)
{
	level++;
	if (level < 6)
	{
		if (pElement->Role == ROLE_SYSTEM_MENUITEM || pElement->Role == ROLE_SYSTEM_MENUPOPUP ||
			pElement->Role == ROLE_SYSTEM_MENUBAR || pElement->Role == ROLE_SYSTEM_WINDOW)
		{
			if (pElement->Role == ROLE_SYSTEM_MENUBAR )
			{
				menu = GetMenu(pElement->hWnd);
			}
			int childCount = RxElementGetChildCount(pElement);
			for(int index=0;index<childCount;index++)
			{
				int childId=0;
				ElementStruct child;
				HMENU subMenu;
				BOOL ret=RxElementGetChild(pElement, index, &child);
				if( ret == TRUE )
				{
					if (child.Role == ROLE_SYSTEM_MENUITEM || child.Role == ROLE_SYSTEM_MENUPOPUP ||
						child.Role == ROLE_SYSTEM_MENUBAR)
					{
						printf("%d",level);
						for(int j=0;j<level;j++)
							printf("   ");

						char szText[256];
						 	
						
						UINT ID = ::GetMenuItemID(menu,index);
						::GetMenuString(menu,index,szText,255,MF_BYPOSITION);
					 	
					 
						printf("Index=%d Name=%s Role=%d Value=%s ID=%d %s\n",
							index,child.Name,child.Role,RxElementGetValue(&child),ID,szText);

					
						if (ID == 20061)
						{
							RxElementDoDefaultAction(&child);
						}
						subMenu = GetSubMenu(menu,index);
						if (level == 3)
						{
							subMenu = menu;
						}
						DumpElementTree(&child,level,subMenu); 
				 
					}
				}
			}
		}
	}
}

int _tmain(int argc, _TCHAR* argv[])
{

	if (argc < 2)
	{
		printf("ERROR: Need executable name");
		return 0;
	}
	printf("-------------------------------------\n");
	printf(" Starting application...             \n");
	printf("-------------------------------------\n");
	 
	// Starting testapplication
	int ret = RxApplicationStart(argv[1]);
	if ( ret != 0 )
	{
		printf(" ERROR: Cannot start application %s\n",argv[1]);
		exit(1);
	}
 
	HWND form = RxFormFindTitle("Ed", MATCH_SUBSTRING , TRUE, 90000);	
	// Finding form by class name and activate it (timeout=3000 msec)
 	if ( form == 0 )
	{
 		printf(" ERROR: Application not found\n");
 		exit(1);
	}


	printf("Selecting menu items\n");


	ElementStruct elBrowser;
	if (RxControlGetElement (form, &elBrowser)) 
	{
		DumpElementTree(&elBrowser, 0);
	}

    int i;
    int k;
 	int m1;
	int iID;
	int iState;
	char *szName;
	i = RxMenuGetItemCount(form,0);
	for (int j=1;j<=i;j++)
	{
		szName = RxMenuGetItemText(form,j);
		iID =    RxMenuGetItemId (form,j);
		iState =    RxMenuGetItemState  (form,j);
		printf("%d\tNAME: %s\t%d\t%d\n",j, szName, iID, iState);
		k = RxMenuGetItemCount(form,j);
		for (int l=1;l<=k;l++)
		{
			szName = RxMenuGetItemText(form,j,l);
			iID =    RxMenuGetItemId (form,j,l);
			iState =    RxMenuGetItemState  (form,j,l);
			printf("\t%d\tNAME: %s\t%d\t%d\n",l,szName, iID, iState);
		
			m1 = RxMenuGetItemCount(form,j,l);
			for (int m2=1;m2<=m1;m2++)
			{
				szName = RxMenuGetItemText(form,j,l,m2);
				iID =    RxMenuGetItemId (form,j,l,m2);
				iState =    RxMenuGetItemState  (form,j,l,m2);
				printf("\t\t%d\tNAME: %s\t%d\t%d\n",m2,szName, iID, iState);
			}
		}
	}
	ret = RxMenuSelectPosition (form,1,2,-1);
	char* str = RxMenuGetItemText(form,3,2);
  	ret = RxMenuSelectItemText (form, "View","Fullscreen");	
 
	RxFormClose(form);
	return 0;
}

admin
Site Admin
Site Admin
Posts: 350
Joined: Wed Jul 05, 2006 7:44 pm

Post by admin » Mon Jan 22, 2007 9:36 pm

The following code clicks the menu item "Widget" -> "Set background... Ctrl-B" in the Widgets Demo application.

Code: Select all

RxMenuSelectItemText(form, "&Widget", "Set &background...\tCtrl-B");
You should use the "&" and "\t" chars if your menu item has keyboard shortcuts.

Please try and response your results.

Gabor Herget
Ranorex Team

mweilbacher
Posts: 3
Joined: Fri Jan 19, 2007 6:19 am

The & does not work

Post by mweilbacher » Mon Jan 22, 2007 10:44 pm

Adding the & does not work.

The text for the menu is actually blank when I use the iteration process sample above.

Is there anyway to specific a position to go to instead of my name? It know the item is there with the correct ID. Just no text.

admin
Site Admin
Site Admin
Posts: 350
Joined: Wed Jul 05, 2006 7:44 pm

Post by admin » Mon Jan 22, 2007 11:05 pm

mweilbacher wrote:The text for the menu is actually blank when I use the iteration process sample above.
We used your sample code with the Widgets Demo application and we got the text for all menu items.
We tried both the functions RxMenuSelectItemText() and RxMenuSelectItemPosition() .
mweilbacher wrote:Is there anyway to specific a position to go to instead of my name?
Yes, RxMenuSelectItemPosition()

Which Ranorex version do you use?
Can you try the Widgets Demo app from www.wxwidgets.org please.

Jenö Herget
Ranorex Team