views:

321

answers:

1

Hi, I want to wait for and close a modal form (a popup) from another application, as soon as it appears. I want to do this from VB.NET, but suggestions in C# should be easily translateable.

I can hard-code the modal popup's caption in my app, since it's long and unique. What I want to do is simulate either the user clicking on the close ("X") button on the form, or a click on the defeault, tab-order 0 button of the form. Either would work.

Maybe I need more info about the modal popup other than the title bar's caption? In any case, it's safe to use it as an unique identifier of that modal form. I also want that code to terminate checking as soon as the first event of closing the popup happens.

I believe it's trivial, but I can't find any ready info on that. Microsoft says I should not send WM_CLOSE to the modal popup, since it will call DestroyWindow() instead of EndDialog(), but to be honest I don't even know what "sending WM_CLOSE" to the "window" means =/

Thanks for sharing a bit of guru-ness! :D

P.S.: This may be trivial in AutoHotkey. I feel lame not knowing it, I know I need it.

+1  A: 
IntPtr handle = FindWindow(null, "Dialog_Title");
SendMessage(handle, WM_NCDESTROY, 0, 0);

This should close the dialog

Nick Brooks
WM_NCDESTROY = 0x0082
Nick Brooks
Uh... just to understand it better; does "destroy" mean it will close the whole application? And, your comment means I can use 0x0082 instead of WM_NCDESTROY, or that I ***should*** use it?
Camilo Martin
Also, how can I check the window exists? (returning a boolean on that) Thanks!
Camilo Martin
0x0082 is the value of the constant WM_NCDESTROY. And no , it won't close the window , just the dialog. If FindWindow returns 0 then it doesnt exist.
Nick Brooks
Thanks! Choosen.
Camilo Martin