我有一个正在运行的旧Smalltalk应用程序,我想让我的c#程序访问其菜单并单击一个项目。该应用程序有4个子菜单,此时只能看到它调用任何一个都会很好。 我一直在圈子里搜索这个但是没有让它工作。在我的代码中点击一个菜单项我需要什么? 我看到提到SendMessage的一个例子,我看到另一个有PostMessage的例子? 到目前为止,我有...
I have an old Smalltalk application that is running and I want to have my c# program access its menu and click on an item. The app has 4 submenus and at this point just being able to see it call any one would be good. I have been going around in circles googling this but have not got it working. What do I need in my code to click on a menu item? One example I saw mentioned SendMessage and I see another with PostMessage? So far I have...
private const uint WM_COMMAND = 0x111; IntPtr theWindow = (IntPtr)0; theWindow = FindWindow((string)null, "My Smalltalk App"); IntPtr hMainMenu = GetMenu(theWindow); IntPtr hMenu = GetSubMenu(hMainMenu, 0); uint MenuID = GetMenuItemID(hMenu, 1); // for future use PostMessage(hMenu, WM_COMMAND, 2, 0); // Does not compile抱歉,我对Win API的使用经验不多,而且我正在努力获得一个概念验证工作。 有人可以给我一些可以点击的代码菜单项? 提前致谢, John。
Sorry but I have little experience of Win API usage and I am trying to get a proof of concept working. Could someone be kind enough to give me some code that would click a menu item? Thanks in advance, John.
推荐答案请参阅我对该问题的评论。到目前为止,我认为没有任何理由去做你正在做的事情。 但即使不了解你在做什么,也可以做一个有用的答案,因为这个与一个非常常见的误解相关:调用事件而不是仅处理事件的想法。 如果您使用纯.NET和.NET事件,则不会能够直接调用.NET FCL中定义的任何事件,因为除了声明事件成员的类型的方法的代码之外,.NET不允许从任何地方调用事件;这是一个重要的傻瓜式功能。 (当然,某些类型可以暴露一些显式的方法,例如使用WPF RaiseEvent ;将其视为某些类型实现的后门。)问题是:你不要真的需要它。 正确的方法很简单:通过说以编程方式点击一个菜单项你从来没有真正意味着点击。 (只有一个用户可以用鼠标点击某些东西;没有程序化点击,它只能是一些仿真。)你的意思是实现与点击相同的精确效果。如果您有这样的效果,则意味着您已将某个处理程序添加到某个事件实例的调用列表中。如果这样做,你可以调用一些函数,只有一个函数来自这个处理程序,并且这个函数可以单独声明。您所需要的只是在其他地方调用此功能。是的,就这么简单。
为了演示我得到了一个使用Sendkeys工作的解决方案。 For the sake of teh demo I got a solution working using Sendkeys. SendKeys.SendWait("%A"); SendKeys.SendWait("p");
%= ALT,所以ALT A会带我到一个子菜单,然后选择我需要的菜单。 我在那里仍然必须有一个更好的解决方案,但这个让我通过演示。 感谢大家的评论。
% = ALT, so ALT A would take me to a sub menu and p selects the menu that I needed. I beleive there still must be a better solution but this one got me through the demo. thanks to everyone for their comments.
更多推荐
以编程方式单击c#中的菜单项
发布评论