捕获WindowClass#32770

时间:2013-12-23 07:56:34

标签: c#

我是C#的新手,我在服务器中捕获任何Windows对话框时遇到了一些问题。我需要知道来自Windows对话框的消息(标题和标题),以便我可以写入我的应用程序日志。

我知道我必须找到#32770类窗口,但我不知道如何使用enumwindows。在delphi 7中,代码应该使用一些函数,如:

  • EnumWindows的
  • EnumProcess
  • Enumchildwindows
  • Enumchildwindowsproc
  • Getwindowthreadprocessid
  • GetClassName
  • GetWindowText函数

有没有解决方案?

1 个答案:

答案 0 :(得分:1)

您也可以在C#中使用Windows API。您可以找到使用here的大量信息和示例。 here是有关DllImport属性的信息。

您可以尝试以下内容:

class Program
{
    [DllImport("user32.dll", SetLastError = true)]
    public static extern IntPtr FindWindowEx(IntPtr parentHandle, IntPtr childAfter, string className, string windowTitle);

    static void Main(string[] args)
    {
        var handle = IntPtr.Zero;
        do
        {
            handle = FindWindowEx(IntPtr.Zero, handle, "#32770", null);
            if (handle != IntPtr.Zero )
                Console.WriteLine("Found handle: {0:X}", handle.ToInt64());
        } while (handle != IntPtr.Zero);


        Console.ReadLine();
    }
}