// ConnList.cpp : implementation file // #include "stdafx.h" #include "dclient.h" #include "ConnList.h" #include "SrvrProp.h" #include #ifdef _DEBUG #define new DEBUG_NEW #undef THIS_FILE static char THIS_FILE[] = __FILE__; #endif enum { CONNECTION_NAME=0, CONNECTION_PEER_ADDRESS, CONNECTION_PEER_PORT, CONNECTION_CALLED, CONNECTION_CALLING, CONNECTION_HOST_ADDRESS, CONNECTION_HOST_PORT, CONNECTION_MAX }; ///////////////////////////////////////////////////////////////////////////// // CConnectList dialog CConnectList::CConnectList(CWnd* pParent /*=NULL*/) : CDialog(CConnectList::IDD, pParent) { //{{AFX_DATA_INIT(CConnectList) // NOTE: the ClassWizard will add member initialization here //}}AFX_DATA_INIT } void CConnectList::DoDataExchange(CDataExchange* pDX) { CDialog::DoDataExchange(pDX); //{{AFX_DATA_MAP(CConnectList) DDX_Control(pDX, IDC_CONNECTIONS, m_Connections); //}}AFX_DATA_MAP } BEGIN_MESSAGE_MAP(CConnectList, CDialog) //{{AFX_MSG_MAP(CConnectList) ON_BN_CLICKED(IDC_INSERT, OnInsert) ON_BN_CLICKED(IDC_MODIFY, OnModify) ON_BN_CLICKED(IDC_DELETE, OnDelete) ON_NOTIFY(NM_DBLCLK, IDC_CONNECTIONS, OnDblclkConnections) //}}AFX_MSG_MAP END_MESSAGE_MAP() ///////////////////////////////////////////////////////////////////////////// // CConnectList message handlers BOOL CConnectList::OnInitDialog() { CDialog::OnInitDialog(); int i; short nIndex; CString strText; CString strTemp; m_Connections.InsertColumn(CONNECTION_NAME, "Name", LVCFMT_LEFT, 120, CONNECTION_NAME+1); m_Connections.InsertColumn(CONNECTION_PEER_ADDRESS, "Server Address", LVCFMT_LEFT, 100, CONNECTION_PEER_ADDRESS+1); m_Connections.InsertColumn(CONNECTION_PEER_PORT, "Server Port", LVCFMT_LEFT, 70, CONNECTION_PEER_PORT+1); m_Connections.InsertColumn(CONNECTION_CALLED, "Called Application", LVCFMT_LEFT, 100, CONNECTION_CALLED+1); m_Connections.InsertColumn(CONNECTION_CALLING, "Calling Application", LVCFMT_LEFT, 100, CONNECTION_CALLING+1); m_Connections.InsertColumn(CONNECTION_HOST_ADDRESS, "Local Address", LVCFMT_LEFT, 100, CONNECTION_HOST_ADDRESS+1); m_Connections.InsertColumn(CONNECTION_HOST_PORT, "Local Port", LVCFMT_LEFT, 70, CONNECTION_HOST_PORT+1); SetDlgItemInt(IDC_TIMEOUT, m_nTimeout, FALSE); m_nIndex = -1; if(m_nConnection < 1) { MessageBox("You must add at least one connection!", "Notice", MB_OK); return FALSE; } for (i = 0; i < m_nConnection; i++) { nIndex = m_Connections.InsertItem(m_Connections.GetItemCount(), "Z"); m_Connections.SetItemText(nIndex, CONNECTION_NAME, m_pConnection[i].szName); m_Connections.SetItemText(nIndex, CONNECTION_PEER_ADDRESS, m_pConnection[i].szPeerAddress); strText.Format("%lu", m_pConnection[i].nPeerPort); m_Connections.SetItemText(nIndex, CONNECTION_PEER_PORT, strText); m_Connections.SetItemText(nIndex, CONNECTION_CALLED, m_pConnection[i].szCalled); m_Connections.SetItemText(nIndex, CONNECTION_CALLING, m_pConnection[i].szCalling); m_Connections.SetItemText(nIndex, CONNECTION_HOST_ADDRESS, m_pConnection[i].szHostAddress); strText.Format("%lu", m_pConnection[i].nHostPort); m_Connections.SetItemText(nIndex, CONNECTION_HOST_PORT, strText); } m_Connections.SetItemState(0, LVIS_FOCUSED, LVIS_FOCUSED); m_Connections.SetItemState(0, LVIS_FOCUSED|LVIS_SELECTED, LVIS_FOCUSED|LVIS_SELECTED); m_Connections.SetFocus(); return FALSE; // return TRUE unless you set the focus to a control // EXCEPTION: OCX Property Pages should return FALSE } void CConnectList::OnOK() { int i; CString strText; m_nTimeout = GetDlgItemInt(IDC_TIMEOUT, NULL, FALSE); if (m_pConnection != NULL) { GlobalFreePtr(m_pConnection); m_pConnection = NULL; m_nConnection = 0; } if (m_Connections.GetItemCount() != 0) m_pConnection = (pNETCONNECTION)GlobalAllocPtr(GMEM_MOVEABLE, sizeof(NETCONNECTION)*m_Connections.GetItemCount()); if (m_pConnection != NULL) { m_nConnection = m_Connections.GetItemCount(); for (i = 0; i < m_Connections.GetItemCount(); i++) { strncpy(m_pConnection[i].szName, m_Connections.GetItemText(i, CONNECTION_NAME), sizeof(m_pConnection[i].szName)-1); strncpy(m_pConnection[i].szHostAddress, m_Connections.GetItemText(i, CONNECTION_HOST_ADDRESS), sizeof(m_pConnection[i].szHostAddress)-1); m_pConnection[i].nHostPort = atoi(m_Connections.GetItemText(i, CONNECTION_HOST_PORT)); strncpy(m_pConnection[i].szPeerAddress, m_Connections.GetItemText(i, CONNECTION_PEER_ADDRESS), sizeof(m_pConnection[i].szPeerAddress)-1); m_pConnection[i].nPeerPort = atoi(m_Connections.GetItemText(i, CONNECTION_PEER_PORT)); strncpy(m_pConnection[i].szCalled, m_Connections.GetItemText(i, CONNECTION_CALLED), sizeof(m_pConnection[i].szCalled)-1); strncpy(m_pConnection[i].szCalling, m_Connections.GetItemText(i, CONNECTION_CALLING), sizeof(m_pConnection[i].szCalling)-1); m_pConnection[i].szName[sizeof(m_pConnection[i].szName)-1] = 0; m_pConnection[i].szHostAddress[sizeof(m_pConnection[i].szHostAddress)-1] = 0; m_pConnection[i].szPeerAddress[sizeof(m_pConnection[i].szPeerAddress)-1] = 0; m_pConnection[i].szCalled[sizeof(m_pConnection[i].szCalled)-1] = 0; m_pConnection[i].szCalling[sizeof(m_pConnection[i].szCalling)-1] = 0; } } for (i = 0; i < m_Connections.GetItemCount(); i++) { if (m_Connections.GetItemState(i, LVIS_SELECTED) == LVIS_SELECTED) { m_nIndex = i; m_strHostAddress = m_Connections.GetItemText(i, CONNECTION_HOST_ADDRESS); m_nHostPort = atoi(m_Connections.GetItemText(i, CONNECTION_HOST_PORT)); m_strPeerAddress = m_Connections.GetItemText(i, CONNECTION_PEER_ADDRESS); m_nPeerPort = atoi(m_Connections.GetItemText(i, CONNECTION_PEER_PORT)); m_strCalled = m_Connections.GetItemText(i, CONNECTION_CALLED); m_strCalling = m_Connections.GetItemText(i, CONNECTION_CALLING); } } CDialog::OnOK(); } void CConnectList::OnInsert() { CServerProp dlg; short nIndex; dlg.m_strName = ""; dlg.m_strHostAddress = ""; dlg.m_strHostPort = ""; dlg.m_strPeerAddress = ""; dlg.m_strPeerPort = ""; dlg.m_strCalled = ""; dlg.m_strCalling = ""; if (dlg.DoModal() != IDOK) { m_Connections.SetFocus(); return; } nIndex = m_Connections.InsertItem(m_Connections.GetItemCount(), "Z"); m_Connections.SetItemText(nIndex, CONNECTION_NAME, dlg.m_strName); m_Connections.SetItemText(nIndex, CONNECTION_HOST_ADDRESS, dlg.m_strHostAddress); m_Connections.SetItemText(nIndex, CONNECTION_HOST_PORT, dlg.m_strHostPort); m_Connections.SetItemText(nIndex, CONNECTION_PEER_ADDRESS, dlg.m_strPeerAddress); m_Connections.SetItemText(nIndex, CONNECTION_PEER_PORT, dlg.m_strPeerPort); m_Connections.SetItemText(nIndex, CONNECTION_CALLED, dlg.m_strCalled); m_Connections.SetItemText(nIndex, CONNECTION_CALLING, dlg.m_strCalling); m_Connections.SetItemState(nIndex, LVIS_FOCUSED, LVIS_FOCUSED); m_Connections.SetItemState(nIndex, LVIS_FOCUSED|LVIS_SELECTED, LVIS_FOCUSED|LVIS_SELECTED); m_Connections.SetFocus(); } void CConnectList::OnModify() { CServerProp dlg; int i; for (i = 0; i < m_Connections.GetItemCount(); i++) { if (m_Connections.GetItemState(i, LVIS_SELECTED) == LVIS_SELECTED) { dlg.m_strName = m_Connections.GetItemText(i, CONNECTION_NAME); dlg.m_strHostAddress = m_Connections.GetItemText(i, CONNECTION_HOST_ADDRESS); dlg.m_strHostPort = m_Connections.GetItemText(i, CONNECTION_HOST_PORT); dlg.m_strPeerAddress = m_Connections.GetItemText(i, CONNECTION_PEER_ADDRESS); dlg.m_strPeerPort = m_Connections.GetItemText(i, CONNECTION_PEER_PORT); dlg.m_strCalled = m_Connections.GetItemText(i, CONNECTION_CALLED); dlg.m_strCalling = m_Connections.GetItemText(i, CONNECTION_CALLING); if (dlg.DoModal() != IDOK) { m_Connections.SetFocus(); return; } m_Connections.SetItemText(i, CONNECTION_NAME, dlg.m_strName); m_Connections.SetItemText(i, CONNECTION_HOST_ADDRESS, dlg.m_strHostAddress); m_Connections.SetItemText(i, CONNECTION_HOST_PORT, dlg.m_strHostPort); m_Connections.SetItemText(i, CONNECTION_PEER_ADDRESS, dlg.m_strPeerAddress); m_Connections.SetItemText(i, CONNECTION_PEER_PORT, dlg.m_strPeerPort); m_Connections.SetItemText(i, CONNECTION_CALLED, dlg.m_strCalled); m_Connections.SetItemText(i, CONNECTION_CALLING, dlg.m_strCalling); m_Connections.SetFocus(); break; } } } void CConnectList::OnDelete() { int i; for (i = 0; i < m_Connections.GetItemCount(); i++) { if (m_Connections.GetItemState(i, LVIS_SELECTED) == LVIS_SELECTED) { m_Connections.DeleteItem(i); m_Connections.SetItemState((i != m_Connections.GetItemCount()) ? i : i-1, LVIS_SELECTED | LVIS_FOCUSED, LVIS_SELECTED | LVIS_FOCUSED); m_Connections.SetFocus(); break; } } } void CConnectList::OnDblclkConnections(NMHDR* pNMHDR, LRESULT* pResult) { OnOK(); *pResult = 0; }