⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ~rightlogin.~cpp

📁 实时监控
💻 ~CPP
📖 第 1 页 / 共 2 页
字号:
		if( ::GetDlgCtrlID(pMsg->hwnd) == IDED_LOGINIP ||
			::GetDlgCtrlID(pMsg->hwnd) == IDED_PASSWORD )
		{
			if( pMsg->wParam == VK_RETURN )
			{
				OnLogin();
				return TRUE;
			}
		}
	}
	if( pMsg->message == WM_LBUTTONUP &&
		pMsg->hwnd == m_lstLogged.m_hWnd )
	{
		UpdateData(FALSE);
	}
	bool right = false;
	if( pMsg->hwnd == m_lstLogged.m_hWnd )
	{
		if( pMsg->message == WM_RBUTTONDOWN )
		{
			pMsg->message = WM_LBUTTONDOWN;
			right = true;
		}
	}
	BOOL res = baseclass::PreTranslateMessage(pMsg);
	if( right )
	{
		OnRightClickList();
	}
	return res;
}

/*
 *	鼠标右键点击登录项的处理(弹出菜单)
 */
void CRightLogin::OnRightClickList()
{
	popup_menu pm;
	int idx = m_lstLogged.GetCurSel();
	if( idx == -1 )
		return;

	// 从ListBox查找选中项
	idx = m_lstLogged.GetItemData(idx);

	// 在内部列表中查找
	channel_info& ref = cmgr[idx];

	// 准备菜单
	for( int i=0; i<ref.get_channels(); i++ )
	{
		CString str;
		str.Format(IDS_CHNL_FMT, i+1);
		pm.add_item(str, i+1);
		
		// 如果该路已打开, 则标示菜单项
		if( ref.is_opened(i) )
			pm.select_item(i);
	}

	// 这里返回sel的值基值为1, 如果为0则说明菜单中没有项目选中
	UINT sel = pm.popup(this);
	if( sel == 0 )
		return;

	open_channel(ref, sel-1);
}

#include "msgbox.h"
/*
 *	打开视频通道(由右键菜单调用)
 */
void CRightLogin::open_channel(channel_info& ci, int channel)
{
	// 真正的视频通道号
	channel_info* ci1 = cmgr.find(ci.get_ip_port());
	if( !ci1 )
		return;
	
	if( ci1->is_opened(channel) )
	{
		msgbox(IDS_CHNL_OPENED, IDS_WARNING, MB_OK|MB_ICONWARNING, this);
		return;
		
	}
	
	video_channel* p = video_channel::current_sel();
	if( p->is_video_opened() )
	{
		msgbox(IDS_CHNL_OPENED, IDS_WARNING, MB_OK|MB_ICONWARNING, this);
		return;
		//if( IDOK != msgbox(IDS_CHANNEL_OPENED, IDS_QUESTION, MB_OKCANCEL|MB_ICONQUESTION, this) )
		//	return;

//		OnClose();
//		Sleep(500);
	}
	
	// 加入多播
	net_open_remote_channel(net, 
		ci.get_ip(), 
		ci.look_port(), 
		channel, 
		p->index(),
		p->m_hWnd);
}

/*
 *	处理UpdateData请求
 *	在某些线程中, 同步调用UpdateData会出错.
 *	所以必须用PostMessage(WM_UPDATE_DATA, ?)
 *	?: TRUE, FALSE
 */
// WM_UPDATE_DATA
LRESULT CRightLogin::OnUpdateData(WPARAM w, LPARAM)
{
	UpdateData(w);
//	SetDlgItemText(ID_VIDEO_TITLE, m_strVideoTitle);
//	SetDlgItemText(ID_CHANNEL_IP, m_strChannelIP);
//	SetDlgItemText(ID_CHANNEL_INDEX, m_strChannelIndex);
	return 0;
}

/*
 *	登录列表框更改选择的处理
 */
void CRightLogin::OnSelchangeList()
{
	int idx = m_lstLogged.GetCurSel();
	if( idx == -1 )
		return;
	idx = m_lstLogged.GetItemData(idx);

	channel_info& ref = cmgr[idx];
	m_loginip = ipmgr.get_alias(ref.get_ip_port());
	UpdateData(FALSE);
}

/*
 *	Close按钮响应, 关闭某个视频通道
 */
void CRightLogin::OnClose()
{
	video_channel* p = video_channel::current_sel();
	if( !p->is_video_opened() )
		return;

	if( p->is_vod() )
	{
		on_close_vod(0,0);
		return;
	}

	/*
	 *	p->channel_index() : 得到该窗口打开的视频通道(主机端)
	 */
	net_close_local_channel(net, p->index());
}

/*
 *	Close Remote按钮响应, 关闭主机视频通道, 并关闭本地视频通道
 */
void CRightLogin::OnCloseRemote() 
{
	video_channel* p = video_channel::current_sel();
	if( !p->is_video_opened() )
		return;

	/*
	 *	p->channel_index() : 得到该窗口打开的视频通道(主机端)
	 */
	net_close_remote_channel(net, p->index());

	OnClose();
}

/*
 *	处理从CDlgIPMoniker来的别名登录消息
 */
LRESULT CRightLogin::OnConnect(WPARAM w, LPARAM)
{
	LPCTSTR ip = (LPCTSTR)w;
	m_loginip = ip;
	UpdateData(FALSE);
	OnLogin();
	return 0;
}

CString CRightLogin::alias(const channel_info& ci)
{
	return ipmgr.get_alias(ci.get_ip_port());
}
//DEL BOOL CRightLogin::OnEraseBkgnd(CDC* pDC) 
//DEL {
//DEL 	return TRUE;
//DEL }

void fill_combo(CComboBox* cbb)
{
	if( !cbb )
		return;

	cbb->ResetContent();
	CRightLogin* rlogin = CRightLogin::the_one();

	for( int i=0; i<rlogin->cmgr.count(); i++ )
	{
		cbb->AddString(rlogin->alias(rlogin->cmgr[i]));
	}
}

void fill_combo_chnls(LPCTSTR alias, CComboBox* cbb)
{
	if( !cbb )
		return;

	cbb->ResetContent();
	int cnt = get_chnls(alias);
	if( !cnt )
		return;

	for( int i=0; i<cnt; i++ )
	{
		CString str;
		str.Format(IDS_CHNL_FMT, i+1);
		cbb->AddString(str);
	}
}

void fill_combo_inputs(LPCTSTR alias, CComboBox* cbb)
{
	if( !cbb )
		return;
	
	cbb->ResetContent();
	int cnt = get_chnls(alias);
	if( !cnt )
		return;
	
	for( int i=0; i<cnt; i++ )
	{
		CString str;
		str.Format(IDS_INPUT_FMT, i+1);
		cbb->AddString(str);
	}
}

void get_addr(LPCTSTR alias, ULONG& ip, USHORT& port)
{
	CRightLogin* l = CRightLogin::the_one();
	ip_port ipp = l->ipmgr.trans_ip(alias);

	ip = ipp.get_ip();
	port = ipp.look_port();
}

void set_net_opt(LPCTSTR alias, DWORD opt, void* stuff, 
				 OPT_SET_CALLEE cb)
{
	CRightLogin* l = CRightLogin::the_one();
	ULONG ip;
	USHORT port;
	get_addr(alias, ip, port);

	net_set_options(l->net, ip, port, (NET_OPTIONS)opt, stuff, cb);
}

void get_net_opt(LPCTSTR alias, DWORD opt, int channel, OPT_GET_CALLEE cb)
{
	CRightLogin* l = CRightLogin::the_one();
	ULONG ip;
	USHORT port;
	get_addr(alias, ip, port);
	
	net_get_options(l->net, ip, port, (NET_OPTIONS)opt, channel, cb);
}

int get_chnls(ULONG ip, USHORT port)
{
	CRightLogin* l = CRightLogin::the_one();
	return get_chnls(l->ipmgr.get_alias(ip, port));
}
int get_chnls(LPCTSTR alias)
{
	CRightLogin* l = CRightLogin::the_one();
	ip_port ipp = l->ipmgr.trans_ip(alias);
	channel_info* ci = l->cmgr.find(ipp);
	if( !ci )
		return 0;
	return ci->get_channels();
}

CString get_alias(const ip_port& ipp)
{
	CRightLogin* l = CRightLogin::the_one();
	return l->ipmgr.get_alias(ipp.get_ip(), ipp.look_port());
}

void start_bk(LPCTSTR alias, void* opt, BACKUP_CALLEE cb)
{
	CRightLogin* l = CRightLogin::the_one();
	ip_port ipp = l->ipmgr.trans_ip(alias);

	net_start_backup(l->net, ipp.get_ip(), ipp.look_port(), 
		(TREC_BACKUPTIME*)opt, 
		cb);
}

void stop_bk()
{
	CRightLogin* l = CRightLogin::the_one();
	net_stop_backup(l->net);
}

PRIVILEGE get_priv(ULONG ip, USHORT port)
{
	CRightLogin* l = CRightLogin::the_one();
	return net_get_privilege(l->net, ip, port);
}

/*
 *	从CRightVOD传来
 */
LRESULT CRightLogin::on_open_vod(WPARAM w, LPARAM l)
{
	video_channel* vc = video_channel::current_sel();
	if( vc->is_video_opened() )
	{
		if( IDOK != msgbox(IDS_CHANNEL_OPENED, IDS_QUESTION, MB_OKCANCEL|MB_ICONQUESTION, this) )
			return 0;
		OnClose();
		Sleep(100);
	}

	ip_port* ipp = (ip_port*)l;
	net_start_vod(
		net, 
		ipp->get_ip(), 
		ipp->look_port(), 
		(TREC_FILETIME*)w, 
		video_channel::current_sel()->index(),
		video_channel::current_sel()->m_hWnd);

	return 0;
}

LRESULT CRightLogin::on_close_vod(WPARAM, LPARAM)
{
	net_stop_vod(net);
	return 0;
}

LRESULT CRightLogin::on_set_vod_speed(WPARAM w, LPARAM)
{
	net_set_vod_speed(net, (VOD_SPEED)w);
	return 0;
}

LRESULT CRightLogin::on_local_rec(WPARAM w, LPARAM l)
{
	BOOL begin = LOWORD(w);
	TCHAR drive = HIWORD(w);

	video_channel* vc = (video_channel*)l;

	int group = 0;
//	if( vc->is_vod() )
//		group = VOD_GROUP;
//	else
		group = vc->index();

	if( begin )
		net_start_local_record(net, group, drive);
	else
		net_stop_local_record(net, group);

	return 0;
}

#include "rightlocal.h"
LRESULT CRightLogin::on_snapshot(WPARAM, LPARAM)
{
	int group = video_channel::current_sel()->index();
	CString fmt;
	CString file;
	fmt.LoadString(IDS_SNAP_BMP_FILE_FMT);
	file = CRightLocal::the_one()->m_snappath;
	file += CTime::GetCurrentTime().Format(fmt);
	recursive_create_dir(file);
	
	net_snapshot(net, group, file);

	return 0;
}

/*
 *	查看某主机上的某路通道被哪个视频窗口打开
 *	如果没打开,返回NULL
 */
video_channel* who_opened_it(LPCTSTR alias, int channel)
{
	CRightLogin* l = CRightLogin::the_one();
	ip_port ipp = l->ipmgr.trans_ip(alias);
	channel_info* ci = l->cmgr.find(ipp);
	if( ci )
	{
		if( ci->is_opened(channel) )
		{
			return (video_channel*)ci->who(channel);
		}
	}
	return NULL;
}

LRESULT CRightLogin::on_video_wnd(WPARAM w, LPARAM l)
{
	UINT msg = l;
	video_channel* vc = (video_channel*)w;
	if( vc->is_video_opened() )
	{
		net_switch_audio(net, vc->index());
	}
	return 0;
}

LRESULT CRightLogin::on_get_vod_speed(WPARAM, LPARAM)
{
	return net_get_vod_speed(net);
}

LRESULT CRightLogin::on_get_local_rec(WPARAM w, LPARAM)
{
	return net_get_local_record(net, w);
}
LRESULT CRightLogin::on_update_wnd(WPARAM w, LPARAM)
{
	net_update_window(net, w);
	return 0;
}
void CRightLogin::OnChangeLoginip() 
{
	// TODO: If this is a RICHEDIT control, the control will not
	// send this notification unless you override the baseclass::OnInitDialog()
	// function and call CRichEditCtrl().SetEventMask()
	// with the ENM_CHANGE flag ORed into the mask.
	
	// TODO: Add your control notification handler code here

	UpdateData();
}

LRESULT CRightLogin::on_alarm(WPARAM addr, LPARAM data)
{
	return AfxGetMainWnd()->SendMessage(NTM_ALARM, addr, data);
}

LRESULT CRightLogin::on_mute(WPARAM w, LPARAM l)
{
	if(net)
	{
		BOOL muted = net_is_muted(net);
		net_mute_audio(net, !muted);
		return !muted;
	}
	return 0;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -