在使用C#弹出的Windows文本框中输入数据

时间:2019-05-28 14:43:37

标签: c#

我必须在Windows弹出窗口的文本框中输入文件路径

我尝试了一段代码,可以根据其名称返回窗口的句柄。

class Program
{
    private const int WM_GETTEXT = 13;
    [DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = true)]
    public static extern IntPtr SendMessage(IntPtr hWnd, int msg, IntPtr wParam, IntPtr lParam);

    [DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = true)]
    private static extern IntPtr FindWindowEx(IntPtr parentHandle, IntPtr childAfter, string lclassName, string windowTitle);

    [DllImport("user32.dll")]
    static extern IntPtr FindWindow(string lpClassName, string lpWindowName);
    static void  Main(string[] args)
    {
        IntPtr Hwnd = FindWindow(null, "Choose File to Upload");
        // Alloc memory for the buffer that recieves the text
        IntPtr Handle = Marshal.AllocHGlobal(100);
        // send WM_GWTTEXT message to the notepad window
        int NumText = (int)SendMessage(Hwnd, WM_GETTEXT, (IntPtr)50, Handle);
        // copy the characters from the unmanaged memory to a managed string
        string Text = Marshal.PtrToStringUni(Handle);

    }

我的流行音乐如下: Windows pop up

我需要在窗口的文本框中设置数据。

0 个答案:

没有答案