In VC, the event message routine has the following format.
LRESULT CAioDlg::DefWindowProc(UINT message, WPARAM wParam, LPARAM lParam)
message
The message number is passed.
wParam
The ID is passed to the lower 2 bytes. The upper two bytes are not currently used.
lParam
Parameters specific to each event are passed.
Message Processing Example 1
If there is only one device that uses the event, the device's decision by ID is not particularly necessary. The following code shows an example of displaying a message box when an event occurs.
switch( message ){
case AIOM_AIE_START :
AfxMessageBox("Sampling start", MB_OK, 0);
break;
case AIOM_AIE_RPTEND :
AfxMessageBox("Repeat end", MB_OK, 0);
break;
case AIOM_AIE_END :
AfxMessageBox("Sampling end", MB_OK, 0);
break;
case AIOM_AIE_DATA_NUM :
AfxMessageBox("Data stored", MB_OK, 0);
break;
case AIOM_AIE_OFERR :
AfxMessageBox("Overflow error", MB_OK, 0);
break;
case AIOM_AIE_SCERR :
AfxMessageBox("Sampling clock period error", MB_OK, 0);
break;
case AIOM_AIE_ADERR :
AfxMessageBox("AD conversion error", MB_OK, 0);
break;
}
Message Processing Example 2
When using events on multiple devices, you need to decide which device generated event. The following code is an example of using events on two devices (ID1 and ID2).
if ( wParam = ID1 ){
switch( message ){
case AIOM_AIE_START :
AfxMessageBox("ID1 : Sampling start", MB_OK, 0);
break;
case AIOM_AIE_RPTEND :
AfxMessageBox("ID1 : Repeat end", MB_OK, 0);
break;
case AIOM_AIE_END :
AfxMessageBox("ID1 : Sampling end", MB_OK, 0);
break;
case AIOM_AIE_DATA_NUM :
AfxMessageBox("ID1 : Data stored", MB_OK, 0);
break;
case AIOM_AIE_OFERR :
AfxMessageBox("ID1 : Overflow error", MB_OK, 0);
break;
case AIOM_AIE_SCERR :
AfxMessageBox("ID1 : Sampling clock period error", MB_OK, 0);
break;
case AIOM_AIE_ADERR :
AfxMessageBox("ID1 : AD conversion error", MB_OK, 0);
break;
}
}
else{
switch( message ){
case AIOM_AIE_START :
AfxMessageBox("ID2 : Sampling start", MB_OK, 0);
break;
case AIOM_AIE_RPTEND :
AfxMessageBox("ID2 : Repeat end", MB_OK, 0);
break;
case AIOM_AIE_END :
AfxMessageBox("ID2 : Sampling end", MB_OK, 0);
break;
case AIOM_AIE_DATA_NUM :
AfxMessageBox("ID2 : Data stored", MB_OK, 0);
break;
case AIOM_AIE_OFERR :
AfxMessageBox("ID2 : Overflow error", MB_OK, 0);
break;
case AIOM_AIE_SCERR :
AfxMessageBox("ID2 : Sampling clock period error", MB_OK, 0);
break;
case AIOM_AIE_ADERR :
AfxMessageBox("ID2 : AD conversion error", MB_OK, 0);
break;
}
return CDialog::DefWindowProc(message, wParam, lParam);
}