// IOModuleTesterDlg.cpp : implementation file // #include "stdafx.h" #include "IOModuleTester.h" #include "IOModuleTesterDlg.h" #include #include #ifdef _DEBUG #define new DEBUG_NEW #undef THIS_FILE static char THIS_FILE[] = __FILE__; #endif ///////////////////////////////////////////////////////////////////////////// // CAboutDlg dialog used for App About class CAboutDlg : public CDialog { public: CAboutDlg(); // Dialog Data //{{AFX_DATA(CAboutDlg) enum { IDD = IDD_ABOUTBOX }; //}}AFX_DATA // ClassWizard generated virtual function overrides //{{AFX_VIRTUAL(CAboutDlg) protected: virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support //}}AFX_VIRTUAL // Implementation protected: //{{AFX_MSG(CAboutDlg) //}}AFX_MSG DECLARE_MESSAGE_MAP() }; CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD) { //{{AFX_DATA_INIT(CAboutDlg) //}}AFX_DATA_INIT } void CAboutDlg::DoDataExchange(CDataExchange* pDX) { CDialog::DoDataExchange(pDX); //{{AFX_DATA_MAP(CAboutDlg) //}}AFX_DATA_MAP } BEGIN_MESSAGE_MAP(CAboutDlg, CDialog) //{{AFX_MSG_MAP(CAboutDlg) // No message handlers //}}AFX_MSG_MAP END_MESSAGE_MAP() ///////////////////////////////////////////////////////////////////////////// // CIOModuleTesterDlg dialog //#define _WC8K_ #define _UNO_ #if defined(_WC8K_) CIOModuleTesterDlg::CIOModuleTesterDlg(CWnd* pParent /*=NULL*/) : CDialog(CIOModuleTesterDlg::IDD, pParent) { //{{AFX_DATA_INIT(CIOModuleTesterDlg) m_strProperty0 = _T("INT"); m_strProperty1 = _T("INT"); m_strProperty2 = _T("INT"); m_strProperty3 = _T("INT"); m_strProperty4 = _T("INT"); m_strAddress = _T("192.168.0.184"); m_strDestination = _T("WC8K.Chobits"); m_nPort = 6000; m_strReceived = _T(""); m_strText = _T(""); m_strValue0 = _T(""); m_strValue1 = _T(""); m_strValue2 = _T(""); m_strValue3 = _T(""); m_strValue4 = _T(""); m_strSubscribe = _T("*"); m_strUsername = _T("ice"); m_strProduct = _T("ice"); m_strPassword = _T("ice"); m_strCompany = _T("ice"); m_strName0 = _T("Report"); m_strName1 = _T(""); m_strName2 = _T(""); m_strName3 = _T(""); m_strName4 = _T(""); //}}AFX_DATA_INIT // Note that LoadIcon does not require a subsequent DestroyIcon in Win32 m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME); m_hAgent=NULL; } #elif defined(_UNO_) CIOModuleTesterDlg::CIOModuleTesterDlg(CWnd* pParent /*=NULL*/) : CDialog(CIOModuleTesterDlg::IDD, pParent) { //{{AFX_DATA_INIT(CIOModuleTesterDlg) m_strProperty0 = _T("INT"); m_strProperty1 = _T("STRING"); m_strProperty2 = _T("INT"); m_strProperty3 = _T("INT"); m_strProperty4 = _T("INT"); m_strAddress = _T("192.168.0.183"); m_strDestination = _T("UNO.Icetech.COM1"); m_nPort = 6000; m_strReceived = _T(""); m_strText = _T(""); m_strValue0 = _T("1"); m_strValue1 = _T(""); m_strValue2 = _T(""); m_strValue3 = _T(""); m_strValue4 = _T(""); m_strSubscribe = _T("*"); m_strUsername = _T("ice"); m_strProduct = _T("ice"); m_strPassword = _T("ice"); m_strCompany = _T("ice"); m_strName0 = _T("ModuleID"); m_strName1 = _T("Value"); m_strName2 = _T(""); m_strName3 = _T(""); m_strName4 = _T(""); //}}AFX_DATA_INIT // Note that LoadIcon does not require a subsequent DestroyIcon in Win32 m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME); m_hAgent=NULL; } #endif void CIOModuleTesterDlg::DoDataExchange(CDataExchange* pDX) { CDialog::DoDataExchange(pDX); //{{AFX_DATA_MAP(CIOModuleTesterDlg) DDX_CBString(pDX, IDC_COMBO_PROPERTY0, m_strProperty0); DDX_CBString(pDX, IDC_COMBO_PROPERTY1, m_strProperty1); DDX_CBString(pDX, IDC_COMBO_PROPERTY2, m_strProperty2); DDX_CBString(pDX, IDC_COMBO_PROPERTY3, m_strProperty3); DDX_CBString(pDX, IDC_COMBO_PROPERTY4, m_strProperty4); DDX_Text(pDX, IDC_EDIT_ADDRESS, m_strAddress); DDX_Text(pDX, IDC_EDIT_DESTINATION, m_strDestination); DDX_Text(pDX, IDC_EDIT_PORT, m_nPort); DDX_Text(pDX, IDC_EDIT_RECEIVED, m_strReceived); DDX_Text(pDX, IDC_EDIT_TEXT, m_strText); DDX_Text(pDX, IDC_EDIT_VALUE0, m_strValue0); DDX_Text(pDX, IDC_EDIT_VALUE1, m_strValue1); DDX_Text(pDX, IDC_EDIT_VALUE2, m_strValue2); DDX_Text(pDX, IDC_EDIT_VALUE3, m_strValue3); DDX_Text(pDX, IDC_EDIT_VALUE4, m_strValue4); DDX_Text(pDX, IDC_EDIT_SUBSCRIBE, m_strSubscribe); DDX_Text(pDX, IDC_EDIT_USERNAME, m_strUsername); DDX_Text(pDX, IDC_EDIT_PRODUCT, m_strProduct); DDX_Text(pDX, IDC_EDIT_PASSWORD, m_strPassword); DDX_Text(pDX, IDC_EDIT_COMPANY, m_strCompany); DDX_CBString(pDX, IDC_COMBO_NAME0, m_strName0); DDX_CBString(pDX, IDC_COMBO_NAME1, m_strName1); DDX_CBString(pDX, IDC_COMBO_NAME2, m_strName2); DDX_CBString(pDX, IDC_COMBO_NAME3, m_strName3); DDX_CBString(pDX, IDC_COMBO_NAME4, m_strName4); //}}AFX_DATA_MAP } BEGIN_MESSAGE_MAP(CIOModuleTesterDlg, CDialog) //{{AFX_MSG_MAP(CIOModuleTesterDlg) ON_WM_SYSCOMMAND() ON_WM_PAINT() ON_WM_QUERYDRAGICON() ON_BN_CLICKED(IDC_BUTTON_CONNECT, OnButtonConnect) ON_BN_CLICKED(IDC_BUTTON_SUBSCRIBE, OnButtonSubscribe) ON_BN_CLICKED(IDC_BUTTON_PUBLISH, OnButtonPublish) ON_BN_CLICKED(IDC_BUTTON_DISCONNECT, OnButtonDisconnect) ON_BN_CLICKED(IDC_BUTTON_UNSUBSCRIBE, OnButtonUnsubscribe) ON_MESSAGE(WM_SUBJECTRECEIVED, OnMessageReceived) ON_MESSAGE(WM_COMMAND_MESSAGE, OnCommandReceived) ON_MESSAGE(WM_CONNECTION_FAIL, OnConnectFail) ON_MESSAGE(WM_CONNECTION_LOST, OnConnectionLost) ON_MESSAGE(WM_CONNECTION_READY, OnConnectOK) ON_BN_CLICKED(IDC_BUTTON_CLEAR, OnButtonClear) //}}AFX_MSG_MAP END_MESSAGE_MAP() ///////////////////////////////////////////////////////////////////////////// // CIOModuleTesterDlg message handlers BOOL CIOModuleTesterDlg::LoadModule() { //載入iPush DLL API char buf[256]; GetModuleFileName(GetModuleHandle(NULL), buf, 256); CString ModuleFilename=buf; ModuleFilename=ModuleFilename.Left(ModuleFilename.ReverseFind('\\')+1)+"MsgAgent.dll"; m_hAgent=LoadLibrary(ModuleFilename); if(!m_hAgent) { AfxMessageBox("Agent Module load fail.\r\n"); return FALSE; } m_procConnect=(ConnectRealProc)GetProcAddress(m_hAgent, "ConnectReal"); m_procDisconnect=(DisconnectRealProc)GetProcAddress(m_hAgent, "DisconnectReal"); m_procSubscribe=(SubSubjectProc)GetProcAddress(m_hAgent, "SubSubject"); m_procUnsubscribe=(UnsubSubjectProc)GetProcAddress(m_hAgent, "UnsubSubject"); m_procSubmit=(SubmitSubjectProc)GetProcAddress(m_hAgent, "SubmitSubject"); if(!m_procConnect || !m_procDisconnect || !m_procSubscribe || !m_procUnsubscribe || !m_procSubmit) { AfxMessageBox("Agent Module procedures load fail.\r\n"); FreeLibrary(m_hAgent); return FALSE; } return TRUE; } BOOL CIOModuleTesterDlg::OnInitDialog() { CDialog::OnInitDialog(); // Add "About..." menu item to system menu. // IDM_ABOUTBOX must be in the system command range. ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX); ASSERT(IDM_ABOUTBOX < 0xF000); CMenu* pSysMenu = GetSystemMenu(FALSE); if (pSysMenu != NULL) { CString strAboutMenu; strAboutMenu.LoadString(IDS_ABOUTBOX); if (!strAboutMenu.IsEmpty()) { pSysMenu->AppendMenu(MF_SEPARATOR); pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu); } } // Set the icon for this dialog. The framework does this automatically // when the application's main window is not a dialog SetIcon(m_hIcon, TRUE); // Set big icon SetIcon(m_hIcon, FALSE); // Set small icon // TODO: Add extra initialization here //在這裡就先將iPushAPI DLL載入 if(!LoadModule()) exit(0); SetUIDisconnected(); return TRUE; // return TRUE unless you set the focus to a control } void CIOModuleTesterDlg::OnSysCommand(UINT nID, LPARAM lParam) { if ((nID & 0xFFF0) == IDM_ABOUTBOX) { CAboutDlg dlgAbout; dlgAbout.DoModal(); } else { CDialog::OnSysCommand(nID, lParam); } } // If you add a minimize button to your dialog, you will need the code below // to draw the icon. For MFC applications using the document/view model, // this is automatically done for you by the framework. void CIOModuleTesterDlg::OnPaint() { if (IsIconic()) { CPaintDC dc(this); // device context for painting SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0); // Center icon in client rectangle int cxIcon = GetSystemMetrics(SM_CXICON); int cyIcon = GetSystemMetrics(SM_CYICON); CRect rect; GetClientRect(&rect); int x = (rect.Width() - cxIcon + 1) / 2; int y = (rect.Height() - cyIcon + 1) / 2; // Draw the icon dc.DrawIcon(x, y, m_hIcon); } else { CDialog::OnPaint(); } } // The system calls this to obtain the cursor to display while the user drags // the minimized window. HCURSOR CIOModuleTesterDlg::OnQueryDragIcon() { return (HCURSOR) m_hIcon; } void CIOModuleTesterDlg::OnButtonConnect() { // TODO: Add your control notification handler code here UpdateData(TRUE); if(m_strAddress.IsEmpty() || !m_nPort || m_strCompany.IsEmpty() || m_strProduct.IsEmpty() || m_strUsername.IsEmpty() || m_strPassword.IsEmpty()) { AfxMessageBox("Invalid server address or login info."); return; } if(m_procConnect((char*)LPCTSTR(m_strCompany), (char*)LPCTSTR(m_strProduct), (char*)LPCTSTR(m_strUsername), (char*)LPCTSTR(m_strPassword), NULL, 0, (char*)LPCTSTR(m_strAddress), m_nPort, m_hWnd)<=0) { AfxMessageBox("Fail to create socket."); return; } //SetUIConnected(); } void CIOModuleTesterDlg::OnButtonSubscribe() { // TODO: Add your control notification handler code here //訂閱 UpdateData(TRUE); if(!m_strSubscribe.IsEmpty()) { m_procSubscribe((char*)LPCTSTR(m_strSubscribe)); } else AfxMessageBox("Can't subscribe empty subject"); } void CIOModuleTesterDlg::DoSetProperty(MessageObject *lpMsgObj, CString strProperty, CString strName, CString strValue) { if(strProperty == "BOOL") { BOOL bValue; if(strValue=="TRUE") bValue=TRUE; else bValue=FALSE; lpMsgObj->setBooleanProperty((char*)LPCTSTR(strName), bValue); } else if(strProperty == "BYTE") { lpMsgObj->setByteProperty((char*)LPCTSTR(strName), (BYTE)atoi(strValue)); } else if(strProperty == "SHORT") { lpMsgObj->setShortProperty((char*)LPCTSTR(strName), (short)atoi(strValue)); } else if(strProperty == "INT") { lpMsgObj->setIntProperty((char*)LPCTSTR(strName), (int)atoi(strValue)); } else if(strProperty == "FLOAT") { lpMsgObj->setFloatProperty((char*)LPCTSTR(strName), (float)atof(strValue)); } else if(strProperty == "DOUBLE") { lpMsgObj->setDoubleProperty((char*)LPCTSTR(strName), (double)atof(strValue)); } else if(strProperty == "STRING") { lpMsgObj->setStringProperty((char*)LPCTSTR(strName), (char*)LPCTSTR(strValue)); } else { CString str; str.Format("Unknown Property %s", strProperty); AfxMessageBox(str); } } void CIOModuleTesterDlg::OnButtonPublish() { // TODO: Add your control notification handler code here UpdateData(TRUE); //首先檢查各欄位是否有值 if(m_strDestination.IsEmpty()) { AfxMessageBox("Which topic you wish to submit to?"); return; } if(m_strName0.IsEmpty() && m_strName1.IsEmpty() && m_strName2.IsEmpty() && m_strName3.IsEmpty() && m_strName4.IsEmpty() && m_strText.IsEmpty()) { AfxMessageBox("You can't publish nothing."); return; } //將各欄位值置入MessageObject中 MessageObject MO; if(!m_strName0.IsEmpty()) DoSetProperty(&MO, m_strProperty0, m_strName0, m_strValue0); if(!m_strName1.IsEmpty()) DoSetProperty(&MO, m_strProperty1, m_strName1, m_strValue1); if(!m_strName2.IsEmpty()) DoSetProperty(&MO, m_strProperty2, m_strName2, m_strValue2); if(!m_strName3.IsEmpty()) DoSetProperty(&MO, m_strProperty3, m_strName3, m_strValue3); if(!m_strName4.IsEmpty()) DoSetProperty(&MO, m_strProperty4, m_strName4, m_strValue4); if(!m_strText.IsEmpty()) MO.setText((char*)LPCTSTR(m_strText)); //將MessageObject轉換成字串 char strBuf[1024]; int nLen=MessageObject2String(strBuf, 1024, &MO); if(nLen>0) { //呼叫iPushAPI將該字串送出 m_procSubmit((char*)LPCTSTR(m_strDestination), strBuf, nLen); } } void CIOModuleTesterDlg::OnButtonDisconnect() { // TODO: Add your control notification handler code here //斷線 m_procDisconnect(); m_strReceived+="Connection Closed\r\n"; SetDlgItemText(IDC_EDIT_RECEIVED, m_strReceived); ((CEdit*)GetDlgItem(IDC_EDIT_RECEIVED))->SetSel(m_strReceived.GetLength(), m_strReceived.GetLength()); SetUIDisconnected(); } void CIOModuleTesterDlg::OnButtonUnsubscribe() { // TODO: Add your control notification handler code here //解除訂閱 UpdateData(TRUE); if(!m_strSubscribe.IsEmpty()) { m_procUnsubscribe((char*)LPCTSTR(m_strSubscribe)); } else AfxMessageBox("Can't unsubscribe empty subject"); } void CIOModuleTesterDlg::SetUIConnected() { //將各UI變更為已連線狀態 GetDlgItem(IDC_EDIT_ADDRESS)->EnableWindow(FALSE); GetDlgItem(IDC_EDIT_PORT)->EnableWindow(FALSE); GetDlgItem(IDC_EDIT_COMPANY)->EnableWindow(FALSE); GetDlgItem(IDC_EDIT_PRODUCT)->EnableWindow(FALSE); GetDlgItem(IDC_EDIT_USERNAME)->EnableWindow(FALSE); GetDlgItem(IDC_EDIT_PASSWORD)->EnableWindow(FALSE); GetDlgItem(IDC_BUTTON_CONNECT)->EnableWindow(FALSE); GetDlgItem(IDC_BUTTON_DISCONNECT)->EnableWindow(TRUE); GetDlgItem(IDC_BUTTON_SUBSCRIBE)->EnableWindow(TRUE); GetDlgItem(IDC_BUTTON_UNSUBSCRIBE)->EnableWindow(TRUE); GetDlgItem(IDC_BUTTON_PUBLISH)->EnableWindow(TRUE); } void CIOModuleTesterDlg::SetUIDisconnected() { //將各UI變更為未連線狀態 GetDlgItem(IDC_EDIT_ADDRESS)->EnableWindow(TRUE); GetDlgItem(IDC_EDIT_PORT)->EnableWindow(TRUE); GetDlgItem(IDC_EDIT_COMPANY)->EnableWindow(TRUE); GetDlgItem(IDC_EDIT_PRODUCT)->EnableWindow(TRUE); GetDlgItem(IDC_EDIT_USERNAME)->EnableWindow(TRUE); GetDlgItem(IDC_EDIT_PASSWORD)->EnableWindow(TRUE); GetDlgItem(IDC_BUTTON_CONNECT)->EnableWindow(TRUE); GetDlgItem(IDC_BUTTON_DISCONNECT)->EnableWindow(FALSE); GetDlgItem(IDC_BUTTON_SUBSCRIBE)->EnableWindow(FALSE); GetDlgItem(IDC_BUTTON_UNSUBSCRIBE)->EnableWindow(FALSE); GetDlgItem(IDC_BUTTON_PUBLISH)->EnableWindow(FALSE); } void CIOModuleTesterDlg::OnMessageReceived(BlockDataStruct *pBlock, LPARAM lParam) { //將資料轉成MessageObject物件 MessageObject MO; String2MessageObject(&MO, pBlock->pData); //檢查MessageObject帶有哪些資料,然後印出來 CString str2; str2.Format("%s ", pBlock->strName); if(MO.isPropertyExist("Time")) { CTime time((time_t)MO.getIntProperty("Time")); str2+=time.Format("(%d/%m/%y %H:%M:%S) "); } #if defined(_UNO_) if(MO.isPropertyExist("GetComData")) { char *strData=MO.getStringProperty("GetComData"); if(strData) { str2+="Received COM Data => "; str2+=strData; } } if(MO.isPropertyExist("CommandOK")) { int nModuleID=MO.getIntProperty("CommandOK"); CString strText; strText.Format("Command OK, ModuleID = %d", nModuleID); str2+=strText; } if(MO.isPropertyExist("CommandFail")) { int nModuleID=MO.getIntProperty("CommandFail"); CString strText; strText.Format("Command FAIL, ModuleID = %d", nModuleID); str2+=strText; } if(MO.isPropertyExist("State")) { char *strNewState=MO.getStringProperty("State"); if(strNewState) { CString strText; strText.Format("Module State = %s", strNewState); str2+=strText; } } #endif #if defined(_WC8K_) if(MO.isPropertyExist("DeviceInfo")) { char *strName=MO.getStringProperty("DeviceInfo"); if(strName) { CString str; str.Format("Device %s info DI:%d DO:%d AI:%d AO:%d Counter:%d", strName, MO.getIntProperty("#DI"), MO.getIntProperty("#DO"), MO.getIntProperty("#AI"), MO.getIntProperty("#AO"), MO.getIntProperty("#Counter")); str2+=str; } } if(MO.isPropertyExist("DigitalInput")) { int nValue=MO.getIntProperty("DigitalInput"); CString str; str.Format("DigitalInput=%d ", nValue); str2+=str; } if(MO.isPropertyExist("BitInput")) { BOOL bValue=MO.getBooleanProperty("BitInput"); CString str; str.Format("BitInput=%s ", bValue?"TRUE":"FALSE"); str2+=str; } if(MO.isPropertyExist("DigitalOutput")) { int nValue=MO.getIntProperty("DigitalOutput"); CString str; str.Format("DigitalOutput=%d ", nValue); str2+=str; } if(MO.isPropertyExist("BitOutput")) { BOOL bValue=MO.getBooleanProperty("BitOutput"); CString str; str.Format("BitOutput=%s ", bValue?"TRUE":"FALSE"); str2+=str; } if(MO.isPropertyExist("VoltageInput")) { float fVoltage=MO.getFloatProperty("VoltageInput"); CString str; str.Format("VoltageInput=%f ", fVoltage); str2+=str; } if(MO.isPropertyExist("VoltageOutput")) { float fVoltage=MO.getFloatProperty("VoltageOutput"); CString str; str.Format("VoltageOutput=%f ", fVoltage); str2+=str; } if(MO.isPropertyExist("CurrentInput")) { float fCurrent=MO.getFloatProperty("CurrentInput"); CString str; str.Format("CurrentInput=%f ", fCurrent); str2+=str; } if(MO.isPropertyExist("CurrentOutput")) { float fCurrent=MO.getFloatProperty("CurrentOutput"); CString str; str.Format("CurrentOutput=%f ", fCurrent); str2+=str; } if(MO.isPropertyExist("AnalogOutput")) { float fOutPut=MO.getFloatProperty("AnalogOutput"); CString str; str.Format("AnalogOutput=%f ", fOutPut); str2+=str; } if(MO.isPropertyExist("AnalogInput")) { float fInput=MO.getFloatProperty("AnalogInput"); CString str; str.Format("AnalogInput=%f ", fInput); str2+=str; } if(MO.isPropertyExist("Frequency")) { int nFrequency=MO.getIntProperty("Frequency"); CString str; str.Format("Frequency=%d ", nFrequency); str2+=str; } if(MO.isPropertyExist("Slot")) { int nSlot=MO.getIntProperty("Slot"); int nType=MO.getIntProperty("Type"); int nID=MO.getIntProperty("Id"); char *strName=MO.getStringProperty("Name"); BOOL bActived=MO.getBooleanProperty("Active"); CString str; if(bActived) str.Format("Device Slot %d Name=%s, ID=%d, Type=%x, Actived=TRUE", nSlot, strName, nID, nType); else str.Format("Device Slot %d Name=%s, ID=%d, Type=%x, Actived=FALSE", nSlot, strName, nID, nType); str2+=str; } #endif m_strReceived+=str2+"\r\n"; SetDlgItemText(IDC_EDIT_RECEIVED, m_strReceived); if(m_strReceived.GetLength()>8192) m_strReceived=m_strReceived.Right(4096); ((CEdit*)GetDlgItem(IDC_EDIT_RECEIVED))->SetSel(m_strReceived.GetLength(), m_strReceived.GetLength()); } void CIOModuleTesterDlg::OnCommandReceived(int nCommandType, char *strCommand) { //此函式處理處理來自iPush的回應訊息,諸如訂閱成不成功之類的 m_strReceived+="Command Result "; switch(nCommandType) { case CM_COMMAND_OK: m_strReceived+="CM_COMMAND_OK "; break; case CM_CHANNEL_INVALID: m_strReceived+="CM_CHANNEL_INVALID "; break; case CM_CHANNEL_OVERFLOW: m_strReceived+="CM_CHANNEL_OVERFLOW "; break; case CM_CHANNEL_DUPLICATE: m_strReceived+="CM_CHANNEL_DUPLICATE "; break; case CM_UNSUB_NONE: m_strReceived+="CM_UNSUB_NONE "; break; case CM_CHANNEL_NOPERMISSION: m_strReceived+="CM_CHANNEL_NOPERMISSION "; break; case CM_SUBJECT_OK: m_strReceived+="CM_SUBJECT_OK "; break; case CM_SUBJECT_INVALID: m_strReceived+="CM_SUBJECT_INVALID "; break; case CM_SUBJECT_OVERFLOW: m_strReceived+="CM_SUBJECT_OVERFLOW "; break; case CM_SUBJECT_DUPLICATE: m_strReceived+="CM_SUBJECT_DUPLICATE "; break; case CM_SUBJECT_UNSUB_NONE: m_strReceived+="CM_SUBJECT_UNSUB_NONE "; break; case CM_SUBJECT_NOPERMISSION: m_strReceived+="CM_SUBJECT_NOPERMISSION "; break; default: m_strReceived+="UNKNOWN "; break; } m_strReceived+=strCommand; m_strReceived+="\r\n"; SetDlgItemText(IDC_EDIT_RECEIVED, m_strReceived); } void CIOModuleTesterDlg::OnConnectFail(int nErrorCode, HANDLE hSocket) { //此函式處理連線發生失敗的回應 m_strReceived+="Connect Fail => "; switch(nErrorCode) { case CF_CONNECT_FAIL: m_strReceived+="CF_CONNECT_FAIL"; break; case CF_LOGININFO_UNKNOWN: m_strReceived+="CF_CONNECT_FAIL"; break; case CF_CORE_UNKNOWN: m_strReceived+="CF_CONNECT_FAIL"; break; case CF_SOCKET_CREATE_FAIL: m_strReceived+="CF_CONNECT_FAIL"; break; case CF_PROXY_FAIL: m_strReceived+="CF_CONNECT_FAIL"; break; case CF_CONNECT_UNREADY: m_strReceived+="CF_CONNECT_FAIL"; break; case CF_LOGIN_FAIL: m_strReceived+="CF_CONNECT_FAIL"; break; case CF_PASSWORD_FAIL: m_strReceived+="CF_CONNECT_FAIL"; break; case CF_USER_UNKNOWN: m_strReceived+="CF_CONNECT_FAIL"; break; case CF_CONNECT_LIMIT: m_strReceived+="CF_CONNECT_FAIL"; break; case CF_PROXY_USERDATA_REQUIRE: m_strReceived+="CF_CONNECT_FAIL"; break; default: m_strReceived+="UNKNOWN"; break; } m_strReceived+="\r\n"; SetDlgItemText(IDC_EDIT_RECEIVED, m_strReceived); } void CIOModuleTesterDlg::OnConnectionLost(int nErrorCode, HANDLE hSocket) { //此函式處離連線中斷 CString str; str.Format("Connection Lost ! error code = %d\r\n", nErrorCode); m_strReceived+=str; SetDlgItemText(IDC_EDIT_RECEIVED, m_strReceived); SetUIDisconnected(); } void CIOModuleTesterDlg::OnConnectOK(char *HostInfo, HANDLE hSocket) { //此函式處理連線成功 m_strReceived+="Connect OK => "; m_strReceived+=HostInfo; m_strReceived+="\r\n"; SetDlgItemText(IDC_EDIT_RECEIVED, m_strReceived); SetUIConnected(); } BOOL CIOModuleTesterDlg::PreTranslateMessage(MSG* pMsg) { // TODO: Add your specialized code here and/or call the base class if(pMsg->wParam==VK_ESCAPE || pMsg->wParam==VK_RETURN) return TRUE; return CDialog::PreTranslateMessage(pMsg); } void CIOModuleTesterDlg::OnButtonClear() { // TODO: Add your control notification handler code here m_strReceived=""; SetDlgItemText(IDC_EDIT_RECEIVED, ""); }