简体   繁体   English

如何使用 windows API 和 c# 操作右键单击上下文菜单

[英]how to manipulate right click context menu using windows API and c#

i have work on an app that manipulate some application context menue to extend its functions, i have checked all the common posts here on stackOverFlow on how to manipulate the menu context using Windows api in C# using functions like GetMenu(...) , InsertMenuItem(...) , ShowOwnedPopups(...) and that comes in vain, here is the scenario, the application i wanna manipulate it context menu has many context menus in many parts but i want to manipulate certain one which belongs to the viewer part.我在一个应用程序上工作,该应用程序可以操纵某些应用程序上下文菜单以扩展其功能,我已经检查了 stackOverFlow 上所有关于如何使用 Windows api 中的 C# 使用GetMenu(...)InsertMenuItem(...)等函数来操纵菜单上下文的常见帖子InsertMenuItem(...) , ShowOwnedPopups(...)并且是徒劳的,这是场景,我想操作它的应用程序上下文菜单在许多部分有很多上下文菜单,但我想操作属于查看器的某些上下文菜单部分。 so i have used spy++ to figure the the handle of the viewer and a send a message WM_CONTEXTMENU using SendMessage(...) function. the menu finally appears and i have its handle.所以我使用 spy++ 来确定查看器的句柄,并使用SendMessage(...) function 发送一条消息WM_CONTEXTMENU 。菜单终于出现了,我有了它的句柄。

发送消息后获取句柄

i guess after i get the handle it would be constant for the life time of the program for the single running time, but i figured out that the handle is changing every single time ai have clicked right click.我想在我得到句柄后,它在程序的整个生命周期内对于单次运行时间都是不变的,但我发现句柄每次都在改变我点击右键。 and the parent of the context menu isn't the viewer area itself but the desktop that's was disappointing.上下文菜单的父级不是查看器区域本身,而是令人失望的桌面。

句柄正在改变,上下文的父级是桌面窗口本身

so i have two problems所以我有两个问题

1- i can't get the handle directly as using GetMenu(...) passing the handle of the viewer returns null, after some search if found that the context menu has a class name of "#32768" so i have filtered all the open windows to get the one that its class name equlas "#32768". 1-我无法直接获取句柄,因为使用GetMenu(...)传递查看器的句柄返回 null,如果发现上下文菜单的 class 名称为“#32768”,那么我已经过滤了所有打开 windows 得到它的 class 名称等于“#32768”的那个。 and now i can access the handle from my c# code not from the spy.现在我可以从我的 c# 代码而不是间谍访问句柄。 but here is an comming issue: if there is a sub menue.. it also have the same class and unfortunately this is totally logical:/但这是一个即将到来的问题:如果有一个子菜单..它也有相同的 class 不幸的是这是完全合乎逻辑的:/

父母和孩子有相同的班级名称

2- i can't get the context handle before it is shown and if it is shown, i can't manipulate it as i know. 2-我无法在显示之前获取上下文句柄,如果显示,我将无法据我所知对其进行操作。 The second thing is that the context handle continuously changes every single time i right click the mouse.第二件事是,每次我右键单击鼠标时,上下文句柄都会不断变化。 so i can't pass the first time i click then save the handle for the next clicks to make it work.所以我不能在第一次点击时通过,然后保存下一次点击的句柄以使其工作。

any suggestion are very welcomed.任何建议都非常受欢迎。

First of all you should figure out if you can just send it a WM_COMMAND message to perform your command.首先,您应该弄清楚是否可以向它发送WM_COMMAND消息来执行您的命令。 A context menu might not use that message but if the application also has a normal menu then it is likely that it will handle the message.上下文菜单可能不会使用该消息,但如果应用程序也有一个普通菜单,那么它很可能会处理该消息。 Note that the command id might change between program versions.请注意,命令 ID 可能会在程序版本之间发生变化。

All Win32 HMENU menus use the same class and MN_GETHMENU is the only related documented message.所有 Win32 HMENU 菜单都使用相同的 class 并且MN_GETHMENU是唯一相关的记录消息。

The recommended solution is to use UI Automation/MSAA to navigate the UI of other applications.推荐的解决方案是使用UI Automation/MSAA来导航其他应用程序的 UI。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何使用 C# 禁用 Windows 中文本框的右键单击上下文菜单? - How to disable the right-click context menu on textboxes in Windows, using C#? 使用C#为所有桌面快捷方式创建自定义右键单击上下文菜单项(Windows资源管理器) - Create custom right-click context menu item with C# for all desktop shortcuts (windows explorer) c#wpf在Windows的右键单击上下文菜单中设置链接 - c# wpf set link in the right-click context menu of windows 无法右键单击上下文菜单条 c# - Can't right-click a context menu strip c# C#-在上下文菜单之前触发“右键单击”事件 - C# - Trigger “right click” event before context menu 在C#中的列表框项中添加右键单击/上下文菜单 - Adding a right click / context menu to listbox items in C# ChromiumWebBrowser禁用右键单击上下文菜单C# - ChromiumWebBrowser Disable Right-Click Context Menu C# 如何使用 PowerShell 禁用 Windows 表单标题栏上的右键单击上下文菜单 - How to disable the right click context menu on the title bar of a Windows Form using PowerShell 在Windows C#中的进程中调用右键单击菜单 - Invoke right-click menu in a process in windows c# 如何使用上下文菜单将文件导入我的应用程序(单击鼠标右键) - how to import a file to my application using the context menu (right Click)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM