Destroy a window automacally - P/invoke...window handle??

teixeira

Regular
Joined
Apr 5, 2005
Messages
94
Location
LEIRIA-PORTUGAL
Hello,

I'm using a 3rd part DLL via Add reference i my C# project and sometimes the DLL generate a messagebox with an error and an OK button.

I would like to know if its possible to automatically and programatically do the "OK Click" or how to destroy this window.
This windows is not a separeated proccess so i cannot kill it using System.Diagnostics.Process any idea?? I heard about windows handle and maybe with p/invoke but i can see how can i do it.

Thanks in advance,
 
This is not super fun or easy to do, but possible. I can't release the code my company's developed, but it revolves around the API calls for SetWindowsHookEx, UnhookWindowsHookEx, CallNextHookEx and a few others to look for a window created with a class name of "#32770" - the magic value for a standard windows messagebox.

The idea is this:
1. Call SetWindowsHookEx - this takes a param for a delegate that will get called on certain hooked events.

2. In the delegate, check the message type looking for HCBT_CREATEWND (value = 3).

3. Get the class name of the created window - compare to the magic value above.

4. Make sure to call CallNextHookEx (another API)

5. At some point (I can't recall when and not obvious from the code) much later, probably sometime before shutting down your application, call UnhookWindowsHookEx.

-ner
 
Hi,

sure i understand that you can't expose the code.
I'm used to deal with apis but make a deeper search using the keywords you gave me to try to solve my problem.

Thanks a lot,
Teixeira
 
Back
Top