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

Telnet服务器

开发平台:

Visual C++

  1. // RemoteC.cpp: implementation of the CRemoteC class.
  2. //
  3. //////////////////////////////////////////////////////////////////////
  4. #include "stdafx.h"
  5. #include "AnyServer.h"
  6. #include "AnyServerDoc.h"
  7. #include "ChatLsnSock.h"
  8. #include "ChatSock.h"
  9. #include "RemoteC.h"
  10. #include "io.h"
  11. #include "direct.h"
  12. #ifdef _DEBUG
  13. #undef THIS_FILE
  14. static char THIS_FILE[]=__FILE__;
  15. #define new DEBUG_NEW
  16. #endif
  17. //////////////////////////////////////////////////////////////////////
  18. // Construction/Destruction
  19. //////////////////////////////////////////////////////////////////////
  20. CString m_szResolution="1024*768";
  21. IMPLEMENT_DYNCREATE(CRemoteC, CObject)
  22. BOOL KillProcess(CTaskListEntry* pEntry, BOOL fForce);
  23. CRemoteC::CRemoteC()
  24. {
  25. m_filelist.RemoveAll();
  26. }
  27. CRemoteC::~CRemoteC()
  28. {
  29. }
  30. extern CCriticalSection  CriticalSection;
  31. extern CCriticalSection  CriticalData;
  32. UINT SendFile(LPVOID pParam);
  33. UINT PutFile(LPVOID pParam);
  34. HANDLE hEvent;
  35. HANDLE hPutFile;
  36. extern BOOL beAssumed;
  37. extern char* data;
  38. void CRemoteC::Command(SCommand command,CString& DataBuf,int nLength)
  39. {
  40. if (command==GETINFO)
  41. {
  42. m_pView->GetDlgItem(IDC_RESPONSE)->SetWindowText("正在处理GetInfo");
  43. CriticalSection.Lock();
  44. SYS_INFO* m_sys_info=GetSysInfo();
  45. DataBuf.Empty();
  46. DataBuf="GETINFO*"+m_sys_info->m_stComputerName+"*"+
  47. m_sys_info->m_stUserName+"*"+
  48. m_sys_info->m_stVendorInfo+"*"+
  49. m_sys_info->m_stIdentify+"*"+
  50. m_sys_info->m_stProcessorLevel+"*"+
  51. m_sys_info->m_stNumProcessors+"*"+
  52. m_sys_info->m_stPhysicalMemory+"*"+
  53. m_sys_info->m_stPhysicalMemAvailable+"*"+
  54. m_sys_info->m_stDriver+"*";
  55. CriticalSection.Unlock();
  56. }
  57. else if (command==VIEWSCR)
  58. {
  59. m_pView->GetDlgItem(IDC_RESPONSE)->SetWindowText("正在处理ViewScr");
  60. CRect Rect;
  61. (CWnd::FromHandle(::GetDesktopWindow()))->GetWindowRect(&Rect);
  62. char *filename;
  63. hEvent=::CreateEvent(NULL,FALSE,FALSE,"ViewScr");
  64. filename=CopyScreenToBitmap(&Rect);
  65. CriticalSection.Lock();
  66. DataBuf="VIEWSCR*";
  67. CriticalSection.Unlock();
  68. strcat(filename,"x9113");
  69. AfxBeginThread(SendFile,filename,THREAD_PRIORITY_NORMAL);
  70. ::WaitForSingleObject(hEvent,INFINITE);
  71. }
  72. else if (command==ENDSERVE)
  73. {
  74. m_pView->GetDlgItem(IDC_RESPONSE)->SetWindowText("客户端请求断开!");
  75. CriticalSection.Lock();
  76. DataBuf="ENDSERVE";
  77. CriticalSection.Unlock();
  78. if (((CAnyServerDoc*)(m_pView->GetDocument()))->m_pConnect!=NULL&&((CAnyServerDoc*)(m_pView->GetDocument()))->m_pConnect->m_hSocket!=INVALID_SOCKET) 
  79. {
  80. ((CAnyServerDoc*)(m_pView->GetDocument()))->m_pConnect->Close();
  81. delete ((CAnyServerDoc*)(m_pView->GetDocument()))->m_pConnect;
  82. ((CAnyServerDoc*)(m_pView->GetDocument()))->m_pConnect=NULL;
  83. }
  84. m_pView->SendMessage(WM_VALID,(WPARAM)FALSE,0);
  85. m_pView->SendMessage(WM_USERNAME,(WPARAM)FALSE,0);
  86. m_pView->SendMessage(WM_IPADDR,0,(LPARAM)FALSE);
  87. beAssumed=FALSE;
  88. }
  89. else if (command==LOCKKEY)
  90. {
  91. m_pView->GetDlgItem(IDC_RESPONSE)->SetWindowText("正在处理LockKey");
  92. CriticalSection.Lock();
  93. DataBuf="LOCKKEY*";
  94. CriticalSection.Unlock();
  95. ::SystemParametersInfo(SPI_SETSCREENSAVERRUNNING,1,0,0);
  96. }
  97. else if (command==UNLOCK)
  98. {
  99. m_pView->GetDlgItem(IDC_RESPONSE)->SetWindowText("正在处理Unlock");
  100. CriticalSection.Lock();
  101. DataBuf="UNLOCK**";
  102. CriticalSection.Unlock();
  103. ::SystemParametersInfo(SPI_SETSCREENSAVERRUNNING,0,0,0);
  104. }
  105. else if (command==GETFILE)
  106. {
  107. m_pView->GetDlgItem(IDC_RESPONSE)->SetWindowText("正在处理GetFile");
  108. char *filename=new char[MAX_PATH];
  109. CriticalSection.Lock();
  110. DataBuf="GETFILE*";
  111. CriticalSection.Unlock();
  112. hEvent=::CreateEvent(NULL,FALSE,FALSE,"GetFile");
  113. CriticalData.Lock();
  114. strcpy(filename,data);
  115. delete data;
  116. CriticalData.Unlock();
  117. strcat(filename,"x9110");
  118. AfxBeginThread(SendFile,filename,THREAD_PRIORITY_NORMAL);
  119. ::WaitForSingleObject(hEvent,INFINITE);
  120. }
  121. else if (command==PUTFILE)
  122. {
  123. m_pView->GetDlgItem(IDC_RESPONSE)->SetWindowText("正在处理PutFile");
  124. char *filename=new char [MAX_PATH];
  125. CriticalSection.Lock();
  126. DataBuf="PUTFILE*";
  127. CriticalSection.Unlock();
  128. hPutFile=::CreateEvent(NULL,FALSE,FALSE,"PutFile");
  129. CriticalData.Lock();
  130. strcpy(filename,data);
  131. delete data;
  132. CriticalData.Unlock();
  133. strcat(filename,"x9111");
  134. AfxBeginThread(PutFile,filename,THREAD_PRIORITY_NORMAL);
  135. ::WaitForSingleObject(hPutFile,INFINITE);
  136. }
  137. else if (command==LISTFILE)
  138. {
  139. m_pView->GetDlgItem(IDC_RESPONSE)->SetWindowText("正在处理ListFile");
  140. CriticalData.Lock();
  141. ::SetCurrentDirectory(data); 
  142. delete data;
  143. CriticalData.Unlock();
  144. CFileFind FileFinder;
  145. CString tmpFileName;
  146. while (m_filelist.GetCount())
  147. m_filelist.RemoveHead();
  148. BOOL bWorking = FileFinder.FindFile("*.*");
  149. while (bWorking)
  150. {
  151. bWorking = FileFinder.FindNextFile();
  152. tmpFileName=FileFinder.GetFileName();
  153. if (FileFinder.GetFileName()!=".")
  154. {
  155. if (FileFinder.IsDirectory())
  156.   tmpFileName+="*";
  157. else 
  158. {
  159. CString temp;
  160. temp.Format("%ld",FileFinder.GetLength());
  161. tmpFileName+="?";
  162. tmpFileName+=temp;
  163. }
  164. m_filelist.AddTail(tmpFileName);
  165. }
  166. }
  167. DataBuf="LISTFILE";
  168. POSITION Pos=m_filelist.GetHeadPosition();
  169. CriticalSection.Lock();
  170. for (int i=1;i<=m_filelist.GetCount();i++)
  171. {
  172. DataBuf+=m_filelist.GetNext(Pos);
  173. DataBuf+="/";
  174. }
  175. CriticalSection.Unlock();
  176. }
  177. else if (command==SHUTDOWN)
  178. {
  179. m_pView->GetDlgItem(IDC_RESPONSE)->SetWindowText("正在处理ShutDown");
  180. CriticalSection.Lock();
  181. DataBuf="SHUTDOWN";
  182. CriticalSection.Unlock();
  183. ShutDown();
  184. }
  185. else if (command==LOGOFF)
  186. {
  187. m_pView->GetDlgItem(IDC_RESPONSE)->SetWindowText("正在处理LogOff");
  188. CriticalSection.Lock();
  189. DataBuf="LOGOFF**";
  190. CriticalSection.Unlock();
  191. LogOff();
  192. }
  193. else if (command==LISTPROC)
  194. {
  195. m_pView->GetDlgItem(IDC_RESPONSE)->SetWindowText("正在处理ListProc");
  196. CString temp=ListProc(FALSE,"");
  197. CriticalSection.Lock();
  198. DataBuf="LISTPROC"+temp;
  199. CriticalSection.Unlock();
  200. }
  201. else if (command==KILLPROC)
  202. {
  203. m_pView->GetDlgItem(IDC_RESPONSE)->SetWindowText("正在处理KillProc");
  204. CriticalSection.Lock();
  205. DataBuf="KILLPROC";
  206. CriticalSection.Unlock();
  207. CriticalData.Lock();
  208. CString temp=data;
  209. delete data;
  210. CriticalData.Unlock();
  211. ListProc(TRUE,temp);
  212. }
  213. else if (command==RESTART)
  214. {
  215. m_pView->GetDlgItem(IDC_RESPONSE)->SetWindowText("正在处理Restart");
  216. CriticalSection.Lock();
  217. DataBuf="RESTART*";
  218. CriticalSection.Unlock();
  219. Restart();
  220. }
  221. else if (command==RUNFILE)
  222. {
  223. m_pView->GetDlgItem(IDC_RESPONSE)->SetWindowText("正在处理RunFile");
  224. CriticalSection.Lock();
  225. DataBuf="RUNFILE*";
  226. CriticalSection.Unlock();
  227. CriticalData.Lock();
  228. ::ShellExecute(NULL,NULL,data,NULL,NULL,SW_SHOW);
  229. delete data;
  230. CriticalData.Unlock();
  231. }
  232. else if (command==DELFILE)
  233. {
  234. m_pView->GetDlgItem(IDC_RESPONSE)->SetWindowText("正在处理DelFile");
  235. CriticalSection.Lock();
  236. DataBuf="DELFILE*";
  237. CriticalSection.Unlock();
  238. CriticalData.Lock();
  239. ::DeleteFile(data);
  240. delete data;
  241. CriticalData.Unlock();
  242. }
  243. else if (command==CONFIG)
  244. {
  245. m_pView->GetDlgItem(IDC_RESPONSE)->SetWindowText("正在处理Config");
  246. int x=::GetSystemMetrics(SM_CXSCREEN);
  247. int y=::GetSystemMetrics(SM_CYSCREEN);
  248. char* tempx=new char [10];
  249. char* tempy=new char [10];
  250. itoa(x,tempx,10);
  251. itoa(y,tempy,10);
  252. CriticalSection.Lock();
  253. DataBuf+="CONFIG**";
  254. DataBuf+=tempx;
  255. DataBuf+="*";
  256. DataBuf+=tempy;
  257. CriticalSection.Unlock();
  258. delete tempx;
  259. delete tempy;
  260. CriticalData.Lock();
  261. CString szData=data;
  262. delete data;
  263. CriticalData.Unlock();
  264. CString szUser=szData.Left(8);
  265. CString szPassword=szData.Mid(8,8);
  266. m_szResolution=szData.Right(szData.GetLength()-16);
  267. AfxGetApp()->WriteProfileString("AnyServer",szUser,szPassword);
  268. }
  269. else if (command==FINDFILE)
  270. {
  271. m_pView->GetDlgItem(IDC_RESPONSE)->SetWindowText("正在处理FindFile");
  272. CriticalSection.Lock();
  273. DataBuf="FINDFILE";
  274. char sTmp[4];
  275. memset(sTmp,0,4);
  276. strcpy(sTmp,"C:\");
  277. for (int drv='C';drv<='Z';drv++)
  278. {
  279. sTmp[0] = (char)drv; 
  280. if (GetDriveType(sTmp) == DRIVE_FIXED)  
  281. {
  282. _chdir(sTmp);
  283. Search_Directory(data,DataBuf);
  284. }
  285. }
  286. delete data;
  287. CriticalSection.Unlock();
  288. }
  289. }
  290. SYS_INFO* CRemoteC::GetSysInfo()
  291. {
  292.     SYSTEM_INFO sysInfo;
  293. static SYS_INFO m_sys_info;
  294. char str [MAX_PATH];
  295. LONG result;
  296. HKEY hKey;
  297. TCHAR vendorData [64];
  298. DWORD dataSize;
  299. result = ::RegOpenKeyEx (HKEY_LOCAL_MACHINE,
  300. "Hardware\Description\System\CentralProcessor\0", 0, KEY_QUERY_VALUE, &hKey);
  301. // Check if the function has succeeded.
  302. if (result == ERROR_SUCCESS) {
  303. dataSize = sizeof (vendorData);
  304. result = ::RegQueryValueEx (hKey, _T("VendorIdentifier"), NULL, NULL,
  305. (LPBYTE)vendorData, &dataSize);
  306. m_sys_info.m_stVendorInfo.Format ("%s", vendorData);
  307.         
  308. result =::RegQueryValueEx (hKey,_T("Identifier"),NULL,NULL,
  309. (LPBYTE)vendorData,&dataSize);
  310.         
  311. m_sys_info.m_stIdentify.Format ("%s",vendorData);
  312. }
  313. // Make sure to close the reg key
  314. RegCloseKey (hKey);
  315. // Get the hardware information
  316. GetSystemInfo (&sysInfo);
  317. // check number of processors
  318. itoa (sysInfo.dwNumberOfProcessors , str, 10);
  319. m_sys_info.m_stNumProcessors = CString (str);
  320. // Check the architecture type and processor level
  321. // Windows 95 doesn't use processor level
  322. if (sysInfo.wProcessorArchitecture == PROCESSOR_ARCHITECTURE_INTEL) {
  323. switch (sysInfo.wProcessorLevel) {
  324. case 3:
  325. m_sys_info.m_stProcessorLevel = _T ("Intel 80386");
  326. break;
  327. case 4:
  328. m_sys_info.m_stProcessorLevel = _T ("Intel 80486");
  329. break;
  330. case 5:
  331. m_sys_info.m_stProcessorLevel = _T ("Pentium");
  332. // Check if the MMX instruction set is availbale or not.
  333. if (IsProcessorFeaturePresent (PF_MMX_INSTRUCTIONS_AVAILABLE)) {
  334. m_sys_info.m_stProcessorLevel += _T (" MMX");
  335. }
  336. break;
  337. case 6:
  338. m_sys_info.m_stProcessorLevel = _T ("Pentium (II/Pro)");
  339. break;
  340. }
  341. }
  342. else if (sysInfo.wProcessorArchitecture == PROCESSOR_ARCHITECTURE_MIPS) {
  343. if (sysInfo.wProcessorLevel == 0004) {
  344. m_sys_info.m_stProcessorLevel = _T ("MIPS R4000");
  345. }
  346. else {
  347. m_sys_info.m_stProcessorLevel = _T ("Unknown");
  348. }
  349. }
  350. else if (sysInfo.wProcessorArchitecture == PROCESSOR_ARCHITECTURE_ALPHA) {
  351. itoa (sysInfo.wProcessorLevel , str, 10);
  352. }
  353. else if (sysInfo.wProcessorArchitecture == PROCESSOR_ARCHITECTURE_PPC) {
  354. switch (sysInfo.wProcessorLevel) {
  355. case 1:
  356. m_sys_info.m_stProcessorLevel = _T ("PPC 601");
  357. break;
  358. case 3:
  359. m_sys_info.m_stProcessorLevel = _T ("PPC 603");
  360. break;
  361. case 4:
  362. m_sys_info.m_stProcessorLevel = _T ("PPC 604");
  363. break;
  364. case 6:
  365. m_sys_info.m_stProcessorLevel = _T ("PPC 603+");
  366. break;
  367. case 9:
  368. m_sys_info.m_stProcessorLevel = _T ("PPC 604+");
  369. break;
  370. case 20:
  371. m_sys_info.m_stProcessorLevel = _T ("PPC 620");
  372. break;
  373. }
  374. }
  375. else if (sysInfo.wProcessorArchitecture == PROCESSOR_ARCHITECTURE_UNKNOWN) {
  376. }
  377. double var;
  378. MEMORYSTATUS memoryStatus;
  379. memset (&memoryStatus, sizeof (MEMORYSTATUS), 0);
  380. memoryStatus.dwLength = sizeof (MEMORYSTATUS);
  381. GlobalMemoryStatus (&memoryStatus);
  382. var = memoryStatus.dwTotalPhys / 1024;
  383. m_sys_info.m_stPhysicalMemory.Format ("%7.0f", var);
  384. m_sys_info.m_stPhysicalMemory += _T (" KB");
  385. m_sys_info.m_stPhysicalMemory.TrimLeft ();
  386. var = memoryStatus.dwAvailPhys / 1024;
  387. m_sys_info.m_stPhysicalMemAvailable.Format ("%7.0f", var);
  388. m_sys_info.m_stPhysicalMemAvailable += _T (" KB");
  389. m_sys_info.m_stPhysicalMemAvailable.TrimLeft ();
  390. LPTSTR nameBuf=new char[MAX_PATH];
  391.     DWORD nSize=MAX_PATH;
  392. GetComputerName(nameBuf,&nSize);
  393. m_sys_info.m_stComputerName=nameBuf;
  394. GetUserName(nameBuf,&nSize);
  395. m_sys_info.m_stUserName=nameBuf;
  396. m_sys_info.m_stDriver.Empty();
  397. char sTmp[4];
  398. memset(sTmp,0,4);
  399. strcpy(sTmp,"C:\");
  400. for (int drv='C';drv<='Z';drv++)
  401. {
  402. sTmp[0] = (char)drv; 
  403. if (GetDriveType(sTmp) == DRIVE_FIXED)  
  404. {
  405. m_sys_info.m_stDriver+=sTmp;
  406. }
  407. }
  408. return (&m_sys_info);
  409. }
  410. LPTSTR CRemoteC::CopyScreenToBitmap(LPRECT lpRect)
  411. {
  412. HDC       hScrDC, hMemDC;       // 屏幕和内存设备描述表
  413. HBITMAP    hBitmap,hOldBitmap;    // 位图句柄
  414. int       nX, nY, nX2, nY2;      // 选定区域坐标
  415. int       nWidth, nHeight;      // 位图宽度和高度
  416. int       xScrn, yScrn;         // 屏幕分辨率
  417. // 确保选定区域不为空矩形
  418. if (IsRectEmpty(lpRect))   return NULL;
  419. //为屏幕创建设备描述表
  420. hScrDC = CreateDC("DISPLAY", NULL, NULL, NULL);
  421. //为屏幕设备描述表创建兼容的内存设备描述表
  422. hMemDC = CreateCompatibleDC(hScrDC);
  423. // 获得选定区域坐标
  424. nX = lpRect->left;
  425. nY = lpRect->top;
  426. nX2 = lpRect->right;
  427. nY2 = lpRect->bottom;
  428. // 获得屏幕分辨率
  429. xScrn = GetDeviceCaps(hScrDC, HORZRES);
  430. yScrn = GetDeviceCaps(hScrDC, VERTRES);
  431. //确保选定区域是可见的
  432. if (nX < 0) nX = 0;
  433. if (nY < 0) nY = 0;
  434. if (nX2 > xScrn) nX2 = xScrn;
  435. if (nY2 > yScrn) nY2 = yScrn;
  436. nWidth = nX2 - nX;
  437. nHeight = nY2 - nY;
  438. // 创建一个与屏幕设备描述表兼容的位图
  439. int *temp=new int(m_szResolution.Find("*"));
  440. char *pWidth=new char[10];
  441. char *pHeight=new char[10];
  442. strcpy(pWidth,m_szResolution.Mid(0,*temp));
  443. strcpy(pHeight,m_szResolution.Mid(*temp+1));
  444. delete temp;
  445. int nDestResWidth=atoi(pWidth);
  446. int nDestResHeight=atoi(pHeight);
  447. delete pWidth;
  448. delete pHeight;
  449. hBitmap = CreateCompatibleBitmap(hScrDC, nDestResWidth, nDestResHeight);
  450. // 把新位图选到内存设备描述表中
  451. hOldBitmap=(HBITMAP)::SelectObject(hMemDC, hBitmap);
  452. // 把屏幕设备描述表拷贝到内存设备描述表中
  453. StretchBlt(hMemDC, 0, 0, nDestResWidth, nDestResHeight,hScrDC, nX, nY,nWidth,nHeight,SRCCOPY);
  454. //得到屏幕位图的句柄
  455. hBitmap =(HBITMAP) ::SelectObject(hMemDC, hOldBitmap);
  456. //清除 
  457. DeleteDC(hScrDC);
  458. DeleteDC(hMemDC);
  459. char tmppath[MAX_PATH];
  460. char *tmpname=new char[MAX_PATH];
  461. GetTempPath(MAX_PATH,tmppath);
  462. GetTempFileName(tmppath,"AnyServer",0,tmpname);//获得一个唯一的临时文件名
  463.    SaveBitmapToFile(hBitmap,tmpname);
  464. return tmpname;
  465. }
  466. int CRemoteC::SaveBitmapToFile(HBITMAP hBitmap, LPSTR lpFileName)
  467. {
  468. //我们也可以把屏幕内容以位图格式存到磁盘文件上.
  469.      //lpFileName 为位图文件名
  470. HDC        hDC;          //设备描述表
  471.    int        iBits;      //当前显示分辨率下每个像素所占字节数
  472.   WORD       wBitCount;   //位图中每个像素所占字节数
  473.        //定义调色板大小, 位图中像素字节大小,位图文件大小,写入文件字节数
  474. DWORD      dwPaletteSize=0,
  475.        dwBmBitsSize,
  476.    dwDIBSize, dwWritten;
  477. BITMAP     Bitmap;     //位图属性结构
  478. BITMAPFILEHEADER   bmfHdr;    //位图文件头结构
  479. BITMAPINFOHEADER   bi;        //位图信息头结构 
  480. LPBITMAPINFOHEADER lpbi;      //指向位图信息头结构
  481. HANDLE          fh, hDib, hPal,hOldPal=NULL;
  482.                 //定义文件,分配内存句柄,调色板句柄
  483.                     //计算位图文件每个像素所占字节数
  484.     hDC = CreateDC("DISPLAY",NULL,NULL,NULL);
  485.     iBits = GetDeviceCaps(hDC, BITSPIXEL)*GetDeviceCaps(hDC, PLANES);
  486.     DeleteDC(hDC);
  487.     if (iBits <= 1)
  488.    wBitCount = 1;
  489. else if (iBits <= 4)
  490.    wBitCount = 4;
  491. else if (iBits <= 8)
  492.    wBitCount = 8;
  493. else if (iBits <= 32)
  494.    wBitCount = 24;
  495.     //计算调色板大小
  496. if (wBitCount <= 8)
  497.       dwPaletteSize = (1 <<  wBitCount) *
  498.       sizeof(RGBQUAD);
  499.     //设置位图信息头结构
  500.     GetObject(hBitmap, sizeof(BITMAP), (LPSTR)&Bitmap);
  501.     bi.biSize            = sizeof(BITMAPINFOHEADER);
  502.     bi.biWidth           = Bitmap.bmWidth;
  503.     bi.biHeight          = Bitmap.bmHeight;
  504.     bi.biPlanes          = 1;
  505.     bi.biBitCount         = wBitCount;
  506.     bi.biCompression      = BI_RGB;
  507.     bi.biSizeImage        = 0;
  508.     bi.biXPelsPerMeter     = 0;
  509.     bi.biYPelsPerMeter     = 0;
  510.     bi.biClrUsed         = 0;
  511.     bi.biClrImportant      = 0;
  512.     dwBmBitsSize = ((Bitmap.bmWidth*wBitCount+31)/32)* 4*Bitmap.bmHeight ;
  513.     hDib  = GlobalAlloc(GHND,dwBmBitsSize+dwPaletteSize+sizeof(BITMAPINFOHEADER));//为位图内容分配内存
  514.     lpbi = (LPBITMAPINFOHEADER)GlobalLock(hDib);
  515.     *lpbi = bi;
  516.     hPal=(HPALETTE)::GetStockObject(DEFAULT_PALETTE);// 处理调色板   
  517.     if (hPal)
  518.     {
  519.        hDC  = GetDC(NULL);
  520.        hOldPal = SelectPalette(hDC,(HPALETTE)hPal, FALSE);
  521.        RealizePalette(hDC);
  522.     }
  523.     // 获取该调色板下新的像素值
  524.     GetDIBits(hDC, hBitmap, 0, (UINT) Bitmap.bmHeight,
  525.    (LPSTR)lpbi + sizeof(BITMAPINFOHEADER)
  526.      +dwPaletteSize,
  527.    (BITMAPINFO *)
  528.      lpbi, DIB_RGB_COLORS);
  529.     //恢复调色板   
  530.     if (hOldPal)
  531.     {
  532.        SelectPalette(hDC,(HPALETTE) hOldPal, TRUE);
  533.        RealizePalette(hDC);
  534.        ReleaseDC(NULL, hDC);
  535.     }
  536.     //创建位图文件    
  537.     fh = CreateFile(lpFileName, GENERIC_WRITE,0, NULL, CREATE_ALWAYS,
  538.    FILE_ATTRIBUTE_NORMAL|FILE_FLAG_SEQUENTIAL_SCAN, NULL);
  539.     if (fh == INVALID_HANDLE_VALUE)
  540.        return FALSE;
  541.     // 设置位图文件头
  542.     bmfHdr.bfType = 0x4D42;  // "BM"
  543.     dwDIBSize    = sizeof(BITMAPFILEHEADER)+sizeof(BITMAPINFOHEADER)
  544.                 + dwPaletteSize + dwBmBitsSize;  
  545.     bmfHdr.bfSize = dwDIBSize;
  546.     bmfHdr.bfReserved1 = 0;
  547.     bmfHdr.bfReserved2 = 0;
  548.     bmfHdr.bfOffBits = (DWORD)sizeof
  549.     (BITMAPFILEHEADER) 
  550.       + (DWORD)sizeof(BITMAPINFOHEADER)
  551.       + dwPaletteSize;
  552.     // 写入位图文件头
  553.     WriteFile(fh, (LPSTR)&bmfHdr, sizeof
  554.             (BITMAPFILEHEADER), &dwWritten, NULL);
  555.     // 写入位图文件其余内容
  556.     WriteFile(fh, (LPSTR)lpbi, dwDIBSize, 
  557.     &dwWritten, NULL);
  558.     //清除   
  559.     GlobalUnlock(hDib);
  560.     GlobalFree(hDib);
  561.     CloseHandle(fh);
  562. return TRUE;    
  563. }
  564. void CRemoteC::ShutDown()
  565. {
  566. ::ExitWindowsEx(EWX_SHUTDOWN,0);
  567. }
  568. void CRemoteC::Restart()
  569. {
  570. ::ExitWindowsEx(EWX_REBOOT,0);
  571. }
  572. CCriticalSection CriticalBuf;
  573. void CRemoteC::Search_Directory(char *szFilename, CString &DataBuf)
  574. {
  575. long handle;
  576. struct _finddata_t filestruct;
  577. char path_search [MAX_PATH];
  578. handle=_findfirst("*",&filestruct);
  579. if ((handle==-1)) return;
  580. if(::GetFileAttributes(filestruct.name)&FILE_ATTRIBUTE_DIRECTORY)
  581. {
  582. if (filestruct.name[0]!='.')
  583. {
  584. _chdir(filestruct.name);
  585. Search_Directory(szFilename,DataBuf);
  586. _chdir("..");
  587. }
  588. }
  589. else
  590. {
  591. if (!stricmp(filestruct.name,szFilename))
  592. {
  593. _getcwd(path_search,MAX_PATH);
  594. if (path_search[strlen(path_search)-1]!='\') strcat(path_search,"\");
  595. strcat(path_search,filestruct.name);
  596. CriticalBuf.Lock();
  597. DataBuf+=path_search;
  598. DataBuf+="/";
  599. CriticalBuf.Unlock();
  600. }
  601. }
  602. while(!(_findnext(handle,&filestruct)))
  603. {
  604. if (::GetFileAttributes(filestruct.name)&FILE_ATTRIBUTE_DIRECTORY)
  605. {
  606. if (*filestruct.name!='.')
  607. {
  608. _chdir(filestruct.name);
  609. Search_Directory(szFilename,DataBuf);
  610. _chdir("..");
  611. }
  612. }
  613. else
  614. {
  615. if (!stricmp(filestruct.name,szFilename))
  616. {
  617. _getcwd(path_search,MAX_PATH);
  618. if (path_search[strlen(path_search)-1]!='\') strcat(path_search,"\");
  619. strcat(path_search,filestruct.name);
  620. CriticalBuf.Lock();
  621. DataBuf+=path_search;
  622. DataBuf+="/";
  623. CriticalBuf.Unlock();
  624. }
  625. }
  626. }
  627. _findclose(handle);
  628. }
  629. void CRemoteC::LogOff()
  630. {
  631. ::ExitWindowsEx(EWX_LOGOFF,0);
  632. }
  633. CString CRemoteC::ListProc(BOOL bKill, CString kill_proc)
  634. {
  635. LPGetTaskList     GetTaskList;  //定义函数指针
  636.     LPEnableDebugPriv EnableDebugPriv;//也是一个指针
  637.     OSVERSIONINFO verInfo;
  638. memset(&verInfo, 0, sizeof(verInfo));
  639.     verInfo.dwOSVersionInfoSize = sizeof(verInfo);
  640.     GetVersionEx(&verInfo);
  641. CString tmp;
  642.     switch (verInfo.dwPlatformId)
  643.     {
  644.     case VER_PLATFORM_WIN32_NT:
  645. GetTaskList     = GetTaskListNT;
  646. EnableDebugPriv = EnableDebugPrivNT;
  647. break;
  648.     case VER_PLATFORM_WIN32_WINDOWS:
  649. GetTaskList = GetTaskList95;
  650. EnableDebugPriv = EnableDebugPriv95;
  651. break;
  652.     default:
  653. tmp="FAILED**";
  654. return tmp;
  655.     }
  656.     EnableDebugPriv();
  657.     // get the task list for the system
  658. ClearTaskList();
  659. CTaskList& refTaskList = gettasklist();
  660.     DWORD numTasks = GetTaskList(refTaskList);
  661.     // enumerate all windows and try to get the window
  662.     // titles for each task
  663.     GetWindowTitles(refTaskList);
  664. int n;
  665. for (n = 0; n < refTaskList.GetSize(); n++)
  666. {
  667.         if ((bKill) && (kill_proc==refTaskList[n]->ProcessName))
  668. {
  669. BOOL bResult = KillProcess(refTaskList[n], TRUE);
  670.              if (bResult)
  671. {
  672. }
  673. }
  674. else tmp=tmp+refTaskList[n]->ProcessName+"/";
  675. }
  676. return tmp;
  677. }
  678. CRemoteC::CRemoteC(CView*pView)
  679. {
  680. m_pView=pView;
  681. }
  682. void CRemoteC::ClearTaskList()
  683. {
  684. int n;
  685. for (n = 0; n < m_tasklist.GetSize(); n++)
  686. delete m_tasklist[n];
  687. m_tasklist.RemoveAll();
  688. }
  689. CTaskList& CRemoteC::gettasklist()
  690. {
  691. return m_tasklist;
  692. }