<< 点击显示目录 >> 主页 PVI通信 > PVI帮助信息 > PVI base system > PVICOM interface > PVICOM functions > PviSetGlobEventMsg, PviXSetGlobEventMsg functions |
int PviSetGlobEventMsg (DWORD nGlobEvent, LPVOID hEventMsg, DWORD EventMsgNo, LPARAM EventParam)
int PviXSetGlobEventMsg (DWORD hPvi, DWORD nGlobEvent, LPVOID hEventMsg, DWORD EventMsgNo, LPARAM EventParam)
PviSetGlobEventMsg (ByVal nGlobEvent As Long, ByVal hEventMsg As Long, ByVal EventMsgNo As Long,ByVal EventParam As Long) As Long
PviXSetGlobEventMsg (ByVal hPvi As Long, ByVal nGlobEvent As Long, ByVal hEventMsg As Long, ByVal EventMsgNo As Long, ByVal EventParam As Long) As Long
Argument |
I/O |
说明 |
hPvi |
In |
来自 PviXInitialize 函数的实例句柄 |
nGlobEvent |
In |
POBJ_EVENT_PVI_CONNECT, POBJ_EVENT_PVI_DISCONN, 或POBJ_EVENT_PVI_ARRANGE可以被指定为一个事件。 |
hEventMsg |
In |
定义一个 用户信息 ,在全局事件发生时执行。如果指定hEventMsg = 0(零),那么这个事件的用户消息将被删除。 |
EventMsgNo |
In |
用户信息的信息编号 |
EventParam |
In |
用户信息的消息参数 在32位PVI版本(PviCom.dll)中,消息参数(用户参数)的大小为4字节,在64位PVI版本(PviCom64.dll)中为8字节。 |
如果数值不是0,则表明有错误。错误代码将作为一个值返回。
这个函数将用户信息分配给 通信实例的全局事件 。 PviDeinitialize 或PviXDeinitialize函数用于释放所有通信实例的分配。
可以为每个全局事件类型指定一个不同的用户消息。如果为所有事件定义了相同的用户消息,那么事件类型可以从 RESPONSE_INFO结构中读取 (PviGetResponseInfo 函数)。
在收到全局事件的相应用户消息后,PVI应用必须调用PVICOM函数 PviReadResponse。
Example for Visual C++
#include <PviCom.h>
class CPviDlg : public CDialog
{
...
int Initialize ();
void CreatePviObjects ();
LRESULT OnPviGlobalEvent (WPARAM, LPARAM);
...
DECLARE_MESSAGE_MAP ()
};
BEGIN_MESSAGE_MAP (CPviDlg, CDialog)
...
ON_MESSAGE (WM_USER+1, OnPviGlobalEvent)
END_MESSAGE_MAP()
LRESULT CPviDlg::OnPviGlobalEvent(WPARAM wParam, LPARAM lParam)
{
T_RESPONSE_INFO Info;
int Error;
Error = PviGetResponseInfo (wParam, NULL, NULL, &Info, sizeof (Info));
if (Error != 0)
// no event data:
return (0);
// execute this function on every valid event:
Error = PviReadResponse (wParam, NULL, 0);
switch (Info.nType)
{
case POBJ_EVENT_PVI_CONNECT:
ViewText ("State: CONNECT");
break;
case POBJ_EVENT_PVI_DISCONN:
ViewText ("State: DISCONNECT - Error #%d", Error);
break;
case POBJ_EVENT_PVI_ARRANGE:
CreatePviObjects ();
break;
}
return (0);
}
void CPviDlg::CreatePviObjects()
{
int ErrCode;
...
}
int CPviDlg::Initialize ()
{
int Error;
// create and initialize communication instance:
Error = PviInitialize (8, 0, "IP=10.43.50.62 PN=23840", NULL);
if (Error != 0)
return (Error);
// set global events:
PviSetGlobEventMsg (POBJ_EVENT_PVI_CONNECT, CWnd::m_hWnd, WM_USER+1, 0);
PviSetGlobEventMsg (POBJ_EVENT_PVI_DISCONN, CWnd::m_hWnd, WM_USER+1, 0);
PviSetGlobEventMsg (POBJ_EVENT_PVI_ARRANGE, CWnd::m_hWnd, WM_USER+1, 0);
return (0);
}