RemoteC.cpp
上传用户:wpp2016
上传日期:2010-02-01
资源大小:1250k
文件大小:8k
源码类别:

Telnet服务器

开发平台:

Visual C++

  1. // RemoteC.cpp : implementation file
  2. //
  3. #include "stdafx.h"
  4. #include "anywhere.h"
  5. #include "RemoteC.h"
  6. #include "shadowwnd.h"
  7. #include "proc.h"
  8. #include "thread1.h"
  9. #include "option.h"
  10. #ifdef _DEBUG
  11. #define new DEBUG_NEW
  12. #undef THIS_FILE
  13. static char THIS_FILE[] = __FILE__;
  14. #endif
  15. /////////////////////////////////////////////////////////////////////////////
  16. // CRemoteC
  17. IMPLEMENT_DYNCREATE(CRemoteC, CFormView)
  18. CRemoteC::CRemoteC()
  19. : CFormView(CRemoteC::IDD)
  20. {
  21. //{{AFX_DATA_INIT(CRemoteC)
  22. //}}AFX_DATA_INIT
  23. }
  24. CRemoteC::~CRemoteC()
  25. {
  26. }
  27. void CRemoteC::DoDataExchange(CDataExchange* pDX)
  28. {
  29. CFormView::DoDataExchange(pDX);
  30. //{{AFX_DATA_MAP(CRemoteC)
  31. DDX_Control(pDX, IDC_MENUREPORT, m_lcList);
  32. //}}AFX_DATA_MAP
  33. }
  34. BEGIN_MESSAGE_MAP(CRemoteC, CFormView)
  35. //{{AFX_MSG_MAP(CRemoteC)
  36. ON_WM_SIZE()
  37. ON_WM_CREATE()
  38. ON_NOTIFY(NM_DBLCLK, IDC_MENUREPORT, OnDblclkMenureport)
  39. ON_NOTIFY(NM_RCLICK, IDC_MENUREPORT, OnRclickMenureport)
  40. ON_MESSAGE(WM_SETACTIVE,OnSetActive)
  41. //}}AFX_MSG_MAP
  42. END_MESSAGE_MAP()
  43. /////////////////////////////////////////////////////////////////////////////
  44. // CRemoteC diagnostics
  45. #ifdef _DEBUG
  46. void CRemoteC::AssertValid() const
  47. {
  48. CFormView::AssertValid();
  49. }
  50. void CRemoteC::Dump(CDumpContext& dc) const
  51. {
  52. CFormView::Dump(dc);
  53. }
  54. #endif //_DEBUG
  55. /////////////////////////////////////////////////////////////////////////////
  56. // CRemoteC message handlers
  57. void CRemoteC::OnSize(UINT nType, int cx, int cy) 
  58. {
  59. CFormView::OnSize(nType, cx, cy);
  60. /*
  61.   if (m_treectrl.GetSafeHwnd())
  62.    m_treectrl.MoveWindow(0,0,cx/2,cy,TRUE);
  63.   
  64.   if (m_detail.GetSafeHwnd())
  65.   m_detail.MoveWindow(cx/2+70,70,cx*1/3,100,TRUE);
  66.   
  67.   if (m_btsend.GetSafeHwnd())
  68.    m_btsend.MoveWindow(cx*4/5,cy*4/5,100,50,TRUE);
  69.   */
  70.   if (m_lcList.GetSafeHwnd())
  71.   m_lcList.MoveWindow(0,0,cx,cy,TRUE);
  72.  
  73. }
  74. int CRemoteC::OnCreate(LPCREATESTRUCT lpCreateStruct) 
  75. {
  76. if (CFormView::OnCreate(lpCreateStruct) == -1)
  77. return -1;
  78.   // 
  79. return 0;
  80. }
  81. void CRemoteC::OnInitialUpdate() 
  82. {
  83. CFormView::OnInitialUpdate();
  84.    InitList();
  85. }
  86. static CString csItems[] =
  87. {
  88. _T("Manager Anywhere 控制主菜单"),
  89. _T("注销当前用户"),
  90. _T("重启动"),
  91. _T("关闭Windows"),
  92. //_T("关闭电源"),
  93. _T("键盘加锁"),
  94. _T("键盘解锁"),
  95. _T("进程管理"),
  96. _T("获取系统信息"),
  97. _T("查看屏幕"),
  98. _T("系统设置"),
  99. //_T("注册表")
  100. };
  101. static int detail[]=
  102. {
  103. IDS_MENUCONTROL,//主菜单
  104. IDS_LOGOFF,     //注销
  105. IDS_RESTART,
  106. IDS_SHUTDOWN,
  107. //IDS_POWEROFF,
  108. IDS_LOCKKEY,
  109. IDS_UNLOCKKEY,
  110. IDS_LISTPROC,
  111. IDS_GETINFO,
  112. IDS_VIEWSCR,
  113. IDS_CONFIG,
  114. //IDS_REG
  115. };
  116. static int order[]=
  117. {
  118. IDS_MENUCONTROL,
  119. IDM_LOGOFF,
  120. IDM_RESTART,
  121. IDM_SHUTDOWN,
  122. //IDM_POWEROFF,
  123. IDM_LOCKKEY,
  124. IDM_UNLOCKKEY,
  125. IDM_LISTPROC,
  126. IDM_GETINFO,
  127. IDM_VIEWSCR,
  128. IDM_CONFIG,
  129. //IDM_REG
  130. };
  131. static UINT nImages[] =
  132. {
  133. IDI_ICON_OUTLOOK,
  134. IDI_ICON_PUBLIC,
  135. IDI_ICON_CALENDAR,
  136. IDI_ICON_CONTACTS,
  137. //IDI_ICON_DELETED,
  138. IDI_ICON_DRAFTS,
  139. IDI_ICON_INBOX,
  140. IDI_ICON_JOURNAL,
  141. IDI_ICON_NOTES,
  142. IDI_ICON_OUTBOX,
  143. IDI_ICON_SENT,
  144. //IDI_ICON_TASKS
  145. };
  146. void CRemoteC::InitList()
  147. {
  148. CRect rect;
  149. GetClientRect(&rect);
  150. m_lcList.InsertColumn(0, "命令", LVCFMT_LEFT, rect.Width()/3);
  151. m_lcList.InsertColumn(1, "说明", LVCFMT_LEFT,rect.Width()*3/4);
  152. //m_imagelist.Create(IDB_HEADER, 9, 1, RGB(255,255,255));
  153. //m_bitmap.LoadBitmap(IDB_BITMAP);
  154. CFlatHeaderCtrl* pFlatHeader = (CFlatHeaderCtrl*)m_lcList.GetHeaderCtrl();
  155. pFlatHeader->ModifyProperty(FH_PROPERTY_STATICBORDER, TRUE);
  156. //pFlatHeader->SetImageList(&m_imagelist);
  157. HDITEMEX hditemex;
  158. hditemex.iMinWidth = rect.Width()/2;
  159. hditemex.iMaxWidth = rect.Width()*4/5;
  160. pFlatHeader->SetItemEx(1, &hditemex);//设定最大宽度
  161.     
  162. m_lcList.SetExtendedStyle(LVS_EX_HEADERDRAGDROP|LVS_EX_FULLROWSELECT);
  163.     //选择整行
  164.     //m_lcList.SetImageList(&m_imagelist,LVSIL_SMALL);
  165.     
  166.     //ModifyStyle (0, TVS_HASBUTTONS|TVS_HASLINES|TVS_LINESATROOT);
  167. m_Font.CreatePointFont(95, _T("Tahoma"));
  168. m_lcList.SetFont(&m_Font);
  169. m_imagelist.Create(16,16,true,2,1);
  170. HICON hIcon;
  171. for (int i =0; i < 10; ++i) {
  172. hIcon= AfxGetApp()->LoadIcon (nImages[i]);
  173. m_imagelist.Add (hIcon);
  174. }
  175. //
  176. m_lcList.SetImageList( &m_imagelist,LVSIL_SMALL );
  177. m_lcList.InsertItem(0,csItems[0],0);
  178. CString intro;
  179. intro.LoadString(detail[0]);
  180. m_lcList.SetItemText(0,1,intro);
  181. m_lcList.SetItemData(0,0);
  182. for (i=1;i<10;i++)
  183. {
  184. m_lcList.InsertItem(i,csItems[i],i);
  185. CString intro;
  186. intro.LoadString(detail[i]);
  187. m_lcList.SetItemText(i,1,intro);
  188. m_lcList.SetItemData(i,order[i]);
  189. }
  190. /*
  191. HDITEM hditem;
  192. hditem.mask = HDI_FORMAT|HDI_IMAGE; //|HDI_BITMAP; // <-- remove // to demo bitmaps
  193. pFlatHeader->GetItem(0, &hditem);
  194. hditem.fmt |= HDF_IMAGE; //|HDF_BITMAP;
  195. hditem.iImage = 0;
  196. hditem.hbm = (HBITMAP)m_bitmap;
  197. pFlatHeader->SetItem(0, &hditem);
  198. hditem.mask = HDI_FORMAT|HDI_IMAGE; //|HDI_BITMAP;
  199. pFlatHeader->GetItem(1, &hditem);
  200. hditem.fmt |= HDF_IMAGE; //|HDF_BITMAP;
  201. hditem.iImage = 1;
  202. hditem.hbm = (HBITMAP)m_bitmap;
  203. pFlatHeader->SetItem(1, &hditem);
  204. hditem.mask = HDI_FORMAT|HDI_IMAGE; //|HDI_BITMAP;
  205. pFlatHeader->GetItem(2, &hditem);
  206. hditem.fmt |= HDF_IMAGE; //|HDF_BITMAP|HDF_BITMAP_ON_RIGHT;
  207. hditem.iImage = 2;
  208. hditem.hbm = (HBITMAP)m_bitmap;
  209. pFlatHeader->SetItem(2, &hditem);
  210. */
  211.     /*             
  212. m_lcList.InsertItem(0, "Column 1",1);
  213. m_lcList.SetItemText(0, 1, "Column 2");
  214. m_lcList.SetItemText(0, 2, "Column 3");
  215. */
  216. }
  217. void CRemoteC::OnDblclkMenureport(NMHDR* pNMHDR, LRESULT* pResult) 
  218. {
  219. if (!linkrc.bConnected) {
  220. CString sErrmsg,caption;
  221. sErrmsg.LoadString(IDS_SERVER_FAILED);
  222. caption.LoadString(IDS_CAPTION);
  223. MessageBox(sErrmsg,caption,MB_OK);
  224. return ;}
  225.     int i=m_lcList.GetNextItem(-1,LVNI_ALL|LVNI_SELECTED);
  226. if (i==0) return;
  227. int j=m_lcList.GetItemData(i);//命令代码
  228. CString order;
  229. order.LoadString(j);
  230. if (order=="LISTPROC") {
  231. CProc procdlg;
  232.     procdlg.DoModal();
  233. return;
  234. }
  235.     else if (order=="CONFIG**")
  236. {
  237. COption dlg;
  238. dlg.DoModal();
  239. return;
  240. }
  241. CString intro;
  242. intro.LoadString(detail[i]);
  243. CString caption;
  244. caption.LoadString(IDS_CAPTION);
  245. CString ask="您确信要发出如下命令吗:";
  246.     ask+=intro;
  247. if (IDYES==MessageBox(ask,caption,MB_YESNO))
  248. {
  249. DWORD ThreadId;
  250. strcpy(linkrc.sbuf,order);//命令
  251. if (order=="LOGOFF**" ||order=="RESTART*" ||order=="SHUTDOWN") 
  252. {
  253. linkrc.m_hWnd=GetSafeHwnd();//句柄付给线程
  254. hSend=CreateThread(NULL,0,SysThread,&linkrc,0,&ThreadId);
  255. }
  256. else if (order=="GETINFO*")
  257. {
  258. linkrc.m_hWnd=m_hMainWnd;//句柄付给线程
  259. hSend=CreateThread(NULL,0,SendThread,&linkrc,0,&ThreadId);
  260. }
  261. else if (order=="VIEWSCR*")
  262. {
  263. //linkrc.m_hWnd=m_hMainWnd;//句柄付给线程
  264. linkrc.m_hWnd=AfxGetMainWnd()->GetSafeHwnd();
  265. hSend=CreateThread(NULL,0,ViewScr,&linkrc,0,&ThreadId);
  266. }
  267. else {
  268. linkrc.m_hWnd=GetSafeHwnd();//句柄付给线程
  269.     hSend=CreateThread(NULL,0,SendThread,&linkrc,0,&ThreadId);
  270. }
  271.  }
  272. *pResult = 0;
  273. }
  274. void CRemoteC::OnRclickMenureport(NMHDR* pNMHDR, LRESULT* pResult) 
  275. {
  276.    int  i=m_lcList.GetNextItem(-1,LVNI_ALL|LVNI_SELECTED);
  277.    CString intro;
  278.    intro.LoadString(detail[i]);
  279.    CShadowWnd tips;
  280.    tips.ShowReadOnlyText(intro);
  281. *pResult = 0;
  282. }
  283. LRESULT CRemoteC::OnSetActive(WPARAM wParam,LPARAM lParam)
  284. {
  285. if ((BOOL)wParam) {
  286.   CString text=*(CString*)lParam;
  287.   CString order;
  288.   order=text.Left(8);
  289.   text=text.Right(text.GetLength()-8);
  290.   CString sSucmsg,caption;
  291.   sSucmsg.LoadString(IDS_ACTION_OK);
  292.   caption.LoadString(IDS_CAPTION);
  293.   MessageBox(sSucmsg,caption,MB_OK);
  294.   return 1;
  295. }
  296. return 0;
  297. }