4
Answers

Close Messagebox from an external program

Kai Hung

Kai Hung

16y
11.9k
1

(What im trying to do)

Im creating a web test in vsts 2008, unfortunately, it cant record messagebox and when this pops up you have to manually click it for the test to continue running. This is what im trying to automate. forcibly close the messagebox (at least).

(What i've already done so far)

in one program/process i have been able to automate the closing of messagebox (take note, its only on one application).

To do this i implemented this method

private static void Setup(string caption, uint uTimeout)

{

//if (hHook != IntPtr.Zero)

// throw new NotSupportedException("multiple calls are not supported");

hookTimeout = uTimeout;

hookCaption = caption != null ? caption : "";

hHook = SetWindowsHookEx(WH_CALLWNDPROCRET, hookProc, IntPtr.Zero, AppDomain.GetCurrentThreadId());

}

 

Now this method is only good when your dealing with a controled environment. where you could modify the code of what your testing.

So what happens is when i call the method

Setup("myCaption", 1000);

MessageBox.Show("hello world", "myCaption");

the message box closes after 1000 miliseconds. but this is only the 1st step the real problem begins here.

hHook = SetWindowsHookEx(WH_CALLWNDPROCRET, hookProc, IntPtr.Zero, AppDomain.GetCurrentThreadId());

what should i pass to the parameter in order to detect proceses/threads outside the application? obviously it wont be GetCurrentThreadId();

(What im trying to achive...at the very least)

Create a listener (maybe a console app) run the .exe.

And everytime a messagebox shows up from any applications (e.g. internet explorer, windows forms), ill be able to close using the setup("myCaption",1000);

 

Any ideas are greatly appreciated...

Answers (4)