2

I am new in C#, i've got some problem to capture any windows dialog show in my server. I need to know the message (caption and title) from windows dialog so i can write to my application log.

I know that i must find #32770 class windows, but i do not know how to enumwindows. In delphi 7, the code should use some functions like:

  • Enumwindows
  • EnumProcess
  • Enumchildwindows
  • Enumchildwindowsproc
  • Getwindowthreadprocessid
  • GetClassName
  • Getwindowtext

Is there any solution for this ?

Amal Murali
  • 75,622
  • 18
  • 128
  • 150
Mangs
  • 19
  • 1
  • 3
  • You'll see an example of findDialog in [this code](http://stackoverflow.com/questions/2576156/winforms-how-can-i-make-messagebox-appear-centered-on-mainform/2576220#2576220). Trying to tinker with other programs when you are just starting out learning how to program is a very common goal. Always a bad idea however, you have to learn *three* brand-new things. Keep the winapi and pinvoke on the shelf for a while until you've mastered C# first. – Hans Passant Dec 23 '13 at 08:56
  • @Hans Passant thanks you for your suggestions. C# likes a new jungle to me. Very different from pascal - delphi or vb classic. – Mangs Dec 24 '13 at 03:29

1 Answers1

3

You can use windows API in C# as well. You can find a lot information and examples of using here. And here is information about DllImport attribute.

You can try something like:

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();
    }
}
Tony
  • 7,345
  • 3
  • 26
  • 34
  • is this findwindowex will capture all window dialog ? (i.e. if i open task manager and Date and Time Properties, with findwindowex, i will get 2 #32770 class window. is that right ? – Mangs Dec 23 '13 at 08:31
  • @Mangs Yes, see my updated answer. It shows how to enum all such windows. – Tony Dec 23 '13 at 08:46
  • Thanks, with this code, i also get title and child's caption too. – Mangs Dec 24 '13 at 03:31