Admin Production ni-theme
Current Publication

InstallWinMsgCallback

LabWindows/CVI

InstallWinMsgCallback

int InstallWinMsgCallback (int panelHandle, int messageNumber, WinMsgCallback callbackFunction, int callbackMode, void *callbackData, intptr_t *postingHandle);

Purpose

Installs a callback function for a specific Windows message posted or sent to a LabWindows/CVI panel. A call to ProcessSystemEvents or RunUserInterface causes the panel to receive the message, and the specified callback function will be passed the message data.

You must include windows.h in your source code if you use Windows constants such as WM_CLOSE, WM_PAINT, and so on to denote the message numbers. You can install the same callback function to intercept more than one Windows message by calling InstallWinMsgCallback once for each message and passing the callback function's address in each call. After you finish intercepting messages, call RemoveWinMsgCallback to uninstall the callback functions that were installed using the InstallWinMsgCallback function, and free associated memory.

Notes  
  • Using this function generates chained callback functions. Use the appropriate callback data function if you want to get or set callback data.
  • Windows Messaging is a complicated paradigm, and some things may not work as expected. This is especially true when intercepting messages such as WM_PAINT that occur very frequently during an application's lifetime. Note that these messages are correctly handled by the internal Window Procedures, and that anomalies may be seen when trying to intercept and handle them externally.
  • A message callback cannot be installed for a LabWindows/CVI child panel. In your programs, do not mix the message callback functions with the routing functions in the Route Messages sub–class, as they use different window 'subclassing' mechanisms.

Example Code

int CVICALLBACK MyCallback (int panelHandle, int message, unsigned int* wParam, unsigned int* lParam, void* callbackData);
int panelHandle;
int postHandle;

void main (void)
{

if ((panelHandle = LoadPanel (0, "MyUIR.uir", PANEL)) < 0)

return;

/* To intercept the WM_CLOSE message with MyCallback */
InstallWinMsgCallback (panelHandle, WM_CLOSE, MyCallback, VAL_MODE_INTERCEPT, NULL, &postHandle);
........

/* Uninstall the event handler and free associated memory */
RemoveWinMsgCallback (panelHandle, WM_CLOSE);

}

(Linux) This function is not supported.

Parameters

Input
Name Type Description
panelHandle int The handle of the LabWindows/CVI panel for which to install a Windows message callback function.
messageNumber int The number of the message for which to install a callback function.

Note  You may not respond to WM_DISCARD, WM_DESTROY or WM_DROPFILES messages.
callbackFunction WinMsgCallback The callback function to associate with the specified Windows message. The driver calls this function when the message handler detects the specified message and passes all Windows message data to the function.

The function must be of the prototype:

int CVICALLBACK MyCallback (int panelHandle, int message, unsigned int *wParam, unsigned int *lParam, void* callbackData);


Note Note  If you are running in 64-bit mode, note that the wParam and lParam parameters are actually pointers to 8-byte values (of type WPARAM and LPARAM respectively), and you must cast these parameters accordingly before you can dereference them.
If your callback is configured to intercept the message (execution mode = VAL_MODE_INTERCEPT), the function should return 0 if you want the message to be passed on to the normal LabWindows/CVI panel message–handler. If the function returns a 1, then the message will not be detected by the LabWindows/CVI message–handler. Note that the function has access to message data pointers. If passing the messages on to the LabWindows/CVI message handler, you can alter the contents of these pointers and the LabWindows/CVI message–handler will receive the "adjusted" message data.

If your callback is configured for queued execution, then the return value or changing the message contents has no effect.

An event EVENT_NEWHANDLE may be passed to your callback through the message parameter. When this occurs, it is because the Windows handle of the LabWindows/CVI panel has changed internally. You can obtain the new Windows handle, which you must now use to post messages, from the wParam value.
callbackMode int Specifies when your callback will actually execute.

If you specify VAL_MODE_IN_QUEUE or select In–Queue in the function panel, the LabWindows/CVI handler sees the message and places a call to your callback in the LabWindows/CVI standard user interface event queue.

If you specify VAL_MODE_INTERCEPT or select Intercept in the function panel, the callback is executed before LabWindows/CVI sees the message. You can use this mode if you need to adjust the message before the LabWindows/CVI handler sees the message. In this mode, LabWindows/CVI does not process the event, and the event is passed to the default window procedure, which causes the default event behavior to occur.
Note Note  wParam and lParam might be pointers. If you need to access the referenced data in these parameters, use the Intercept mode to ensure that the callback is called before the referenced data is deallocated.
callbackData void * A pointer to be passed to your message callback function, similar to the standard UI callback mechanism.
Output
Name Type Description
postingHandle intptr_t The Window Handle (HWND) that you can use to post a message to this LabWindows/CVI panel, if you need to post a message.

Note Note  Under certain conditions, this handle may change internally. Therefore, it is necessary to respond to the EVENT_NEWHANDLE message in your callback function and then use the new handle, passed via the contents of the wParam input.

Return Value

Name Type Description
status int The status code that the function returns.

0 indicates success.

A negative value indicates an error.

This function may return a Programmer's Toolbox or UI Library error code. Call GetGeneralErrorString to obtain a text description of the error.

Additional Information

Library: Programmer's Toolbox

Include file: toolbox\toolbox.h

LabWindows/CVI compatibility: LabWindows/CVI 5.5 and later

Example

Refer to toolbox\msgdemo.cws for an example of using the InstallWinMsgCallback function.