📄 display.cpp
字号:
// log.WriteString("\nPlaying......");
disp=" "+header+" is talking...";
SetDlgItemText(6051,(char*)(LPCTSTR)disp);
/*
if(from->FindStringExact(-1,header)==LB_ERR)
{
from->ResetContent();
from->AddString(header);
}
*/
// reccount++;
// sprintf(str,"\n No of Messages received = %d ",reccount);
// log.WriteString(str);
}
}
/* */
/* This function will flash the window whenever */
/* important message has been received...shutdown,logout..etc */
/* */
void Display::showFlash()
{
//flash for 3 times
FlashWindow(TRUE);
Sleep(200);
FlashWindow(TRUE);
}
//
// After pressing the Save button ...
//
//
void Display::OnStartWrite(char *name)
{
isSave=TRUE;
log.WriteString("\n Calling create fun of thread");
write->PostThreadMessage(WM_WRITESOUND_CREATEFILE,0,(LPARAM)name);
}
//
// After pressing the Save button ...later stop...
//
void Display::OnStopWrite()
{
isSave=FALSE;
write->PostThreadMessage(WM_WRITESOUND_CLOSEFILE,0,0);
}
/* */
/* This function will be called whenever user */
/* selects one of the radio button (*all or *client) */
/* */
void Display::OnChange(int id)
{
CString bmesg;
if(cbox->GetCount()<=0)
return;
if(id==IDC_RADIO1 && radio1->GetCheck()) //Send to client
{
cbox->EnableWindow(TRUE);
if(cbox->GetCount()>=1)
{
curuser.Empty();
cbox->GetLBText(cbox->GetCurSel(),curuser);
log.WriteString("\nConnected to user "+curuser);
selectflag=1;
startRecording();
}
else
{
curuser.Empty();
selectflag=0;
stopRecording();
//stopPlaying(); //****** REMOVED ******//
}
}
if(id==IDC_RADIO2 && radio2->GetCheck()) //Send to All
{
curuser="ALL";
if(isstart==0) //Stop the record and play
OnStop();
log.WriteString("\n Broadcasting message");
Broadcast bd(IDD_DIALOG5,this);
bd.DoModal();
bmesg="OVER:";
selectflag=1;
if(sockclt.Send(bmesg,bmesg.GetLength()))
log.WriteString("\n Over Mesg sent to Server");
else
log.WriteString("\n Unable to send over mesg to Server");
curuser.Empty();
radio1->SetCheck(1);
radio2->SetCheck(0);
}
}
/* */
/* This function will be called whenever client */
/* receives new userlist from the server and it will */
/* update the combo box */
/* */
void Display::updateList(CString mesg)
{
int index,num,prevcount;
CString name;
static int first=0;
CString disp;
//Clear the combo box contents
prevcount=cbox->GetCount();
cbox->ResetContent();
do
{
index=mesg.Find(';');
if(index==-1)
break;
name=mesg.Left(index);
if(name.CompareNoCase(sockclt.name)!=0)
cbox->AddString(name);
mesg=mesg.Right(mesg.GetLength()-index-1);
}
while(TRUE);
if(cbox->GetCount()==1)
{
cbox->SetCurSel(0);
cbox->GetLBText(0,curuser);
selectflag=1;
if(prevcount==0 && first==1)
{
showFlash();
disp="New user " + curuser + " logged in";
SetDlgItemText(6051,(char*)(LPCTSTR)disp);
}
}
first=1;
if(cbox->GetCount()>1)
{
if(curuser.IsEmpty()==FALSE)
{
if((num=cbox->FindStringExact(-1,curuser))>=0)
{
selectflag=1;
cbox->SetCurSel(num);
return;
}
}
selectflag=0;
OnStop();
// stopRecording();
cbox->SetCurSel(0);
if(curuser.IsEmpty()==FALSE && curuser!="ALL" )
{
showFlash();
disp=curuser+" logged out \n Please select the user";
SetDlgItemText(6051,(char*)(LPCTSTR)disp);
// MessageBox(curuser+" logged out ......Please select the user");
}
else if(curuser!="ALL")
{
showFlash();
disp="New user logged in";
SetDlgItemText(6051,(char*)(LPCTSTR)disp);
//MessageBox("New user logged in....");
}
}
if(cbox->GetCount()==0)
{
OnStop();
//stopRecording();
//stopPlaying(); //******* REMOVED *******//
if(curuser.IsEmpty()==FALSE && curuser!="ALL")
{
showFlash();
disp=curuser+" logged out";
SetDlgItemText(6051,(char*)(LPCTSTR)disp);
// MessageBox(curuser+" logged out");
}
//SetDlgItemText(6051,"");
//from->ResetContent(); //Clear the From Listbox
curuser.Empty();
}
}
/* */
/* This function will be called whenever user */
/* presses the start/stop button */
/* It updates the button status and starts recording and playing. */
/* */
void Display::OnStart()
{
if(cbox->GetCount()<1)
{
MessageBox("No users are present");
return;
}
if(!isstart)
return;
if(doit==TRUE)
talk->Play(0,-1,-1);
cbox->GetLBText(cbox->GetCurSel(),curuser);
selectflag=1;
//Start recording and playing...
startRecording();
startPlaying();
log.WriteString("\n New Target user is "+ curuser);
//change state
isstart=0;
start->ShowWindow(FALSE);
stop->ShowWindow(TRUE);
}
/* */
/* This function will be called whenever user */
/* presses the Stop button */
/* */
void Display::OnStop()
{
if(isstart)
return;
if(doit==TRUE)
talk->Stop();
stopRecording();
stopPlaying();
selectflag=0;
//change state
isstart=1;
start->ShowWindow(TRUE);
stop->ShowWindow(FALSE);
}
//
//*** Part of this code needs to be removed later***
//
void Display::startRecording()
{
if(record->recording==FALSE)
{
// if(sockclt.name.CompareNoCase("logname")==0)
record->PostThreadMessage(WM_RECORDSOUND_STARTRECORDING,0,0);
}
}
/* */
/* This function will stop the recording by sending */
/* stop message to recording thread */
/* */
void Display::stopRecording()
{
if(record->recording==TRUE)
record->PostThreadMessage(WM_RECORDSOUND_STOPRECORDING,0,0);
}
/* */
/* This function will stop the playing by sending */
/* stop message to player thread. */
/* */
void Display::startPlaying()
{
if(play->Playing==FALSE)
play->PostThreadMessage(WM_PLAYSOUND_STARTPLAYING,0,0);
}
/* */
/* This function will stop the playing by sending */
/* stop message to player thread. */
/* */
void Display::stopPlaying()
{
if(play->Playing==TRUE)
play->PostThreadMessage(WM_PLAYSOUND_STOPPLAYING,0,0);
}
/* */
/* This function will send the voice data to the server */
/* (called from the Recorder Thread) */
/* */
void Display::sendMessage(char *mesg,int length)
{
char buflen[15];
char str[PLAYBUFFER+50];
int i,j;
//If user not selected or no users are present return;
if(selectflag==0 )
return;
if(mesg==NULL)
{
log.WriteString("\nEmpty buffer received from recordsound");
return;
}
if(length<1 || length>PLAYBUFFER)
{
log.WriteString("\n Send : Length is more than the 2000 or less than 1");
return;
}
mesg=mesg-20;
//First 15 bits contains the destination information
//Next 5 bits contains the length of message
//Remaining part contains the data
if(curuser.IsEmpty())
{
log.WriteString("\n Curuser is Empty- No user selected");
return;
}
for(i=0;i < curuser.GetLength();i++)
mesg[i]=curuser[i];
mesg[i]=':';
sprintf(buflen,"%d",length);
for(j=0,i=15;j<5;j++,i++)
mesg[i]=buflen[j];
//Write to log file
sprintf(str,"\n Sending message datalen = %d , mesg = %s",length,&mesg[20]);
log.WriteString(str);
// sendcount++;
// sprintf(str,"\n No of Messages Sent = %d ",sendcount);
// log.WriteString(str);
if(sockclt.Send(mesg,length+20)!=SOCKET_ERROR )
log.WriteString("\n Data sent successfully to "+curuser);
else
log.WriteString("\n Data sent Error ");
}
/* */
/* Display the About Dialog Box */
/* */
void Display::OnAbout()
{
about my(IDD_DIALOG2);
my.DoModal();
}
/* */
/* Display the About Dialog Box */
/* */
void Display::OnSave()
{
if(curuser.IsEmpty())
{
MessageBox("\n First connect to one of the user...");
return;
}
writeuser=curuser;
Save sa(IDD_DIALOG4,this);
sa.DoModal();
}
/* */
/* This function will destroy the client window and */
/* closes all threads and socket connecion */
/* */
void Display::OnCancel()
{
log.WriteString("\n Closing the dialog box");
//Stop the recording and playing threads
if(record->recording==TRUE)
record->PostThreadMessage(WM_RECORDSOUND_STOPRECORDING,0,0);
record->PostThreadMessage(WM_RECORDSOUND_ENDTHREAD,0,0);
if(play->Playing==TRUE)
play->PostThreadMessage(WM_PLAYSOUND_STOPPLAYING,0,0);
play->PostThreadMessage(WM_PLAYSOUND_ENDTHREAD,0,0);
write->PostThreadMessage(WM_WRITESOUND_ENDTHREAD,0,0);
if(sockclt.closeflag==1)
{
showFlash();
MessageBox("Server has shutdown");
}
if(isconnected==TRUE)
sockclt.Close();
CDialog::OnCancel();
}
/* */
/* This function will display the volume setting */
/* dialog box. */
/* */
void Display::OnVolume()
{
Volume vol(IDD_DIALOG3);
vol.DoModal();
}
/* */
/* This function will play the stored sound */
/* */
/* */
void Display::OnPlay()
{
CFileDialog fd(1,0,0,0,"Sound Files(*.wav)|*.wav|All Files|*.*||" );
fd.m_ofn.lpstrTitle="Browse";
if(isstart==0)
{
MessageBox("Please stop chatting...");
return;
}
if(fd.DoModal()==IDOK)
{
sndPlaySound(fd.GetPathName(),SND_ASYNC);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -