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

📄 mianwindow.pas

📁 iocp远控比较完整的代码.iocp far more complete control of the code
💻 PAS
字号:
unit MianWindow;

 {$R CaptureMeidaClient.RES}

interface

uses
  Windows,
  Winsock,
  Messages,
  SelectEventClientClass,
  Const_PublicUnit, 
  PublicFunctionUnit;

//创建窗体,exe方式下使用
procedure CreateTheMainBoxForm;


implementation

var
  thehDlg : HWND;
  myTSelectEventClient : TSelectEventClient;



//call back function
function DlgProc(hDlg: HWND; Msg: UINT; wParam: WPARAM; lParam: LPARAM): BOOL; stdcall;
const
{$J+}
  hWndEdit: LongWord = 0;
{$J-}
var
  Rect: TRect;
  hMenu: LongWord;
  ServerIP : array[0..255] of char;
  ServerPort : array[0..15] of char;
  //创建视频类是否成功
  IsSucess : Boolean;
begin
  Result := FALSE;
  case (Msg) of
    WM_INITDIALOG:
      begin
        SetClassLong(hDlg, GCL_HICON, LoadIcon(hInstance, 'ICON32'));
        //show window in the screen center
        GetWindowRect(hDlg, Rect);
        SetWindowPos(hDlg, 0,
          (GetSystemMetrics(SM_CXSCREEN) - Rect.Right + Rect.Left) div 2,
          (GetSystemMetrics(SM_CYSCREEN) - Rect.Bottom + Rect.Top) div 2,
          0, 0, SWP_NOZORDER or SWP_NOSIZE);
        //innitial IP and port
        SendDlgItemMessage(hDlg, IDC_SERVER_BIND_IP, CB_ADDSTRING, 0, DWORD(PChar('192.168.1.6')));
        SendDlgItemMessage(hDlg, IDC_SERVER_BIND_IP, CB_ADDSTRING, 0, DWORD(PChar('kingniao2000.3322.org')));
        SendDlgItemMessage(hDlg, IDC_SERVER_BIND_IP, CB_ADDSTRING, 0, DWORD(PChar('192.168.91.100')));
        SendDlgItemMessage(hDlg, IDC_SERVER_BIND_IP, CB_ADDSTRING, 0, DWORD(PChar('192.168.91.90')));
        SendDlgItemMessage(hDlg, IDC_SERVER_BIND_IP, CB_ADDSTRING, 0, DWORD(PChar('127.0.0.1')));
        SendDlgItemMessage(hDlg, IDC_SERVER_BIND_IP, CB_SETCURSEL, 0, 0);                                                             
        SetDlgItemText(hDlg, IDC_CLIENT_BIND_PORT, '1980');
        //innitial description text
        hWndEdit := GetDlgItem(hDlg, IDC_MAIN_EDIT);
        SetDlgItemText(hDlg, IDC_MAIN_EDIT, 'application initial sucessed');
        SetFocus(hWndEdit);
        //append system menu
        hMenu := GetSystemMenu(hDlg, FALSE);
        AppendMenu(hMenu, MF_SEPARATOR, 0, nil);
        AppendMenu(hMenu, MF_STRING, IDM_SYS_ABOUT, 'About...');
        //save the handle
        thehDlg := hDlg;
      end;
     WM_NOTIFYTRANSFFERPROCESS:
      begin
        SetDlgItemText(thehDlg, IDC_ERROR_STRING, PChar(
         IntToStr(lParam) + '% stream has been transltated'));
      end;
     WsaNotifyMessage:
      begin
        case wParam of
          0:
          begin
            //显示错误代码
            SetDlgItemText(thehDlg, IDC_ERROR_STRING, pChar(IntToStr(lParam)));
          end;
          1:
          begin
            //处理连接断开的消息
            PostMessage(thehDlg, WM_COMMAND, MakeLong(IDSTOP, 0), lParam);
          end;
        end;
      end;
     WM_COMMAND:
      begin
        case LOWORD(wParam) of
          IDSTART:
           begin
             //将连接按钮设置为false,如果连接失败,那么会自动恢复的
             EnableWindow(GetDlgItem(hDlg, IDSTART), False);
             SetDlgItemText(hDlg, IDC_ERROR_STRING, 'client is connecting to server, please wait');
             GetDlgItemText(hDlg, IDC_SERVER_BIND_IP, ServerIP, 256);
             GetDlgItemText(hDlg, IDC_CLIENT_BIND_PORT, ServerPort, 16);
             try
               StrToInt(ServerPort);
             except
               SetDlgItemText(thehDlg, IDC_ERROR_STRING, 'please input number in the port edit');
               Exit;
             end;
             myTSelectEventClient := TSelectEventClient.Create(hDlg, ServerIP,
               StrToInt(ServerPort), IsSucess);
             if not IsSucess then
             begin
               //告诉主程序,没连接成功,lparam = 2 表示socket断开,1表示没连接成功, 0表示主动断开连接
               SendMessage(thehDlg, WsaNotifyMessage, 1, 1);
             end
             else
               SetDlgItemText(thehDlg, IDC_ERROR_STRING, 'client has successfully connected to server');
           end;
          IDSTOP:
           begin
             if myTSelectEventClient <> nil then
             begin
               FreeAndNil(myTSelectEventClient);
               case lParam of
                 0:
                   SetDlgItemText(thehDlg, IDC_ERROR_STRING, 'disconnet socket sucessed');
                 1:
                   SetDlgItemText(thehDlg, IDC_ERROR_STRING, 'client can not connect to server');
                 2:
                   SetDlgItemText(thehDlg, IDC_ERROR_STRING, 'server socket is closed');
                 else
                   SetDlgItemText(thehDlg, IDC_ERROR_STRING, 'disconnet socket sucessed');
               end;
             end;
             EnableWindow(GetDlgItem(hDlg, IDSTART), True);
           end;
          IDC_ABOUT:
           begin
             MessageBox(hDlg, ABOUT_STRING, szAppName, MB_OK or MB_ICONINFORMATION or MB_APPLMODAL);
           end;
          IDEXIT:
           begin
             //send exit command
             PostMessage(hDlg, WM_SYSCOMMAND, MakeLong(SC_CLOSE, 0), 1);
           end;
        end;
      end;
     WM_SYSCOMMAND:
       begin
         case LOWORD(wParam) of
           IDM_SYS_ABOUT:
            begin
              MessageBox(hDlg, ABOUT_STRING, szAppName, MB_OK or MB_ICONINFORMATION or MB_APPLMODAL);
            end;
           SC_CLOSE:
            begin
               if myTSelectEventClient <> nil then
                 FreeAndNil(myTSelectEventClient);
              EndDialog(hDlg, 0);
              Result := True;
            end;
         end;
       end;
  end;
end;


procedure CreateTheMainBoxForm;
begin
  if (DialogBox(hInstance, szAppName, 0, @DlgProc) = -1) then
    MessageBox(0, 'This program requires Windows NT!', szAppName, MB_ICONERROR);
end;

end.

⌨️ 快捷键说明

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