如何获得主菜单的处理程序 [英] How to get the handler of main menu
本文介绍了如何获得主菜单的处理程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在编写自动化测试,但是我对如何获取主菜单的处理程序感到困惑,虽然我觉得下面的代码是正确的,我无法得到正确的值。
I am writing automated test, but I get confused about how to get the handler of main menu, although I feel the following code is correct, I can not get the correct value.
[DllImport("user32.dll")]
static extern IntPtr GetMenu(IntPtr hWnd);
[DllImport("user32.dll")]
static extern IntPtr GetSubMenu(IntPtr hMenu, int nPos);
[DllImport("user32.dll")]
static extern int GetMenuItemID(IntPtr hMenu, int nPos);
public void FormExitApp(int subMenu, int exitItem)
{
IntPtr pMenu = GetMenu(this.ptrToWindow); // pMenu = 0, ptrToWindow is a correct value.
IntPtr pSubMenu = GetSubMenu(pMenu, 0); // pSubMenu = 0, the handler of "File"
int menuID = GetMenuItemID(pSubMenu, 3); // menuID = -1, the ID of File --> Exit
uint WM_COMMAND = 0x0111;
SendMessage4(this.ptrToWindow, WM_COMMAND, menuID, null);
}
我使用VS2008,测试中的应用程序用C#编码。菜单结构为:
文件编辑帮助
新增
保存
打印
退出
I use VS2008, and the application under test is coded in C#. The menu structure is:
File Edit Help
New
Save
Print
Exit
推荐答案
因为上面的代码来自自动化测试,而不是来自被测试的应用程序,所以我不能使用menustrip.handle属性。似乎win32 API函数可以帮助我,但GetMenu和GetSubMenu函数不起作用。我感到很困惑。
Because the above code is from the automated test, not from the application under test, I can not use menustrip.handle property. It seems win32 API functions can help me, but the GetMenu and GetSubMenu functions don't work. I feel so confused.
这篇关于如何获得主菜单的处理程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文