home *** CD-ROM | disk | FTP | other *** search
/ PC World 2004 November / PCWorld_2004-11_cd.bin / software / temacd / poweroff / pwroff30.exe / src / remote_control.c < prev    next >
C/C++ Source or Header  |  2002-02-16  |  2KB  |  79 lines

  1. #include "poweroff.h"
  2.  
  3. char *EncodePassword(char *password)
  4. {
  5.   static char str[40];
  6.   int x,c=65,len;
  7.  
  8.   Log("EncodePassword start");
  9.   if (password[0]=='\0')
  10.     return "";
  11.   len=strlen(password);
  12.   c=len;
  13.   for (x=0;x<len;x++)
  14.     c=(c+password[x])%256;
  15.   for (x=0;x<40;x++)
  16.   {
  17.     c=(c+password[x%len])%80;
  18.     str[x]=33+c;
  19.   }
  20.   str[39]='\0';
  21.   Log("EncodePassword end, encoded=%s",str);
  22.   return str;
  23. }
  24.  
  25. BOOL FAR PASCAL RemoteControlProc(HWND hWnd, unsigned message,DWORD wParam, LONG lParam)
  26. {
  27.   static PowerSettings *ps;
  28.  
  29.   switch (message) 
  30.   {
  31.     case WM_INITDIALOG:
  32.       {
  33.         char str[40];
  34.  
  35.         ps=(PowerSettings*)lParam;
  36.         sprintf(str,"%d",ps->remote_control.port);
  37.         SetDlgItemText(hWnd,IDC_REMOTE_PORT,str);
  38.         SetDlgItemText(hWnd,IDC_REMOTE_PASSWORD,"********");
  39.       }      
  40.       return TRUE;
  41.     case WM_COMMAND:
  42.       switch (LOWORD(wParam))
  43.       {
  44.         case IDCANCEL:
  45.           EndDialog(hWnd,TRUE);
  46.           break;
  47.         case IDOK:
  48.           {
  49.             char str[40];
  50.  
  51.             GetDlgItemText(hWnd,IDC_REMOTE_PORT,str,40);
  52.             ps->remote_control.port=atoi(str);
  53.             if (ps->remote_control.port<=0)
  54.               ps->remote_control.port=LISTEN_PORT;
  55.             GetDlgItemText(hWnd,IDC_REMOTE_PASSWORD,str,40);
  56.             if (strcmp(str,"********"))
  57.               strcpy(ps->remote_control.password,EncodePassword(str));
  58.             EndDialog(hWnd,TRUE);
  59.           }
  60.           break;
  61.       }
  62.       break;
  63.       default:
  64.          break;
  65.   }
  66.   return FALSE;
  67. }
  68.  
  69. void ShowRemoteControlDialog(HWND hWnd,PowerSettings *ps)
  70. {
  71.   FARPROC dlgproc;
  72.  
  73.   Log("ShowRemoteControlDialog start");
  74.   dlgproc=MakeProcInstance((FARPROC)RemoteControlProc,hInst);
  75.     if (DialogBoxParam(hInst,MAKEINTRESOURCE(IDD_REMOTE_CONTROL),hWnd,(DLGPROC)dlgproc,(LPARAM)ps)==-1)
  76.     DisplayLastError(ps,hWnd);
  77.     FreeProcInstance(dlgproc);
  78.   Log("ShowRemoteControlDialog end");
  79. }