?? dlgipalias.cpp
字號:
// DlgIPAlias.cpp : implementation file
//
#include "stdafx.h"
#include "../dvrmanager.h"
#include "DlgIPAlias.h"
#include "../net/ip_alias.h"
#include "msgbox.h"
#include "reg.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CDlgIPAlias dialog
LPCTSTR rvAutoClose = _T("IPDlgAutoClose");
#define m_simple (*GetDlgItem(IDBTN_SIMPLE))
#define m_btn_detail (*GetDlgItem(IDBTN_DETAIL))
//##ModelId=3F90BABB01BD
CDlgIPAlias::CDlgIPAlias(CWnd* pParent /*=NULL*/)
: base(CDlgIPAlias::IDD, pParent), ipmgr(NULL), caller(NULL)
{
//{{AFX_DATA_INIT(CDlgIPAlias)
m_strAlias = _T("");
m_ip = _T("");
m_autoclose = FALSE;
//}}AFX_DATA_INIT
ft.CreatePointFont(100, _T("Fixedsys"), NULL);
set_sepid(ID_SEP);
m_autoclose = read_dword(rkSettings, rvAutoClose, 1);
}
//##ModelId=3F90BABB0222
void CDlgIPAlias::DoDataExchange(CDataExchange* pDX)
{
base::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CDlgIPAlias)
DDX_Control(pDX, IDCB_IPS, m_cbIPs);
DDX_Control(pDX, ID_LIST, m_lst);
DDX_Text(pDX, IDED_ALIAS, m_strAlias);
DDX_CBString(pDX, IDCB_IPS, m_ip);
DDX_Check(pDX, IDCK_AUTO_CLOSE, m_autoclose);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CDlgIPAlias, base)
//{{AFX_MSG_MAP(CDlgIPAlias)
ON_BN_CLICKED(IDBTN_ADD, OnAdd)
ON_BN_CLICKED(IDBTN_CLEAR, OnClear)
ON_LBN_SELCHANGE(ID_LIST, OnSelchangeList)
ON_CBN_SELCHANGE(IDCB_IPS, OnSelchangeIps)
ON_BN_CLICKED(IDBTN_REMOVE, OnRemove)
ON_LBN_DBLCLK(ID_LIST, OnDblclkList)
ON_BN_CLICKED(ID_APPLY_NOW, OnApplyNow)
ON_BN_CLICKED(IDBTN_DETAIL, OnDetail)
ON_BN_CLICKED(IDBTN_SIMPLE, OnSimple)
ON_BN_CLICKED(IDCK_AUTO_CLOSE, OnAutoClose)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CDlgIPAlias message handlers
//##ModelId=3F90BABB022D
BOOL CDlgIPAlias::OnInitDialog()
{
base::OnInitDialog();
CString ip = m_ip;
m_lst.SetFont(&ft);
update_list();
simple();
/*
* 添加別名
*/
if( !ip.IsEmpty() )
{
m_ip = ip;
m_strAlias.Empty();
UpdateData(FALSE);
}
/*
if( m_ip.IsEmpty() )
m_cbIPs.GetLBText(0, m_ip);
else
{
m_cbIPs.SetWindowText(ip);
m_strAlias.Empty();
}
UpdateData(FALSE);
*/
return TRUE; // return TRUE unless you set the focus to a control
// EXCEPTION: OCX Property Pages should return FALSE
}
// 更新ListBox
//##ModelId=3F90BABB0197
void CDlgIPAlias::update_list()
{
m_lst.ResetContent();
m_cbIPs.ResetContent();
m_strAlias.Empty();
UpdateData(FALSE);
for( int i=0; i<ipmgr->count(); i++ )
{
ip_alias& ref = ipmgr->get(i);
CString insert;
CString combine;
int idx = 0;
combine = ref.get_ip_port();
insert.Format(IDS_IP_ALIAS_FORMAT, ref.get_alias(), combine );
idx = m_lst.AddString(insert);
m_cbIPs.AddString(combine);
m_lst.SetItemData(idx, i);
m_cbIPs.SetItemData(idx, i);
}
m_cbIPs.SetCurSel(0);
update_info();
}
// 更新ComboBox, EditBox
//##ModelId=3F90BABB019F
void CDlgIPAlias::update_info()
{
// combine = ipmgr->get(cur_sel).get_combine();
CString str;
int idx = m_cbIPs.GetCurSel();
if( idx == -1 )
return;
m_cbIPs.GetLBText(idx, m_ip);
if( m_ip.IsEmpty() )
m_cbIPs.GetWindowText(m_ip);
if( m_ip.IsEmpty() )
return;
m_strAlias = ipmgr->get_alias(ip_port(m_ip));
UpdateData(FALSE);
}
// 添加一個新項
//##ModelId=3F90BABB0237
void CDlgIPAlias::OnAdd()
{
UpdateData();
CString strIP;
m_cbIPs.GetWindowText(strIP);
if( strIP.IsEmpty() ||
m_strAlias.IsEmpty() )
{
msgbox(IDS_ALIAS_EMPTY, IDS_ALIAS_EMPTY_TITLE, MB_OK | MB_ICONWARNING, this);
return;
}
ip_alias ia(m_strAlias, strIP);
if( ia.look_port() == 0 )
ia = ip_alias(m_strAlias, strIP+_T(":8101"));
if( duplicated(ia) )
{
return;
}
ia.save_to_reg();
ipmgr->update();
update_list();
}
// 判斷將要添加的項是否有重名
//##ModelId=3F90BABB01A9
bool CDlgIPAlias::duplicated(ip_alias& ia)
{
for( int i=0; i<ipmgr->count(); i++ )
{
ip_alias& ref = ipmgr->get(i);
/*
添加/修改的幾種可能:
1. alias 不存在, 添加
2. alias 不存在, 但IP與PORT相同, 修改 alias
3. alias 存在, 但IP或PORT不同, 修改 IP與PORT
4. alias, IP, PORT均相同, 什么也不作
*/
if( ref.get_alias().CompareNoCase(ia.get_alias()) == 0 ) // alias 存在
{
if( ref == ia ) // 全部相同, (4)
return true;
}
if( ref == ia ) // IP與PORT相同, 且 alias 不存在
{
ref.remove_from_reg(); // 修改alias, (2)
break;
}
}
// alias 不存在
// (1), (3)
return false;
}
// 清除所有別名
//##ModelId=3F90BABB0241
void CDlgIPAlias::OnClear()
{
if( IDOK != msgbox(IDS_ALIAS_CLEAR, IDS_ALIAS_CLEAR_TITLE, MB_OKCANCEL | MB_ICONQUESTION, this) )
return;
ipmgr->clear();
update_list();
}
// 當ListBox選擇改變時
//##ModelId=3F90BABB024B
void CDlgIPAlias::OnSelchangeList()
{
int idx=m_lst.GetCurSel();
if( idx != -1 )
{
idx = m_lst.GetItemData(idx);
for( int i=0; i<m_cbIPs.GetCount(); i++ )
{
if( m_cbIPs.GetItemData(i) == idx )
{
m_cbIPs.SetCurSel(i);
break;
}
}
}
update_info();
}
// 當ComboBox選擇改變時
//##ModelId=3F90BABB0254
void CDlgIPAlias::OnSelchangeIps()
{
update_info();
}
// 刪除一項
//##ModelId=3F90BABB025E
void CDlgIPAlias::OnRemove()
{
UpdateData();
CString strIP;
m_cbIPs.GetWindowText(strIP);
if( strIP.IsEmpty() )
return;
ipmgr->remove_by_alias(m_strAlias);
update_list();
}
//##ModelId=3F90BABB0268
void CDlgIPAlias::OnDblclkList()
{
OnApplyNow();
}
//##ModelId=3F90BABB0272
void CDlgIPAlias::OnApplyNow()
{
UpdateData();
caller->SendMessage(WM_CONNECT, (WPARAM)(LPCTSTR)m_strAlias);
if( m_autoclose )
base::OnOK();
}
//##ModelId=3F90BABB027C
void CDlgIPAlias::OnDetail()
{
detail();
m_simple.ShowWindow(SW_SHOW);
m_btn_detail.ShowWindow(SW_HIDE);
}
//##ModelId=3F90BABB027E
void CDlgIPAlias::OnSimple()
{
simple();
m_simple.ShowWindow(SW_HIDE);
m_btn_detail.ShowWindow(SW_SHOW);
}
//##ModelId=3F90BABB0287
void CDlgIPAlias::OnAutoClose()
{
UpdateData();
write_dword(rkSettings, rvAutoClose, m_autoclose);
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -