Frage

Another application sometimes shows MessageBox with title "Test" and some message inside of MessageBox body, how can i from another application (writed on C++ or C# whatever) get this message and then close it? Code in C#:

[DllImport("user32.dll", SetLastError = true)]
public static extern IntPtr FindWindow(string lpClassName, string lpWindowName);
[DllImport("user32.dll")]
public static extern int SendMessage(int hWnd,uint Msg,int wParam,int lParam);
public const int WM_SYSCOMMAND = 0x0112;
public const int SC_CLOSE = 0xF060;

for (int i = 0; i < 40; i++) // just test cycle
{
     IntPtr window = FindWindow(null, "Test");
     if (window != IntPtr.Zero) // ok we found it!
     {
          // code that reads MessageBox message?
          .....
          // work is done, closing
          SendMessage((int)window, WM_SYSCOMMAND, SC_CLOSE, 0);
          break;
     }
     System.Threading.Thread.Sleep(50);
}

Can you help me with this problem? How can i do it?

War es hilfreich?

Lösung

Take a look into this thread.

Choice 1:

You can use an API like Spy++ to access other windows controls.

Choice 2:

you should use Windows APIs like EnumWindow or FindWindow then use EnumChildWindows API to find the controls in the target window, like the textbox you are looking for, then the API SetWindowText

have a look here for some ideas: Why is EnumChildWindows skipping children? also search for these APIs names here in Stack Overflow and you will find many examples...

Choice 3:

I found this api which may allow you to complete your task : http://www.programmersheaven.com/download/56171/download.aspx

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top