📄 unit2.cpp
字号:
//---------------------------------------------------------------------------
#include <vcl.h>
#pragma hdrstop
#include <mmsystem.h>
#include "Unit2.h"
#include "Unit1.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
#pragma resource "sound.res"
TForm2 *Form2;
//---------------------------------------------------------------------------
__fastcall TForm2::TForm2(TComponent* Owner)
: TForm(Owner)
{
}
//---------------------------------------------------------------------------
void __fastcall TForm2::Button1Click(TObject *Sender)
{
if(Label2->Caption!="")
{
TMemoryStream *mStream = new TMemoryStream();
AnsiString strData,temp;
NMUDP1->ReportLevel = Status_Basic;
NMUDP1->RemoteHost = Label2->Caption;
NMUDP1->RemotePort = 4002;
strData = RichEdit1->Text;
RichEdit1->Clear();
if(strData!="")
{
temp = RichEdit2->Text;
RichEdit2->Clear();
RichEdit2->Text = "To "+Label2->Caption+": "+strData;
RichEdit2->Lines->Add(temp);
mStream->Write(&strData[1],strData.Length());
NMUDP1->SendStream(mStream);
}
mStream->Free();
}
}
//---------------------------------------------------------------------------
void __fastcall TForm2::NMUDP1InvalidHost(bool &handled)
{
MessageBox(0,"对方不在线!","NetQQ错误",0);
}
//---------------------------------------------------------------------------
void __fastcall TForm2::NMUDP1DataReceived(TComponent *Sender,
int NumberBytes, AnsiString FromIP, int Port)
{
if(NumberBytes>=1)
{
char *wav_handle;
HRSRC h = FindResource(HInstance,"CALL","MP3");
HGLOBAL h1 = LoadResource(HInstance, h);
wav_handle = (char *)LockResource(h1);
sndPlaySound(wav_handle,SND_MEMORY | SND_SYNC);
if(Form1->AutoOpen1->Checked)
{
ShowWindow(Form1->Handle ,SW_SHOW);
SetWindowPos(Form1->Handle,HWND_TOPMOST,0,0,0,0,SWP_NOMOVE|SWP_NOSIZE);
Form1->Visible = true;
SetWindowPos(Form2->Handle,HWND_TOPMOST,0,0,0,0,SWP_NOMOVE|SWP_NOSIZE);
ShowWindow(Form2->Handle ,SW_SHOW);
Form2->Visible = true;
}
else
Timer1->Enabled = true;
int index = Form1->ListBox2->Items->IndexOf(FromIP);
if(index>=0)
Label4->Caption = Form1->ListBox1->Items->Strings[index];
else
Label4->Caption = FromIP;
TMemoryStream *mStream = new TMemoryStream();
AnsiString strData,temp;
NMUDP1->ReadStream(mStream);
strData.SetLength(NumberBytes);
mStream->Read(&strData[1],NumberBytes);
if(strData!="")
{
temp = RichEdit2->Text;
RichEdit2->Clear();
RichEdit2->Lines->Add("From "+Label4->Caption+": "+strData);
RichEdit2->Lines->Add(temp);
}
mStream->Free();
}
}
//---------------------------------------------------------------------------
void __fastcall TForm2::Timer1Timer(TObject *Sender)
{
if(Timer1->Tag%2==0)
{
Form1->ModifyIcon(Application->Icon->Handle,Label4->Caption);
Timer1->Interval = 200;
}
else
{
Form1->ModifyIcon(Form1->Image1->Picture->Icon->Handle,Label4->Caption);
Timer1->Interval = 500;
}
Timer1->Tag++;
Timer1->Enabled =true;
}
//---------------------------------------------------------------------------
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -