LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

Intercepting a windows application message?

Hi,
 
I am trying to intercept an access violation message from a third party DLL.  The purpose is to intercept this message and programmatically post the OK message to destroy its popup window.  I am trying to get an example program running which traps for the WM_CLOSE message ID.  My callback is never processed when I hit a close button (X on the title bar).  Any ideas?
 
int main (int argc, char *argv[])
{
 if (InitCVIRTE (0, argv, 0) == 0)
  return -1; // out of memory
 if ((panelHandle = LoadPanel (0, "FindErrorMessage.uir", PANEL)) < 0)
  return -1;
 DisplayPanel (panelHandle);
 
 /* To intercept the WM_CLOSE message with MyCallback */
 status = InstallWinMsgCallback (panelHandle, WM_CLOSE, MyCallback, VAL_MODE_INTERCEPT, NULL, &postHandle);
 RunUserInterface ();
 
 DiscardPanel (panelHandle);
 /* Uninstall the event handler and free associated memory */

 RemoveWinMsgCallback (panelHandle, WM_CLOSE);
 
 return 0;
}

int CVICALLBACK MyCallback (int panelHandle, int message, unsigned int* wParam, unsigned int* lParam, void* callbackData) {
 //to do items here
 MessagePopup ("test 2","test 2");
return 0;
}
0 Kudos
Message 1 of 3
(3,607 Views)
Hello,

This thread might have some useful information for you:
http://forums.ni.com/ni/board/message?board.id=180&thread.id=14973&view=by_date_ascending&page=1

They approach doing what you are trying to do a few different ways, so one of their solutions may work for you.  Let me know if none of those can work for you.
Kristen
National Instruments
0 Kudos
Message 2 of 3
(3,574 Views)
All,
 
Thanks for the link to the previous posts related to this subject.  On the advice of a colleague, I used a tool called Spy++ to query the ID # and text of the application error popup window.  Then using calls from within CVI to the Windows SDK I was able to obtain a handle to that particular popup and post a message to close it programmatically.  The very simple code snippet is below.  Note:  In my case I knew exactly when the application error message would pop up so I was able to trap for it at a specific point in time. 
 
HWND hwnd

//obtain the handle of a window with the ID "#32770" and text which includes "my text"

hwnd = FindWindow ("#32770", "my text)

if (hwnd) {

       //send a WM_CLOSE to the handle found above

       PostMessage (hwnd, WM_CLOSE, 0, 0);

       break;

}



Message Edited by mulhall on 02-19-2008 12:53 PM
0 Kudos
Message 3 of 3
(3,554 Views)