Jump to content
Xtreme .Net Talk

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


Recommended Posts

Posted

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,

  • *Experts*
Posted

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

"I want to stand as close to the edge as I can without going over. Out on the edge you see all the kinds of things you can't see from the center." - Kurt Vonnegut
Posted

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

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...