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

📄 u_crc_main.pas

📁 Voice Commnucation Components for Delphi
💻 PAS
📖 第 1 页 / 共 2 页
字号:
      connType := unapt_TCP;
  end;
  //
  a_cln_connect.enabled := false;
  if (windows.succeeded(f_client.connect(c_edit_srvAddr.text, c_edit_srvPort.text, connType))) then begin
    //
    a_cln_connect.enabled := false;
    a_cln_disconnect.enabled := true;
    a_cln_send.enabled := true;
    //
    a_cln_audioSetup.enabled := false;
    //
    checkCTT();
  end
  else
    a_cln_connect.enabled := true;
  //
end;

// --  --
procedure Tc_crcForm_main.a_cln_disconnectExecute(Sender: TObject);
begin
  //
  f_selfDisconnect := true;
  try
    // disconnect client
    f_client.disconnect();
    //
    a_cln_connect.enabled := true;
    a_cln_disconnect.enabled := false;
    a_cln_send.enabled := false;
    //
    a_cln_audioSetup.enabled := true;
  finally
    f_selfDisconnect := false;
  end;
end;

// --  --
procedure Tc_crcForm_main.a_cln_sendExecute(Sender: TObject);
begin
  f_client.sendText(c_edit_nickname.text + ' says: ' + getREwideText(c_re_userText));
  //
  c_re_userText.clear();
end;

// --  --
procedure Tc_crcForm_main.onClientSE(sender: tObject; connectionId: unsigned; event: unaSocketEvent; data: pointer; len: unsigned);
begin
  case (event) of

    // client
    unaseClientConnect: begin
      addToLog('Connected to remote server.');
    end;

    unaseClientDisconnect,

    // thread
    unaseThreadStartupError: begin
      //
      if (not f_selfDisconnect) then
	a_cln_disconnect.execute();
      //
      addToLog('Disconnected from server.');
    end;

  end;
end;

// --  --
procedure Tc_crcForm_main.onClientPE(sender: tObject; connectionId: unsigned; const packet: unavclInOutIPPacket);
begin
  case (packet.r_command) of

    cmd_inOutIPPacket_userData: begin
      // text data
      gotText(connectionId, @packet.r_data, packet.r_dataSize);
    end;

    cmd_inOutIPPacket_outOfSeats:
      addToLog('Server is out of seats.');

  end;
end;

// --  --
procedure Tc_crcForm_main.c_button_chooseFontClick(Sender: TObject);
begin
  if (c_fontDialog_chat.execute()) then begin
    //
    c_re_userText.font.assign(c_fontDialog_chat.font);
    c_re_chat.font.assign(c_fontDialog_chat.font);
    //
    setREwideText(c_re_chat, getREwideText(c_re_chat));
    setREwideText(c_re_userText, getREwideText(c_re_userText));
  end;
end;

// --  --
procedure Tc_crcForm_main.gotText(connId: unsigned; data: pointer; len: unsigned);
begin
  if ((nil <> data) and (1 < len) and (f_wideCount < high(f_wides))) then begin
    //
    if (f_wideGate.enter(100)) then
      try
	setLength(f_wides[f_wideCount], len shr 1);
	move(data^, f_wides[f_wideCount][1], len);
	inc(f_wideCount);
      finally
	f_wideGate.leave();
      end;
  end;
end;

// --  --
procedure Tc_crcForm_main.addToLog(const text: string);
begin
  if (nil <> f_log) then
    f_log.add('SYS: [' + dateTimeToStr(now) + '] ' + text);
end;

// --  --
procedure Tc_crcForm_main.Clear1Click(Sender: TObject);
begin
  c_re_chat.clear();
end;

// --  --
procedure Tc_crcForm_main.addWides();
var
  i: unsigned;
  result: wideString;
begin
  result := getREwideText(c_re_chat);
  //
  i := 0;
  while (i < f_wideCount) do begin
    //
    result := result + f_wides[i] + #13#10;
    inc(i);
  end;
  f_wideCount := 0;
  //
  setREwideText(c_re_chat, result);
end;

{$IFDEF __BEFORE_D5__ }

type
  GETTEXTEX = record
    cb: DWORD;                 { count of bytes in the string  }
    flags: DWORD;              { flags (see the GT_XXX defines }
    codepage: UINT;            { code page for translation (CP_ACP for default,
				 1200 for Unicode 					 }
    lpDefaultChar: LPCSTR;     { replacement for unmappable chars			 }
    lpUsedDefChar: PBOOL;      { pointer to flag set when def char used	 }
  end;
  {$EXTERNALSYM GETTEXTEX}
  TGetTextEx = GETTEXTEX;

{$ENDIF}

// --  --
function Tc_crcForm_main.getREwideText(re: TRichEdit): wideString;
var
  gte: GETTEXTEX;
  len: int;
begin
  if (g_wideApiSupported) then begin
    //
    setLength(result, 65535);
    //
    fillChar(gte, sizeof(gte), #0);
    gte.cb := 65534 * 2;
    gte.flags := GT_DEFAULT;
    gte.codepage := 1200;
    //
    len := sendMessage(re.handle, EM_GETTEXTEX, wParam(@gte), lParam(@result[1]));
    if (0 < len) then
      setLength(result, len)
    else
      result := '';
  end
  else begin
    //
    result := re.text;
  end;
end;

// --  --
function Tc_crcForm_main.setREwideText(re: TRichEdit; const text: wideString): LRESULT;
var
  ste: SETTEXTEX;
  buf: array[0..0] of wideChar;
begin
  if (g_wideApiSupported) then begin
    //
    ste.flags := ST_DEFAULT;
    ste.codepage := 1200;
    if ('' = text) then begin
      buf[0] := #0;
      result := LRESULT(SendMessage(re.handle, EM_SETTEXTEX, WPARAM(@ste), LPARAM(@buf[0])))
    end
    else
      result := LRESULT(SendMessage(re.handle, EM_SETTEXTEX, WPARAM(@ste), LPARAM(@text[1])))
  end
  else begin
    re.text := text;
    result := length(text);
  end;
end;

// --  --
procedure Tc_crcForm_main.c_comboBox_sdChange(Sender: TObject);
begin
  case (c_comboBox_sd.itemIndex) of

    1: // low
      f_client.setSilenceDetectionParams(100);

    2: // medium
      f_client.setSilenceDetectionParams(800);

    3: // high
      f_client.setSilenceDetectionParams(2000);

    4: // DSP
      f_client.setSilenceDetectionParams(c_unaConf_SD_useDSP);

    else // off
      f_client.setSilenceDetectionParams(c_unaConf_SD_useNone);

  end;
end;

// --  --
procedure Tc_crcForm_main.c_checkBox_recClick(Sender: TObject);
begin
  if (not f_timerUpdate) then
    f_client.recordingEnabled := c_checkBox_rec.checked;
  //
end;

// --  --
procedure Tc_crcForm_main.c_checkBox_playClick(Sender: TObject);
begin
  if (not f_timerUpdate) then
    f_client.playbackEnabled := c_checkBox_play.checked;
  //  
end;

// --  --
procedure Tc_crcForm_main.minMaxInfo(var message: TWMGetMinMaxInfo);
begin
  inherited;
  //
  message.MinMaxInfo.ptMinTrackSize.X := 454;
  message.MinMaxInfo.ptMinTrackSize.Y := 380;
end;

// --  --
procedure Tc_crcForm_main.c_button_clickTTClick(Sender: TObject);
begin
  if (c_form_clickToTalk.changeConfig(f_config)) then
    checkCTT();
end;

// --  --
procedure Tc_crcForm_main.checkCTT(updateParams: bool);
var
  talking: bool;
  pressed: bool;
begin
  if (updateParams) then begin
    //
    f_cct_enabled := f_config.get('cct.enabled', false);
    f_cct_hotkey := f_config.get('cct.hotkey', int($4054));	// CTRL + T
    f_cct_mode := f_config.get('cct.mode', int(0));
  end;
  //
  talking := true;
  //
  if (f_cct_enabled) then begin
    //
    pressed := (0 <> ($0000F000 and f_cct_hotKey)) or (0 <> ($FF and f_cct_hotKey));
    //
    if (0 <> ($00002000 and f_cct_hotKey)) then
      pressed := pressed and (0 <> ($8000 and (GetAsyncKeyState(VK_SHIFT))));
    if (0 <> ($00004000 and f_cct_hotKey)) then
      pressed := pressed and (0 <> ($8000 and (GetAsyncKeyState(VK_CONTROL))));
    if (0 <> ($00008000 and f_cct_hotKey)) then
      pressed := pressed and (0 <> ($8000 and (GetAsyncKeyState(VK_MENU))));
    if (0 <> ($FF and f_cct_hotKey)) then
      pressed := pressed and (0 <> ($8000 and (GetAsyncKeyState($FF and f_cct_hotKey))));
    //
    case (f_cct_mode) of

      0: begin
	// hold to talk
	talking := pressed;
      end;

      1: begin
	// toggle
	if (pressed) then
	  talking := f_client.recordingMuted
	else
	  talking := not f_client.recordingMuted;
      end;

    end;
  end;
  //
  f_client.recordingMuted := not talking;
  //
  if (f_client.ipClient.active) then
    c_statusBar_main.panels[1].text := choice(talking, 'Talking', 'Muted')
  else
    c_statusBar_main.panels[1].text := 'Not connected';
end;

// --  --
procedure Tc_crcForm_main.a_cln_audioSetupExecute(Sender: TObject);
begin
  // enum format is valid
  //
  c_form_common_audioConfig.enumFlags := 0;
  //
  if (0 = c_form_common_audioConfig.doConfig(f_client.waveIn, f_client.waveOut, f_client.codecIn, nil, f_config)) then ;
end;

// --  --
procedure Tc_crcForm_main.Exit1Click(Sender: TObject);
begin
  close();
end;

// --  --
procedure Tc_crcForm_main.About1Click(Sender: TObject);
begin
  guiMessageBox('Conference Room Client 1.2'#13#10'Copyright (c) 2003-2007 Lake of Soft, Ltd', 'About Conference Client', MB_OK or MB_ICONINFORMATION);
end;


end.

⌨️ 快捷键说明

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