/
#include "stdafx.h"
#include "TmBridgeInt.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
enum {
BRIDGECONTROLAPI_ATTACH_SUCCESS=0,//���ӳɹ�
BRIDGECONTROLAPI_ATTACH_FAILED=1,//����ʧ��
BRIDGECONTROLAPI_ATTACH_EXIT=2, //�������˳�
BRIDGECONTROLAPI_ATTACH_API_AVAILABLE=0x8001
};
//״̬��չ��...
#define BRIDGE_CALLIN "CALLIN"//���� �磺CALLIN 2011 ��ʾ2011��������
/////////////////////////////////////////////////////////////////////////////
// CTmBridgeInt
CTmBridgeInt::CTmBridgeInt()
{
m_bInit= FALSE;
m_bIsInstall = TRUE;
}
CTmBridgeInt::~CTmBridgeInt()
{
}
BEGIN_MESSAGE_MAP(CTmBridgeInt, CWnd)
//{{AFX_MSG_MAP(CTmBridgeInt)
ON_WM_TIMER()
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
#define BRIDGE_REG_ROOT HKEY_CURRENT_USER
#define BRIDGE_REG_VALUEPATH "Software\\Quanova\\Bridge"
/////////////////////////////////////////////////////////////////////////////
// CTmBridgeInt message handlers
BOOL CTmBridgeInt::IsInstalled()
{
m_bIsInstall = TRUE;
return TRUE;
/*
HKEY hk;
char path[MAX_PATH];
memset(path,0,MAX_PATH);
strcpy(path,BRIDGE_REG_VALUEPATH);
if (RegOpenKey(BRIDGE_REG_ROOT, path, &hk) != ERROR_SUCCESS )
{
m_bIsInstall = FALSE;
return FALSE;
}
else
{
m_bIsInstall = TRUE;
RegCloseKey(hk);
return TRUE;
}
*/
return TRUE;
}
BOOL CTmBridgeInt::InitWindow()
{
if(!IsInstalled())
{
return FALSE;
}
if(!m_bInit)
{
CString szClassName = AfxRegisterWndClass(CS_CLASSDC|CS_SAVEBITS,
LoadCursor(NULL, IDC_ARROW));
BOOL Ret=Create(szClassName,_T(""),0,CRect(0,0,1,1),AfxGetMainWnd(),12999,NULL);
InitVariable();
}
return TRUE;
}
BOOL CTmBridgeInt::Init(HWND hParent)
{
if(!m_bIsInstall)
return FALSE;
m_hParentWnd = hParent;
InitWindow();
BOOL bRet=FALSE;
hInit_MainWindowHandle = this->GetSafeHwnd();
uiGlobal_MsgID_BridgeControlAPIAttach=RegisterWindowMessage("BridgeControlAPIAttach");
uiGlobal_MsgID_BridgeControlAPIDiscover=RegisterWindowMessage("BridgeControlAPIDiscover");
if( ::PostMessage( HWND_BROADCAST, uiGlobal_MsgID_BridgeControlAPIDiscover, (WPARAM)hInit_MainWindowHandle, 0)!=0 )
{
bRet = TRUE;
}
if(!m_ReConnectTimer)
{//�������ʧ�ܣ��Զ�ÿ��30����������
m_ReConnectTimer = SetTimer(10,30000,NULL);
}
return bRet;
}
BOOL CTmBridgeInt::UnInit()
{
if(!m_bInit)
return FALSE;
::PostMessage( HWND_BROADCAST, uiGlobal_MsgID_BridgeControlAPIDiscover, (WPARAM)hInit_MainWindowHandle,1);
if(m_ReConnectTimer)
{
KillTimer(m_ReConnectTimer);
m_ReConnectTimer = NULL;
}
return TRUE;
}
BOOL CTmBridgeInt::SendBridgeCommand(const CString &strCommand)
{
if(!strCommand.IsEmpty())
{
if(!hGlobal_BridgeAPIWindowHandle)
{
return FALSE;
}
COPYDATASTRUCT oCopyData;
oCopyData.dwData=0;
oCopyData.lpData=(LPTSTR)(LPCTSTR)strCommand;
oCopyData.cbData=strlen((LPTSTR)(LPCTSTR)strCommand) 1;
if( oCopyData.cbData!=1 )
{
if( ::SendMessage( hGlobal_BridgeAPIWindowHandle, WM_COPYDATA, (WPARAM)hInit_MainWindowHandle, (LPARAM)&oCopyData)==FALSE )
{//�Ѿ����Ͽ��ˣ�������������
return FALSE;
}else
{
return TRUE;
}
}
}
return FALSE;
}
LRESULT CTmBridgeInt::WindowProc(UINT message, WPARAM wParam, LPARAM lParam)
{
UINT uiMessage=message;
WPARAM uiParam = wParam;
LPARAM ulParam = lParam;
LRESULT lReturnCode;
bool fIssueDefProc;
lReturnCode=0;
fIssueDefProc=false;
switch(uiMessage)
{
case WM_COPYDATA:
if( hGlobal_BridgeAPIWindowHandle==(HWND)uiParam )
{
PCOPYDATASTRUCT poCopyData=(PCOPYDATASTRUCT)ulParam;
lReturnCode=1;//��֤����1��ȷ�����ӣ�����0�����������Ͽ�����
m_strBridgeReturn = (LPTSTR)(LPCTSTR)poCopyData->lpData;
ProcessCallStatue();
}
break;
default:
if( uiMessage==uiGlobal_MsgID_BridgeControlAPIAttach )
{
switch(ulParam)
{
case BRIDGECONTROLAPI_ATTACH_SUCCESS:
hGlobal_BridgeAPIWindowHandle=(HWND)uiParam;
AppendResult("�����������ӳɹ�");
break;
case BRIDGECONTROLAPI_ATTACH_FAILED:
AppendResult("����������ʧ��");
break;
case BRIDGECONTROLAPI_ATTACH_EXIT:
//AppendResult("�������˳�����");
//����������ʱ���Զ���������
//
break;
}
lReturnCode=1;
break;
}
fIssueDefProc=true;
break;
}
if( fIssueDefProc )
lReturnCode=CWnd::WindowProc(message, wParam, lParam);//DefWindowProc( hWindow, uiMessage, uiParam, ulParam);
return(lReturnCode);
//return CWnd::WindowProc(message, wParam, lParam);
}
void CTmBridgeInt::InitVariable()
{
hGlobal_BridgeAPIWindowHandle=NULL;
m_bInit = TRUE;
}
void CTmBridgeInt::AppendResult(CString str)
{
TRACE(str);
TRACE("\n");
::SendMessage(m_hParentWnd,BRIDGE_CALLBACK_STATUE_MESSAGE,0,(LPARAM)(LPTSTR)(LPCTSTR)str);
}
int CTmBridgeInt::_StringSplit(const CString &str, CStringArray &arr, TCHAR chDelimitior)
{
int nStart = 0, nEnd = 0;
arr.RemoveAll();
while (nEnd < str.GetLength())
{
nEnd = str.Find(chDelimitior, nStart);
if( nEnd == -1 )
{
// reached the end of string
nEnd = str.GetLength();
}
CString s = str.Mid(nStart, nEnd - nStart);
if (!s.IsEmpty())
arr.Add(s);
nStart = nEnd 1;
}
return arr.GetSize();
}
void CTmBridgeInt::ProcessCallStatue()
{
CStringArray strArray;
if(_StringSplit(m_strBridgeReturn,strArray,' ') > 0)
{
if(strArray.GetAt(0) == BRIDGE_CALLIN)
{//��0.1�汾֧�֣�����,�Ժ���̭
if(strArray.GetSize() > 1)
{
CString str;
str="���������յ����磬���룺";
str =strArray.GetAt(1);
AppendResult(str);
}
}else
{
AppendResult(m_strBridgeReturn);
}
}
}
void CTmBridgeInt::OnTimer(UINT nIDEvent)
{
if(nIDEvent == m_ReConnectTimer )
{
::PostMessage( HWND_BROADCAST, uiGlobal_MsgID_BridgeControlAPIDiscover, (WPARAM)hInit_MainWindowHandle, 0);
}
CWnd::OnTimer(nIDEvent);
}
.
├── Bridge API 开发文档.pdf
├── TestBridgeAPI
│ ├── Call.cpp
│ ├── Call.h
│ ├── InputID.cpp
│ ├── InputID.h
│ ├── ReadMe.txt
│ ├── Release
│ ├── StdAfx.cpp
│ ├── StdAfx.h
│ ├── TestBridgeAPI.aps
│ ├── TestBridgeAPI.clw
│ ├── TestBridgeAPI.cpp
│ ├── TestBridgeAPI.dsp
│ ├── TestBridgeAPI.dsw
│ ├── TestBridgeAPI.exe
│ ├── TestBridgeAPI.h
│ ├── TestBridgeAPI.ncb
│ ├── TestBridgeAPI.opt
│ ├── TestBridgeAPI.plg
│ ├── TestBridgeAPI.rc
│ ├── TestBridgeAPIDlg.cpp
│ ├── TestBridgeAPIDlg.h
│ ├── TmBridgeAPI.h
│ ├── TmBridgeInt.cpp
│ ├── TmBridgeInt.h
│ ├── TmBridgeSDK.cpp
│ ├── TmBridgeSDK.h
│ ├── res
│ │ ├── TestBridgeAPI.ico
│ │ └── TestBridgeAPI.rc2
│ └── resource.h
├── TestBridgeAPI.exe
├── 好例子网_Bridge API 开发文档.rar
└── 子佩电话录音盒说明书.doc
3 directories, 32 files
网友评论
我要评论