RemoteC.cpp
资源名称:(vc).rar [点击查看]
上传用户:wpp2016
上传日期:2010-02-01
资源大小:1250k
文件大小:8k
源码类别:
Telnet服务器
开发平台:
Visual C++
- // RemoteC.cpp : implementation file
- //
- #include "stdafx.h"
- #include "anywhere.h"
- #include "RemoteC.h"
- #include "shadowwnd.h"
- #include "proc.h"
- #include "thread1.h"
- #include "option.h"
- #ifdef _DEBUG
- #define new DEBUG_NEW
- #undef THIS_FILE
- static char THIS_FILE[] = __FILE__;
- #endif
- /////////////////////////////////////////////////////////////////////////////
- // CRemoteC
- IMPLEMENT_DYNCREATE(CRemoteC, CFormView)
- CRemoteC::CRemoteC()
- : CFormView(CRemoteC::IDD)
- {
- //{{AFX_DATA_INIT(CRemoteC)
- //}}AFX_DATA_INIT
- }
- CRemoteC::~CRemoteC()
- {
- }
- void CRemoteC::DoDataExchange(CDataExchange* pDX)
- {
- CFormView::DoDataExchange(pDX);
- //{{AFX_DATA_MAP(CRemoteC)
- DDX_Control(pDX, IDC_MENUREPORT, m_lcList);
- //}}AFX_DATA_MAP
- }
- BEGIN_MESSAGE_MAP(CRemoteC, CFormView)
- //{{AFX_MSG_MAP(CRemoteC)
- ON_WM_SIZE()
- ON_WM_CREATE()
- ON_NOTIFY(NM_DBLCLK, IDC_MENUREPORT, OnDblclkMenureport)
- ON_NOTIFY(NM_RCLICK, IDC_MENUREPORT, OnRclickMenureport)
- ON_MESSAGE(WM_SETACTIVE,OnSetActive)
- //}}AFX_MSG_MAP
- END_MESSAGE_MAP()
- /////////////////////////////////////////////////////////////////////////////
- // CRemoteC diagnostics
- #ifdef _DEBUG
- void CRemoteC::AssertValid() const
- {
- CFormView::AssertValid();
- }
- void CRemoteC::Dump(CDumpContext& dc) const
- {
- CFormView::Dump(dc);
- }
- #endif //_DEBUG
- /////////////////////////////////////////////////////////////////////////////
- // CRemoteC message handlers
- void CRemoteC::OnSize(UINT nType, int cx, int cy)
- {
- CFormView::OnSize(nType, cx, cy);
- /*
- if (m_treectrl.GetSafeHwnd())
- m_treectrl.MoveWindow(0,0,cx/2,cy,TRUE);
- if (m_detail.GetSafeHwnd())
- m_detail.MoveWindow(cx/2+70,70,cx*1/3,100,TRUE);
- if (m_btsend.GetSafeHwnd())
- m_btsend.MoveWindow(cx*4/5,cy*4/5,100,50,TRUE);
- */
- if (m_lcList.GetSafeHwnd())
- m_lcList.MoveWindow(0,0,cx,cy,TRUE);
- }
- int CRemoteC::OnCreate(LPCREATESTRUCT lpCreateStruct)
- {
- if (CFormView::OnCreate(lpCreateStruct) == -1)
- return -1;
- //
- return 0;
- }
- void CRemoteC::OnInitialUpdate()
- {
- CFormView::OnInitialUpdate();
- InitList();
- }
- static CString csItems[] =
- {
- _T("Manager Anywhere 控制主菜单"),
- _T("注销当前用户"),
- _T("重启动"),
- _T("关闭Windows"),
- //_T("关闭电源"),
- _T("键盘加锁"),
- _T("键盘解锁"),
- _T("进程管理"),
- _T("获取系统信息"),
- _T("查看屏幕"),
- _T("系统设置"),
- //_T("注册表")
- };
- static int detail[]=
- {
- IDS_MENUCONTROL,//主菜单
- IDS_LOGOFF, //注销
- IDS_RESTART,
- IDS_SHUTDOWN,
- //IDS_POWEROFF,
- IDS_LOCKKEY,
- IDS_UNLOCKKEY,
- IDS_LISTPROC,
- IDS_GETINFO,
- IDS_VIEWSCR,
- IDS_CONFIG,
- //IDS_REG
- };
- static int order[]=
- {
- IDS_MENUCONTROL,
- IDM_LOGOFF,
- IDM_RESTART,
- IDM_SHUTDOWN,
- //IDM_POWEROFF,
- IDM_LOCKKEY,
- IDM_UNLOCKKEY,
- IDM_LISTPROC,
- IDM_GETINFO,
- IDM_VIEWSCR,
- IDM_CONFIG,
- //IDM_REG
- };
- static UINT nImages[] =
- {
- IDI_ICON_OUTLOOK,
- IDI_ICON_PUBLIC,
- IDI_ICON_CALENDAR,
- IDI_ICON_CONTACTS,
- //IDI_ICON_DELETED,
- IDI_ICON_DRAFTS,
- IDI_ICON_INBOX,
- IDI_ICON_JOURNAL,
- IDI_ICON_NOTES,
- IDI_ICON_OUTBOX,
- IDI_ICON_SENT,
- //IDI_ICON_TASKS
- };
- void CRemoteC::InitList()
- {
- CRect rect;
- GetClientRect(&rect);
- m_lcList.InsertColumn(0, "命令", LVCFMT_LEFT, rect.Width()/3);
- m_lcList.InsertColumn(1, "说明", LVCFMT_LEFT,rect.Width()*3/4);
- //m_imagelist.Create(IDB_HEADER, 9, 1, RGB(255,255,255));
- //m_bitmap.LoadBitmap(IDB_BITMAP);
- CFlatHeaderCtrl* pFlatHeader = (CFlatHeaderCtrl*)m_lcList.GetHeaderCtrl();
- pFlatHeader->ModifyProperty(FH_PROPERTY_STATICBORDER, TRUE);
- //pFlatHeader->SetImageList(&m_imagelist);
- HDITEMEX hditemex;
- hditemex.iMinWidth = rect.Width()/2;
- hditemex.iMaxWidth = rect.Width()*4/5;
- pFlatHeader->SetItemEx(1, &hditemex);//设定最大宽度
- m_lcList.SetExtendedStyle(LVS_EX_HEADERDRAGDROP|LVS_EX_FULLROWSELECT);
- //选择整行
- //m_lcList.SetImageList(&m_imagelist,LVSIL_SMALL);
- //ModifyStyle (0, TVS_HASBUTTONS|TVS_HASLINES|TVS_LINESATROOT);
- m_Font.CreatePointFont(95, _T("Tahoma"));
- m_lcList.SetFont(&m_Font);
- m_imagelist.Create(16,16,true,2,1);
- HICON hIcon;
- for (int i =0; i < 10; ++i) {
- hIcon= AfxGetApp()->LoadIcon (nImages[i]);
- m_imagelist.Add (hIcon);
- }
- //
- m_lcList.SetImageList( &m_imagelist,LVSIL_SMALL );
- m_lcList.InsertItem(0,csItems[0],0);
- CString intro;
- intro.LoadString(detail[0]);
- m_lcList.SetItemText(0,1,intro);
- m_lcList.SetItemData(0,0);
- for (i=1;i<10;i++)
- {
- m_lcList.InsertItem(i,csItems[i],i);
- CString intro;
- intro.LoadString(detail[i]);
- m_lcList.SetItemText(i,1,intro);
- m_lcList.SetItemData(i,order[i]);
- }
- /*
- HDITEM hditem;
- hditem.mask = HDI_FORMAT|HDI_IMAGE; //|HDI_BITMAP; // <-- remove // to demo bitmaps
- pFlatHeader->GetItem(0, &hditem);
- hditem.fmt |= HDF_IMAGE; //|HDF_BITMAP;
- hditem.iImage = 0;
- hditem.hbm = (HBITMAP)m_bitmap;
- pFlatHeader->SetItem(0, &hditem);
- hditem.mask = HDI_FORMAT|HDI_IMAGE; //|HDI_BITMAP;
- pFlatHeader->GetItem(1, &hditem);
- hditem.fmt |= HDF_IMAGE; //|HDF_BITMAP;
- hditem.iImage = 1;
- hditem.hbm = (HBITMAP)m_bitmap;
- pFlatHeader->SetItem(1, &hditem);
- hditem.mask = HDI_FORMAT|HDI_IMAGE; //|HDI_BITMAP;
- pFlatHeader->GetItem(2, &hditem);
- hditem.fmt |= HDF_IMAGE; //|HDF_BITMAP|HDF_BITMAP_ON_RIGHT;
- hditem.iImage = 2;
- hditem.hbm = (HBITMAP)m_bitmap;
- pFlatHeader->SetItem(2, &hditem);
- */
- /*
- m_lcList.InsertItem(0, "Column 1",1);
- m_lcList.SetItemText(0, 1, "Column 2");
- m_lcList.SetItemText(0, 2, "Column 3");
- */
- }
- void CRemoteC::OnDblclkMenureport(NMHDR* pNMHDR, LRESULT* pResult)
- {
- if (!linkrc.bConnected) {
- CString sErrmsg,caption;
- sErrmsg.LoadString(IDS_SERVER_FAILED);
- caption.LoadString(IDS_CAPTION);
- MessageBox(sErrmsg,caption,MB_OK);
- return ;}
- int i=m_lcList.GetNextItem(-1,LVNI_ALL|LVNI_SELECTED);
- if (i==0) return;
- int j=m_lcList.GetItemData(i);//命令代码
- CString order;
- order.LoadString(j);
- if (order=="LISTPROC") {
- CProc procdlg;
- procdlg.DoModal();
- return;
- }
- else if (order=="CONFIG**")
- {
- COption dlg;
- dlg.DoModal();
- return;
- }
- CString intro;
- intro.LoadString(detail[i]);
- CString caption;
- caption.LoadString(IDS_CAPTION);
- CString ask="您确信要发出如下命令吗:";
- ask+=intro;
- if (IDYES==MessageBox(ask,caption,MB_YESNO))
- {
- DWORD ThreadId;
- strcpy(linkrc.sbuf,order);//命令
- if (order=="LOGOFF**" ||order=="RESTART*" ||order=="SHUTDOWN")
- {
- linkrc.m_hWnd=GetSafeHwnd();//句柄付给线程
- hSend=CreateThread(NULL,0,SysThread,&linkrc,0,&ThreadId);
- }
- else if (order=="GETINFO*")
- {
- linkrc.m_hWnd=m_hMainWnd;//句柄付给线程
- hSend=CreateThread(NULL,0,SendThread,&linkrc,0,&ThreadId);
- }
- else if (order=="VIEWSCR*")
- {
- //linkrc.m_hWnd=m_hMainWnd;//句柄付给线程
- linkrc.m_hWnd=AfxGetMainWnd()->GetSafeHwnd();
- hSend=CreateThread(NULL,0,ViewScr,&linkrc,0,&ThreadId);
- }
- else {
- linkrc.m_hWnd=GetSafeHwnd();//句柄付给线程
- hSend=CreateThread(NULL,0,SendThread,&linkrc,0,&ThreadId);
- }
- }
- *pResult = 0;
- }
- void CRemoteC::OnRclickMenureport(NMHDR* pNMHDR, LRESULT* pResult)
- {
- int i=m_lcList.GetNextItem(-1,LVNI_ALL|LVNI_SELECTED);
- CString intro;
- intro.LoadString(detail[i]);
- CShadowWnd tips;
- tips.ShowReadOnlyText(intro);
- *pResult = 0;
- }
- LRESULT CRemoteC::OnSetActive(WPARAM wParam,LPARAM lParam)
- {
- if ((BOOL)wParam) {
- CString text=*(CString*)lParam;
- CString order;
- order=text.Left(8);
- text=text.Right(text.GetLength()-8);
- CString sSucmsg,caption;
- sSucmsg.LoadString(IDS_ACTION_OK);
- caption.LoadString(IDS_CAPTION);
- MessageBox(sSucmsg,caption,MB_OK);
- return 1;
- }
- return 0;
- }