I recently had to fix some old code that relied on a DLL that sometimes exposed an assert message. I tried all of the above suggestions, and the only thing I got was to click the "Ignore" button. The user above suggested running EnumWindows in a separate thread - instead, I used FindWindow.
This is a function that finds the Assert pop-up message, finds the Ignore button there, and then clicks on it. It goes through a loop that checks a global variable each time (ugly but fast):
void CloseAssertBox (void *param) { HWND window, button; Sleep (200); //wait 200 milliseconds while (!finishThread) { //see if we can stop checking if ((window = FindWindow (NULL, L"Microsoft Visual C++ Runtime Library")) && (button = FindWindowEx (window, NULL, L"Button", L"&Ignore"))) SendMessage (button, BM_CLICK, 0, 0); //click the button Sleep (50); //then check every 50 milliseconds } }
Your Assert field name may vary. If your Ignore button is specified differently, you can use EnumChildWindows to get the name of each child control, including the buttons.
Before the bit of code that assert pops up, I start a new thread that calls the function above.
finishThread = 0; //this is set to 1 when the thread should finish _beginthread (CloseAssertBox, 0, NULL); //begin the thread
After going through a dangerous code in doubt, I installed:
finishThread = 1; //done threaded stuff
Thus, the thread will close the next time around its cycle. There are probably better ways to do this.
I had to enable these libraries in order for them to work:
#include <process.h> //for multithreading
All this has been done in Visual Studio 2010 using the library since 2006.