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

📄 configframe.cpp

📁 是自己开发的程序
💻 CPP
📖 第 1 页 / 共 2 页
字号:
#include <stdlib.h>#include <sys/socket.h>#include <netinet/in.h>#include <arpa/inet.h>#include "wx/tokenzr.h"#include "PicPanel.h"#include "ConfigFrame.h"#include "wx/artprov.h"#include "wx/listctrl.h"#include "wx/checkbox.h"#include "wx/brush.h"#include "wx/dc.h"#include "wx/dcclient.h"#include "wx/colour.h"#include "mainstore.xpm"#include "unsel.xpm"#include "sel.xpm"#include "check.xpm"#define MAX_WIN           32const int  ID_LOGIN      =143;const int  ID_RESTART    =144;const int  ID_SHUTDOWN   =145;const int  ID_NET        =146;const int  ID_IPLISTCHANGE = 147;const int ID_CHECKBOX1   =148;const int ID_CHECKBOX2   =149;const int ID_LISTFILE    =150;const int ID_SELALL      =151;const int ID_OUTPUT      =152;MYSQL		* myData =NULL;int curSel; typedef struct {	unsigned int	code;			//命令编号,该字段指明报文的类型	char	m_strText[128];		//逻辑机号}TRequest;TRequest pRequest[MAX_WIN];typedef struct {	int isCheck;	int server_type;	char server_ip[20];	char url[128];	char device[9];	int port;	char by1[256];	int by2;}TWinInfo;TWinInfo winInfo[MAX_WIN];BEGIN_EVENT_TABLE(ConfigFrame, wxFrame)    EVT_PAINT(ConfigFrame::OnPaint)    EVT_BUTTON    (ID_LOGIN,           ConfigFrame::OnMyButtons)    EVT_BUTTON    (ID_RESTART,         ConfigFrame::OnMyButtons)    EVT_BUTTON    (ID_SHUTDOWN,        ConfigFrame::OnMyButtons)	EVT_BUTTON    (ID_NET,             ConfigFrame::OnMyButtons)	EVT_BUTTON    (ID_SELALL,        ConfigFrame::OnMyButtons)	EVT_BUTTON    (ID_OUTPUT,        ConfigFrame::OnMyButtons)	EVT_COMBOBOX(ID_IPLISTCHANGE, ConfigFrame::OnSelectIPList)	EVT_CHECKBOX(ID_CHECKBOX1, ConfigFrame::OnCheckBox) 	EVT_CHECKBOX(ID_CHECKBOX2, ConfigFrame::OnCheckBox) 	EVT_LIST_ITEM_SELECTED(ID_LISTFILE, ConfigFrame::OnListFile) 	EVT_LIST_ITEM_DESELECTED(ID_LISTFILE, ConfigFrame::OnListFileUnsel)	EVT_LIST_ITEM_ACTIVATED(ID_LISTFILE , ConfigFrame::OnActived)	EVT_TREE_ITEM_ACTIVATED(TreeTest_Ctrl, ConfigFrame::OnSelChanged)	EVT_MENU(TreeTest_ToReady,ConfigFrame::OnMenuSelect)	EVT_MENU(TreeTest_ToDev,ConfigFrame::OnMenuSelect)END_EVENT_TABLE()wxString ConvertFromStrs(const char *raw){	wxString str;	wxCSConv conv(_("gb2312"));	return wxString(raw,conv);}int Minnumber(int x,int y){		return x>y?y:x;	}int Maxnumber(int x,int y){		return x>y?x:y;	}ConfigFrame::ConfigFrame(wxFrame *frame,                const wxPoint& point,                const wxSize& size,                long style)    : wxFrame(frame, -1, _(""),point,size,style), m_treeCtrl(NULL){	curSel = -1;	wxCSConv conv(_("gb2312"));	memset(&pRequest,0,sizeof(pRequest));	memset(&winInfo,0,sizeof(winInfo));	for(int i=0;i<MAX_WIN;i++)		winInfo[i].server_type = 2;    wxPanel* bg_panel = new wxPanel(this,-1,point,size);    wxBitmap headbitmap(mainstore_xpm);    headPanel = new PicPanel(bg_panel,wxPoint(0,0), wxSize(1024,768),headbitmap);	m_treeCtrl = new MyTreeCtrl(headPanel, TreeTest_Ctrl,                                wxPoint(635,75), wxSize(341,610),                                wxTR_DEFAULT_STYLE);			m_treeCtrl->SetWindowStyle(m_treeCtrl->GetWindowStyle() ^ wxTR_NO_LINES);	m_treeCtrl->SetBackgroundColour(wxColor(192,191,251));	// 列表控件	listCtrlReport = new wxListCtrl(		headPanel , ID_LISTFILE, wxPoint(44,141), wxSize(566, 490),		wxLC_REPORT|wxLC_SINGLE_SEL);	// 图象列表	wxImageList *imageList = new wxImageList(16, 16, true, 1);	wxBitmap listicon0(unsel_xpm);	wxBitmap listicon1(sel_xpm);	wxBitmap listicon2(check_xpm);	imageList->Add(listicon0);	imageList->Add(listicon1);	imageList->Add(listicon2);	//listCtrlReport->SetImageList(imageList, wxIMAGE_LIST_NORMAL);    listCtrlReport->SetImageList(imageList, wxIMAGE_LIST_SMALL);	//listCtrlReport->SetBackgroundColour(wxColor(241,243,250));	wxListItem itemCol;	itemCol.SetAlign(wxLIST_FORMAT_CENTRE);	itemCol.SetText(wxString("状态",conv));	//itemCol.SetImage(-1);	listCtrlReport->InsertColumn(0, itemCol);	listCtrlReport->SetColumnWidth(0, 37 );		itemCol.SetText(wxString("监视位置",conv));	listCtrlReport->InsertColumn(1, itemCol);	listCtrlReport->SetColumnWidth(1, 80 );	itemCol.SetText(wxString("关联设备",conv));	listCtrlReport->InsertColumn(2, itemCol);	listCtrlReport->SetColumnWidth(2, 120/* wxLIST_AUTOSIZE */ );	itemCol.SetText(wxString("关联地址",conv));	listCtrlReport->InsertColumn(3, itemCol);	listCtrlReport->SetColumnWidth(3, 315/* wxLIST_AUTOSIZE */ );	m_radioHAlign = new wxCheckBox(headPanel, ID_CHECKBOX1, _T(""),                                   wxPoint(108,68), wxDefaultSize);    m_radioVAlign = new wxCheckBox(headPanel, ID_CHECKBOX2, _T(""),                                   wxPoint(299,68), wxDefaultSize);	m_radioHAlign->SetValue(1);	m_radioVAlign->SetValue(0);	m_radioHAlign->SetBackgroundColour(wxColor(241,243,250));	m_radioVAlign->SetBackgroundColour(wxColor(241,243,250));    button1 = new wxButton(headPanel,ID_LOGIN,wxString("登录界面",conv),wxPoint(36,716),wxSize(150,30));	button2 = new wxButton(headPanel,ID_NET,wxString("网络配置",conv),wxPoint(296,716),wxSize(150,30));    button3 = new wxButton(headPanel,ID_RESTART,wxString("重启系统",conv),wxPoint(571,716),wxSize(150,30));    button4 = new wxButton(headPanel,ID_SHUTDOWN,wxString("关闭系统",conv),wxPoint(831,716),wxSize(150,30));	buttonSel = new wxButton(headPanel,ID_SELALL,wxString("全选",conv),wxPoint(54,655),wxSize(70,25));	buttonOut = new wxButton(headPanel,ID_OUTPUT,wxString("输出",conv),wxPoint(529,655),wxSize(70,25));    m_panel = new wxPanel(bg_panel,-1,wxPoint(35,60),wxSize(944,636));    	m_panel->SetBackgroundColour(wxColor(241,243,250));    loginPage = new LoginPanel(m_panel,wxDefaultPosition, wxDefaultSize,0);	loginPage->SetBackgroundColour(wxColor(241,243,250));    networkPage = new NetworkPanel(m_panel,wxDefaultPosition, wxDefaultSize,0);	networkPage->SetBackgroundColour(wxColor(241,243,250));    m_sizerFrame = new wxBoxSizer(wxVERTICAL);    m_sizerFrame->Add(loginPage, 0, wxEXPAND);	m_sizerFrame->Add(networkPage, 1, wxEXPAND);    ShowLoginPage();		    m_panel->SetSizer(m_sizerFrame);		}void ConfigFrame::OnMenuSelect(wxCommandEvent& event){	switch(event.GetId())	{		case TreeTest_ToDev:			m_treeCtrl->InitTree();			break;		case TreeTest_ToReady:			m_treeCtrl->InitTrees();			break;		default:			break;	}}void ConfigFrame::OnActived(wxListEvent &event){	//2007-07-27 修改全选的BUG	long selItem = event.GetIndex();	if(winInfo[selItem].port > 0)	{		if(winInfo[selItem].isCheck ==0)			winInfo[selItem].isCheck = 2;		else			winInfo[selItem].isCheck = 0;	}	listCtrlReport->SetItemImage(selItem,winInfo[selItem].isCheck);}void ConfigFrame::OnSelChanged(wxTreeEvent& event){	//选择树型目录	if(curSel == -1)		return;	int i = 0;	long val;	long curSels = curSel;	wxCSConv conv(_("gb2312"));	wxString url,chan,devid,devname;	wxTreeItemId id = event.GetItem();	MyTreeItemData *iData = (MyTreeItemData *)m_treeCtrl->GetItemData(id);	wxString desc = iData->GetDesc();	if(desc.Contains(_T("AllSelected,")))	{		wxString str= odc2->GetValue(); 		if(str.Contains(wxString("服务器IP地址",conv)))		{			wxMessageBox(wxString("请选择服务器IP地址!",conv),wxString("警告",conv),wxOK|wxCENTRE,this,460,300);			return;		}		wxTreeItemIdValue cookie;		wxTreeItemId sid;		sid = m_treeCtrl->GetFirstChild(id,cookie);		while(sid.IsOk())		{			iData = (MyTreeItemData *)m_treeCtrl->GetItemData(sid);			desc = iData->GetDesc();			if(desc.Contains(_T("rtsp://")))			{				wxStringTokenizer tkz(desc, wxT(","));				i=0;				while ( tkz.HasMoreTokens() )				{					wxString token = tkz.GetNextToken();					if(i==0)						url = token;					if(i==1)						chan = token;					if(i==2)						devid = token;					if(i==3)						devname = token;								i++;				}								chan.ToLong(&val);				wxString strDev,strTemp;				strTemp.Printf(wxString("[第 %ld 路]",conv),val+1);				strDev = devname  + strTemp;								listCtrlReport->SetItem(curSels,2,strDev);				listCtrlReport->SetItem(curSels,3,url);				listCtrlReport->SetItemImage(curSels,0);				memset(&pRequest[curSels],0,sizeof(TRequest));				memset(&winInfo[curSels],0,sizeof(TWinInfo));				if(m_radioHAlign->GetValue() == 1)					winInfo[curSels].server_type = 2;				else					winInfo[curSels].server_type = 3;				sprintf(winInfo[curSels].by1,"%s",(const char *)strDev.mb_str(conv));				sprintf(winInfo[curSels].server_ip,"%s",(const char *)(odc2->GetValue()).mb_str(wxConvUTF8));				sprintf(winInfo[curSels].url,"%s",(const char *)url.mb_str(wxConvUTF8));				sprintf(winInfo[curSels].device,"%s",(const char *)devid.mb_str(wxConvUTF8));				winInfo[curSels].port = curSels + 1;				winInfo[curSels].by2 = val;				pRequest[curSels].code = curSels +1;				sprintf(pRequest[curSels].m_strText,"%s",(const char *)url.mb_str(wxConvUTF8));				curSels = curSels + 1;			}			sid = m_treeCtrl->GetNextChild(id,cookie);		}		return;	}	if(desc.Contains(_T("rtsp://")))	{				wxString str= odc2->GetValue();		if(str.Contains(wxString("服务器IP地址",conv)))		{			wxMessageBox(wxString("请选择服务器IP地址!",conv),wxString("警告",conv),wxOK|wxCENTRE,this,460,300);			return;		}		wxStringTokenizer tkz(desc, wxT(","));		i = 0;		while ( tkz.HasMoreTokens() )		{			wxString token = tkz.GetNextToken();			if(i==0)				url = token;			if(i==1)				chan = token;			if(i==2)				devid = token;			if(i==3)				devname = token;						i++;		}		chan.ToLong(&val);		wxString strDev,strTemp;		strTemp.Printf(wxString("[第 %ld 路]",conv),val+1);		strDev = devname  + strTemp;				listCtrlReport->SetItem(curSel,2,strDev);		listCtrlReport->SetItem(curSel,3,url);		listCtrlReport->SetItemImage(curSel,0);		memset(&pRequest[curSel],0,sizeof(TRequest));		memset(&winInfo[curSel],0,sizeof(TWinInfo));		if(m_radioHAlign->GetValue() == 1)			winInfo[curSel].server_type = 2;		else			winInfo[curSel].server_type = 3;		sprintf(winInfo[curSel].by1,"%s",(const char *)strDev.mb_str(conv));		sprintf(winInfo[curSel].server_ip,"%s",(const char *)(odc2->GetValue()).mb_str(wxConvUTF8));		sprintf(winInfo[curSel].url,"%s",(const char *)url.mb_str(wxConvUTF8));		sprintf(winInfo[curSel].device,"%s",(const char *)devid.mb_str(wxConvUTF8));		winInfo[curSel].port = curSel + 1;		winInfo[curSel].by2 = val;		pRequest[curSel].code = curSel +1;		sprintf(pRequest[curSel].m_strText,"%s",(const char *)url.mb_str(wxConvUTF8));	}}void ConfigFrame::InitIPList(){	curSel = -1;		memset(&pRequest,0,sizeof(pRequest));	memset(&winInfo,0,sizeof(winInfo));	listCtrlReport->DeleteAllItems();		m_arrItems.Clear();	if(odc2)		delete odc2;	wxCSConv conv(_("gb2312"));	m_arrItems.Add( wxString("服务器IP地址列表...",conv) );	MYSQL_ROW	row ;	MYSQL_RES	* res;	int devCount;	char szSQL[256];	memset(szSQL,0,sizeof(szSQL));	if(m_radioHAlign->GetValue() == 1)		strcpy(szSQL,"select server_ip from serveriplist where server_code=2");	else		strcpy(szSQL,"select server_ip from serveriplist where server_code=3");	if ( ! mysql_query( myData, szSQL ) ) {		res = mysql_store_result( myData ) ;		devCount = (int) mysql_num_rows( res ) ; 		while ( (row = mysql_fetch_row( res )) ) {			m_arrItems.Add(wxString(row[0],wxConvUTF8));		}		if(res)			mysql_free_result(res);	}        odc2 = new wxOwnerDrawnComboBox(headPanel,ID_IPLISTCHANGE,wxEmptyString,                                    wxPoint(200,97), wxDefaultSize,                                    m_arrItems,                                    wxNO_BORDER | wxCB_READONLY //(long)0 //                                   );	odc2->SetSelection(0);		odc2->SetBackgroundColour(wxColor(241,243,250));}void ConfigFrame::OnListFile(wxListEvent &event){	long selItem = event.GetIndex();	//listCtrlReport->SetItemImage(selItem,1);	curSel = selItem;}

⌨️ 快捷键说明

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