C# WinAPI 单击菜单项

时间:2022-10-27
本文介绍了C# WinAPI 单击菜单项的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

问题描述

我试图点击名为 Media Subtitler 的程序中的菜单项,但无论我尝试做什么,它都不起作用.

I'm trying to click on a menu item inside a program called Media Subtitler and whatever I'm trying to do it's not working.

首先,我尝试使用函数 GetMenu 但它返回 IntPtr.Zero.然后,我尝试使用 ALT 键 + 使用菜单的第一个字母(F 代表文件),但它什么也没做.然后,我尝试使用简单的 MOUSEDOWN 和 MOUSEUP 消息,但同样,它什么也没做(我还尝试创建一个循环,点击该范围内的所有内容,但没有点击该区域).

First, I tried to use the function GetMenu but it returned IntPtr.Zero. Then, I tried using the ALT key + using the first letter of my menu (F stands for file) but it did nothing. Then, I tried using a simple MOUSEDOWN and MOUSEUP messages but again, it did nothing (I also tried creating a loop that clicks on everything in that range but there was no click in that area).

我清楚地知道我在正确的窗口上工作.

What I clearly know is that I'm working on the correct window.

我做错了什么?

如果有人想测试一下,您可以免费下载 Media Subtitler,它的重量并不大.

If someone wants to test it out you can download Media Subtitler for free and it doesn't weight that much.

另外,这是我一直在测试的代码:

Also, Here's the code I've been testing:

Process p = Process.Start(@"C:Program FilesDivXLandMedia SubtitlerMediaSub.exe");
        p.WaitForInputIdle(1500);
        Thread.Sleep(3000);

        SetForegroundWindow(p.MainWindowHandle);
        ShowWindow(p.MainWindowHandle, SW_MAXIMIZE);

        IntPtr handle = p.MainWindowHandle;

        SendMessage(handle, WM_NCHITTEST, 0, MakeLParam(18, 29));

        //for (int i = 0; i < 200; i++)
        //{
        //    for (int x = 0; x < 200; x++)
        //    {
        //        SendMessage(p.MainWindowHandle, WM_LBUTTONDOWN, 0, MakeLParam(i, x));
        //        SendMessage(p.MainWindowHandle, WM_LBUTTONUP, 0, MakeLParam(i, x));
        //    }
        /