VB如何操作其它应用程序的菜单?
目的:窗体中的Command按一下,模拟点击记事本的文件->打开 按钮。
用FindWindow,GetMenu,GetSubMenu后,再如何操作?
用SendMessage发送什么消息?
问题点数:0、回复次数:6Top
1 楼kingcom_xu(冷羽)回复于 2003-02-02 02:03:35 得分 0
获得菜单项的ID,并发送wm_commandTop
2 楼mjcom(不明飞行物)回复于 2003-02-02 10:43:53 得分 0
好啊,又多了像我一样爱管“闲事”的朋友,这个好办,我也正在进一步
研究呢。为了简单起见,只模拟一次按键事件,具体方法如下:
1。用FindWindow函数找到句柄
2。用FindWindowEx找到按钮句柄,或用GetMenu和GetSubMenu得到菜单项句柄
3。正如你所说的,用SendMessage像这个菜单项发送消息就可以了,
SendMessage 句柄,WM_COMMAND,WM_CLICKED,0
Top
3 楼supergoalcn(Supergoal)回复于 2003-02-02 11:24:25 得分 0
那又如何得到菜单的ID呢,Spy++没用。
菜单项的句柄也得不到,Spy++得不到,用GetSubMenu得到的是零。Top
4 楼feihong0233(泓)回复于 2003-02-02 17:11:40 得分 0
模拟打开吗?
自己弹出一个标准打开对话框,
然后NOTEPAD.EXE+文件名Top
5 楼supergoalcn(Supergoal)回复于 2003-02-02 19:33:44 得分 0
当然不行,记事本是我随便说的。
我是要知道具体的操作。Top
6 楼zyl910(编程的乐趣在于编程控制硬件,与用图形学实现绚丽效果)回复于 2003-02-04 11:31:56 得分 0
以windows98作为分界线
以前的一般用WM_COMMAND
以后的一般用WM_MENUCOMMAND
WM_COMMAND
The WM_COMMAND message is sent when the user selects a command item from a menu, when a control sends a notification message to its parent window, or when an accelerator keystroke is translated.
WM_COMMAND
wNotifyCode = HIWORD(wParam); // notification code
wID = LOWORD(wParam); // item, control, or accelerator identifier
hwndCtl = (HWND) lParam; // handle of control
Parameters
wNotifyCode
Value of the high-order word of wParam. Specifies the notification code if the message is from a control. If the message is from an accelerator, this parameter is 1. If the message is from a menu, this parameter is 0.
wID
Value of the low-order word of wParam. Specifies the identifier of the menu item, control, or accelerator.
hwndCtl
Value of lParam. Handle to the control sending the message if the message is from a control. Otherwise, this parameter is NULL.
Return Values
If an application processes this message, it should return zero.
Remarks
Accelerator keystrokes that select items from the window menu are translated into WM_SYSCOMMAND messages.
If an accelerator keystroke occurs that corresponds to a menu item when the window that owns the menu is minimized, no WM_COMMAND message is sent. However, if an accelerator keystroke occurs that does not match any of the items in the window's menu or in the window menu, a WM_COMMAND message is sent, even if the window is minimized.
If an application enables a menu separator, the system sends a WM_COMMAND message with the low-word of the wParam parameter set to zero when the user selects the separator.
QuickInfo
Windows NT: Requires version 3.1 or later.
Windows: Requires Windows 95 or later.
Windows CE: Requires version 1.0 or later.
Header: Declared in winuser.h.
WM_MENUCOMMAND Notification
--------------------------------------------------------------------------------
The WM_MENUCOMMAND message is sent when the user makes a selection from a menu.
Syntax
WM_MENUCOMMAND
WPARAM wParam
LPARAM lParam;
Parameters
wParam
Specifies the zero-based index of the item selected.
Windows 98/Me: The high word is the zero-based index of the item selected. The low word is the item ID.
lParam
Handle to the menu for the item selected.
Return Value
No return value.
Remarks
The WM_MENUCOMMAND message gives you a handle to the menu—so you can access the menu data in the MENUINFO structure—and also gives you the index of the selected item, which is typically what applications need. In contrast, the WM_COMMAND message gives you the menu item identifier.
The WM_MENUCOMMAND message is sent only for menus that are defined with the MNS_NOTIFYBYPOS flag set in the dwStyle member of the MENUINFO structure.
Notification Requirements
Minimum DLL Version None
Header Declared in Winuser.h, include Windows.h
Minimum operating systems Included in Windows 98, Windows 2000
Top




