ServiceManageDlg.cpp
资源名称:Visualhk.rar [点击查看]
上传用户:cjw5120
上传日期:2022-05-11
资源大小:5032k
文件大小:8k
源码类别:
网络截获/分析
开发平台:
Visual C++
- // ServiceManageDlg.cpp : implementation file
- //
- #include "stdafx.h"
- #include "MyClient.h"
- #include "ServiceManageDlg.h"
- #include "resource.h"
- #include "TcpTran.h"
- #include "ServiceManageEditDlg.h"
- /*
- 作者:海啸 lyyer English Name: Jack
- blog:http://lyyer.blog.sohu.com
- website:http://www.cnGSG.com
- 海啸网络安全组织
- */
- #include "comm.h"
- #ifdef _DEBUG
- #define new DEBUG_NEW
- #undef THIS_FILE
- static char THIS_FILE[] = __FILE__;
- #endif
- /////////////////////////////////////////////////////////////////////////////
- // CServiceManageDlg dialog
- CServiceManageDlg *m_servicemanagedlg = NULL;
- static int Svritem = 0;
- //void OnStartManageService();
- CServiceManageDlg::CServiceManageDlg(CWnd* pParent /*=NULL*/)
- : CDialog(CServiceManageDlg::IDD, pParent)
- {
- //{{AFX_DATA_INIT(CServiceManageDlg)
- // NOTE: the ClassWizard will add member initialization here
- //}}AFX_DATA_INIT
- m_servicemanagedlg = this;
- }
- void CServiceManageDlg::DoDataExchange(CDataExchange* pDX)
- {
- CDialog::DoDataExchange(pDX);
- //{{AFX_DATA_MAP(CServiceManageDlg)
- DDX_Control(pDX, IDC_LIST, m_list);
- //}}AFX_DATA_MAP
- }
- DWORD WINAPI InitListService(std::vector<SERVICEINFO *> pServInfo)
- {
- m_servicemanagedlg->m_list.DeleteAllItems();
- for(DWORD i = 0; i < pServInfo.size(); i++)
- {
- CString tmp = _T("");
- /*
- tmp.Format("%d",pServInfo[i]->num); //****得到vector[i] 里的结构的一部分**** //pVecTor->at(i).PID
- m_servicemanagedlg->m_list.InsertItem(i,"");
- m_servicemanagedlg->m_list.SetItemText(i,0,tmp);
- */
- tmp.Format("%s",pServInfo[i]->ServiceName);
- m_servicemanagedlg->m_list.InsertItem(i,(const char *)0);
- m_servicemanagedlg->m_list.SetItemText(i,0,tmp);
- tmp.Format("%s",pServInfo[i]->ServiceDetail);
- m_servicemanagedlg->m_list.InsertItem(i,(const char *)1);
- m_servicemanagedlg->m_list.SetItemText(i,1,tmp);
- tmp.Format("%s",pServInfo[i]->ServiceState);
- m_servicemanagedlg->m_list.InsertItem(i,(const char *)2);
- m_servicemanagedlg->m_list.SetItemText(i,2,tmp);
- tmp.Format("%s",pServInfo[i]->ServiceStartType);
- m_servicemanagedlg->m_list.InsertItem(i,(const char *)3);
- m_servicemanagedlg->m_list.SetItemText(i,3,tmp);
- /* */
- }
- return 0;
- }
- void OnServiceStart()
- {
- COMMAND m_command;
- int len = 0;
- //extern SOCKET g__clientsocket ;
- memset((char *)&m_command, 0,sizeof(m_command));
- m_command.wCmd = CMD_SERVICE_MANAGE;
- m_command.DataSize = 0;
- CTcpTran m_tcptran ;
- int sbuf = 0;
- len = m_tcptran.mysend(m_servicemanagedlg->ClientSocket,(char *)&m_command,sizeof(m_command),0,60);
- if (len<0)
- {
- len = m_tcptran.mysend(m_servicemanagedlg->ClientSocket,(char *)&m_command,sizeof(m_command),0,60);
- }
- int servicelen = m_tcptran.myrecv(m_servicemanagedlg->ClientSocket,(char *)&sbuf,sizeof(int),0,60,NULL,false);
- if (servicelen>0)
- {
- std::vector<SERVICEINFO *> pServiceInfo;
- SERVICEINFO *tmp = new SERVICEINFO; //一样的问题
- //
- for(int i=0;i<sbuf;i++)
- {
- tmp = new SERVICEINFO;
- memset(tmp, 0,sizeof(SERVICEINFO));
- m_tcptran.myrecv(m_servicemanagedlg->ClientSocket,(char *)tmp,sizeof(SERVICEINFO),0,60,0,false);
- pServiceInfo.push_back(tmp);
- //delete tmp;
- }
- /*
- for(int jj = 0;jj<pServiceInfo.size();jj++)
- {
- AfxMessageBox(pServiceInfo[jj]->ServiceName);
- }
- */
- InitListService(pServiceInfo);
- }
- }
- BOOL CServiceManageDlg::OnInitDialog()
- {
- CDialog::OnInitDialog();
- // TODO: Add extra initialization here
- LONG mlStyle = m_list.SendMessage(LVM_GETEXTENDEDLISTVIEWSTYLE);
- mlStyle |= LVS_EX_FULLROWSELECT | LVS_EX_GRIDLINES | LVS_EX_HEADERDRAGDROP;
- m_list.SendMessage(LVM_SETEXTENDEDLISTVIEWSTYLE, 0,(LPARAM)mlStyle);
- LV_COLUMN lvc;
- lvc.mask = LVCF_TEXT | LVCF_SUBITEM | LVCF_WIDTH /*| LVCF_FMT*/;
- m_list.DeleteAllItems();
- //m_list.InsertColumn(0,"编号",LVCFMT_LEFT,50);
- m_list.InsertColumn(0,"服务名称",LVCFMT_LEFT,120);
- m_list.InsertColumn(1,"描述",LVCFMT_LEFT,270);
- m_list.InsertColumn(2,"状态",LVCFMT_LEFT,80);
- m_list.InsertColumn(3,"启动类型",LVCFMT_LEFT,80);
- OnServiceStart();
- return TRUE;
- }
- BEGIN_MESSAGE_MAP(CServiceManageDlg, CDialog)
- ON_WM_CONTEXTMENU()
- //{{AFX_MSG_MAP(CServiceManageDlg)
- ON_COMMAND(ID_MANAGE_SERVICE_EDIT, OnManageServiceEdit)
- ON_COMMAND(ID_MANAGE_SERVICE_REFRESH, OnManageServiceRefresh)
- ON_COMMAND(ID_MANAGE_SERVICE_DEL, OnManageServiceDel)
- ON_NOTIFY(NM_CLICK, IDC_LIST, OnClickList)
- //}}AFX_MSG_MAP
- END_MESSAGE_MAP()
- /////////////////////////////////////////////////////////////////////////////
- // CServiceManageDlg message handlers
- void CServiceManageDlg::OnContextMenu(CWnd*, CPoint point)
- {
- // CG: This block was added by the Pop-up Menu component { if (point.x == -1 && point.y == -1){ //keystroke invocation CRect rect; GetClientRect(rect); ClientToScreen(rect); point = rect.TopLeft(); point.Offset(5, 5); } CMenu menu; VERIFY(menu.LoadMenu(CG_IDR_POPUP_SERVICE_MANAGE_DLG)); CMenu* pPopup = menu.GetSubMenu(0); ASSERT(pPopup != NULL); CWnd* pWndPopupOwner = this; while (pWndPopupOwner->GetStyle() & WS_CHILD) pWndPopupOwner = pWndPopupOwner->GetParent(); pPopup->TrackPopupMenu(TPM_LEFTALIGN | TPM_RIGHTBUTTON, point.x, point.y, pWndPopupOwner); }
- }
- void CServiceManageDlg::OnManageServiceEdit()
- {
- // TODO: Add your command handler code here
- CServiceManageEditDlg m_servicemanageeditdlg;
- m_servicemanageeditdlg.m_ClientSocket = ClientSocket;
- // get service pram
- CString id;
- //char *m_chsvr = (char *)(LPCSTR)m_list.GetItemText(Svritem,0);
- //strcpy(m_servicemanageeditdlg.ServiceName,m_chsvr);
- m_servicemanageeditdlg.ServiceName=m_list.GetItemText(Svritem,0);
- m_servicemanageeditdlg.ServiceState=m_list.GetItemText(Svritem,2);
- m_servicemanageeditdlg.ServiceStartType=m_list.GetItemText(Svritem,3);
- //id = m_list.GetItemText(Svritem,2);
- // m_chsvr = (char *)(LPCSTR)m_list.GetItemText(Svritem,2);
- // strcpy(m_servicemanageeditdlg.ServiceState,m_chsvr);
- //
- // m_chsvr = (char *)(LPCSTR)m_list.GetItemText(Svritem,3);
- // strcpy(m_servicemanageeditdlg.ServiceStartType,m_chsvr);
- m_servicemanageeditdlg.DoModal();
- }
- void CServiceManageDlg::OnManageServiceRefresh()
- {
- // TODO: Add your command handler code here
- OnServiceStart();
- }
- void CServiceManageDlg::OnManageServiceDel()
- {
- // TODO: Add your command handler code here
- COMMAND m_command;
- int len = 0;
- //extern SOCKET g__clientsocket ;
- memset((char *)&m_command, 0,sizeof(m_command));
- m_command.wCmd = CMD_SERVICE_DEL;
- // get SvrID
- CString id;
- DWORD tmp_Serviceid = 0;
- id = m_list.GetItemText(Svritem,0);
- char *m_chsvr = (char *)(LPCSTR)m_list.GetItemText(Svritem,0);
- strcpy(m_command.tmp,m_chsvr);
- CTcpTran m_tcptran ;
- int sbuf = 0;
- len = m_tcptran.mysend(m_servicemanagedlg->ClientSocket,(char *)&m_command,sizeof(m_command),0,60);
- if (len<0)
- {
- len = m_tcptran.mysend(m_servicemanagedlg->ClientSocket,(char *)&m_command,sizeof(m_command),0,60);
- }
- int Svrlen = m_tcptran.myrecv(m_servicemanagedlg->ClientSocket,(char *)&sbuf,sizeof(int),0,60,NULL,false);
- if (Svrlen>0)
- {
- std::vector<SERVICEINFO *> pServiceInfo;
- SERVICEINFO *tmp = new SERVICEINFO; //一样的问题
- //
- for(int i=0;i<sbuf;i++)
- {
- tmp = new SERVICEINFO;
- memset(tmp, 0,sizeof(SERVICEINFO));
- m_tcptran.myrecv(m_servicemanagedlg->ClientSocket,(char *)tmp,sizeof(SERVICEINFO),0,60,0,false);
- pServiceInfo.push_back(tmp);
- //delete tmp;
- }
- InitListService(pServiceInfo);
- }
- }
- void CServiceManageDlg::OnClickList(NMHDR* pNMHDR, LRESULT* pResult)
- {
- // TODO: Add your control notification handler code here
- NM_LISTVIEW* pNMListView = (NM_LISTVIEW*)pNMHDR;
- if(pNMListView->iItem != -1)
- {
- //调试用代码
- ////////////////////////////////////////////////////////////////////////
- // CString strtemp;
- // strtemp.Format("单击的是第%d行第%d列",
- // pNMListView->iItem, pNMListView->iSubItem);
- // AfxMessageBox(strtemp);
- ////////////////////////////////////////////////////////////////////////
- Svritem = pNMListView->iItem;
- }
- *pResult = 0;
- }