0

我已经为此苦苦挣扎了很长一段时间,但无法得到任何我能理解的答案。我是 C# 的新手。

所以我正在启动一个应用程序(具体来说是 Accpac)然后我需要通过 sendkeys/sendmessage 将用户名发送到子窗口。我有子窗口的句柄,但我无法让它工作:IntPtr.(00020380),我收到错误“预期标识符”

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
    using System.Runtime.InteropServices; 
    using System.Diagnostics; 
    using System.Windows.Forms; 
    using System.Threading; 
    
    namespace myNamespace
    {
        class StartAccpac
        {
            [DllImport("user32.dll", SetLastError = true)]
            static extern IntPtr FindWindow(string lpClassName, string lpWindowName);
    
            [DllImport("user32.dll", SetLastError = true)]
            static extern IntPtr FindWindowEx(IntPtr hwndParent, IntPtr hwndChildAfter, string lpszClass, string lpszWindow);
    
            public static void Main3()
            {  
                //START ACCPAC
                //Process.Start("C:\\Programs\\Accpac\\runtime\\accpac.exe");
                IntPtr hwnd = IntPtr.Zero;
                IntPtr hwndChild = IntPtr.Zero;
    
                //Get a MAIN HANDLE
                hwnd = FindWindow(null, "Open Company");
                hwndChild = FindWindowEx(hwnd, IntPtr.(00020380), null, null); <---- ERROR
            }
            
        }
    }

在此处输入图像描述 在此处输入图像描述 在此处输入图像描述

4

1 回答 1

1

你的问题在这里:

IntPtr.(00020380)

你需要做的是这样的:

new IntPtr(00020380)

但是我怀疑,是八位数字并查看您的屏幕截图,这是一个十六进制数字,因此您可能还需要考虑:

new IntPtr(0x00020380)

和他们一起玩,看看会发生什么。

于 2017-01-05T11:05:17.980 回答