XFS事件处理问题

来源:互联网 发布:考勤机怎么修改数据 编辑:程序博客网 时间:2024/06/05 17:12
LRESULT CALLBACK WindowProc(HWND, UINT, WPARAM, LPARAM);

int CreateWindowFunc( HINSTANCE hInstance )
{
        HWND hWinHandle;
        WNDCLASS wndClass;
        char lpszClassName[] = "EVENTPROCESS";
        char lpszTitle[] = "TestSP";
        wndClass.style = 0;
        wndClass.lpfnWndProc = WindowProc;
        wndClass.cbClsExtra = 0;
        wndClass.cbWndExtra = 0;
        wndClass.hInstance = hInstance;
        wndClass.hIcon = NULL;
        wndClass.hCursor = NULL;
        wndClass.hbrBackground = (HBRUSH)(GetStockObject(WHITE_BRUSH)); ; 
        wndClass.lpszMenuName = NULL;
        wndClass.lpszClassName = lpszClassName;

        if(!RegisterClass(&wndClass))
        {
                xfslog.Add( "RegisterClass Failed, the error is: %d", GetLastError() );
                return NULL;
        }

        try{
                hWinHandle = CreateWindow(
                        lpszClassName,
                        lpszTitle,
                        WS_OVERLAPPEDWINDOW,
                        CW_USEDEFAULT,
                        CW_USEDEFAULT,
                        CW_USEDEFAULT,
                        CW_USEDEFAULT,         
                        NULL,  
                        NULL,       
                        hInstance,
                        NULL
        );
        }
        catch (...)
        {
                xfslog.Add( "CreateWindow() Failed, error code is: %d", GetLastError() );
                return NULL;
        }
        
    XfsFun.m_hWnd = hWinHandle;
        ShowWindow( XfsFun.m_hWnd, SW_HIDE );
        UpdateWindow( XfsFun.m_hWnd );
        return 0;
}

LRESULT CALLBACK WindowProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
        switch(message)
        {
            case WM_CREATE:
                    return 0;
            case WFS_EXECUTE_EVENT:
                    hRet = Handle_( (LPWFSRESULT)lParam );
                    WFSFreeResult((WFSRESULT*)lParam);
            default:
                    return DefWindowProc(hwnd, message, wParam, lParam);
        }
        return 0;
}

HRESULT Handle_( LPWFSRESULT pWfsResult )
{
        memcpy(&m_TempWfsResult, pWfsResult, sizeof(WFSRESULT));        
        if(pWfsResult->hResult == WFS_SUCCESS)
        {
                ULONG Digit = 0;
                switch(pWfsResult->u.dwEventID)
                {
                    case WFS_EXEE_PIN_KEY:
                            memcpy(&PressedKey, pWfsResult->lpBuffer, sizeof(WFSPINKEY));
                            Digit = PressedKey.ulDigit;
                            Data[iLen] = UlongToByte(Digit);
                            iLen ++;
                            break;
                    default:
                            break;
                }
        }
        return 0;
}
接着的XfsFun.cpp里面,调用WFSAsyncExecute时,对HWnd参数,传前面CreateWindow生成的窗口句柄XfsFun.m_hWnd = hWinHandle;

iRet = WFSAsyncExecute(m_hService, WFS_CMD_PIN_GET_DATA, pPinGetData, WFS_INDEFINITE_WAIT, this->m_hWnd, &m_pReq);

这样处理了后,一旦SP有事件发送上来时,会发给this->m_hWnd窗口句柄,然后Windows系统自动会调用CALLBACK WindowProc处理。你在CALLBACK WindowProc函数中处理你想接收的事件类型。

0 0