void __fastcall TFormMain::DrawItem(TMessage& Msg) { IconDrawItem((LPDRAWITEMSTRUCT)Msg.LParam); TForm::Dispatch(&Msg); } //--------------------------------------------------------------------------- void __fastcall TFormMain::MyNotify(TMessage& Msg) { POINT MousePos; switch(Msg.LParam) { case WM_RBUTTONUP: if (GetCursorPos(&MousePos)) { PopupMenu1->PopupComponent = FormMain; SetForegroundWindow(Handle); PopupMenu1->Popup(MousePos.x, MousePos.y); } else Show(); break; case WM_LBUTTONDBLCLK: Show(); break; default: break; } TForm::Dispatch(&Msg); } //--------------------------------------------------------------------------- //--------------------------------------------------------------------------- bool __fastcall TFormMain::TrayMessage(DWORD dwMessage) { NOTIFYICONDATA tnd; PSTR pszTip; pszTip = TipText(); tnd.cbSize = sizeof(NOTIFYICONDATA); tnd.hWnd = Handle; tnd.uID = IDC_MYICON; tnd.uFlags = NIF_MESSAGE | NIF_ICON | NIF_TIP; tnd.uCallbackMessage = MYWM_NOTIFY; if (dwMessage == NIM_MODIFY) { tnd.hIcon = (HICON)IconHandle(); if (pszTip) lstrcpyn(tnd.szTip, pszTip, sizeof(tnd.szTip)); else tnd.szTip[0] = '\0'; } else { tnd.hIcon = NULL; tnd.szTip[0] = '\0'; } return (Shell_NotifyIcon(dwMessage, &tnd)); } //--------------------------------------------------------------------------- HICON __fastcall TFormMain::IconHandle(void) { return (Image2->Picture->Icon->Handle); } //--------------------------------------------------------------------------- PSTR __fastcall TFormMain::TipText(void) { return ("Office Chat"); } //--------------------------------------------------------------------------- LRESULT IconDrawItem(LPDRAWITEMSTRUCT lpdi) { return 0; } //--------------------------------------------------------------------------- //--------------------------------------------------------------------------- void __fastcall TFormMain::FormDestroy(TObject *Sender) { TrayMessage(NIM_DELETE); } //--------------------------------------------------------------------------- void __fastcall TFormMain::N1Click(TObject *Sender) { Show(); } //--------------------------------------------------------------------------- void __fastcall TFormMain::N2Click(TObject *Sender) { Application->Terminate(); } //--------------------------------------------------------------------------- void __fastcall TFormMain::FormCloseQuery(TObject *Sender, bool &CanClose) { CanClose=false; FormMain->Hide(); } //---------------------------------------------------------------------------
void __fastcall TForm1::ClientSocketRead(TObject *Sender, TCustomWinSocket *Socket) { AnsiString str=Now().CurrentDateTime(); message=Socket->ReceiveText(); AnsiString recieveText=message; AnsiString Text=recieveText; if(message.SubString(1,4).AnsiCompare("4796")==0) { ClientSocket->Socket->SendText("6141"+myname); } else if(message.SubString(1,4).AnsiCompare("7788")==0) { if(TabControl1->Tabs->operator [](TabControl1->TabIndex).AnsiCompare(message.SubString(5,message.Pos(":")-5))==0) { ListBox->Lines->Add(str+" "+message.SubString(5,message.Length())); file(message.SubString(5,message.Pos(":")-5),message.SubString(message.Pos(":")+1,message.Length()),Now().CurrentDateTime(),"in"); PlaySound("message.wav",0,SND_ASYNC); PopupMenu2->PopupComponent = Form1; PopupMenu2->Popup(GetSystemMetrics(SM_CXSCREEN)-200, 20); } else if(TabControl1->Tabs->operator [](TabControl1->TabIndex).AnsiCompare(message.SubString(5,message.Pos(":")-5))!=0) { PlaySound("message.wav",0,SND_ASYNC); AnsiString im; AnsiString mess; im=message.SubString(5,message.Pos(":")-5); mess=message.SubString(message.Pos(":")+1,message.Length()); file(im,mess,Now().CurrentDateTime(),"in"); AnsiString name=message.SubString(5,message.Pos(":")-5); active=TabControl1->TabIndex; count=TabControl1->Tabs->Count; AnsiString n; TabControl1->Tabs->Clear(); for(int i=0;i<count;i++) { n=m[i]; if(n.AnsiCompare(name)!=0) TabControl1->Tabs->Add(n); else if(n.AnsiCompare(name)==0) TabControl1->Tabs->Add(n+"+1"); } } } else if(message.SubString(1,4).AnsiCompare("8714")==0) { TabControl1->Tabs->Clear(); AnsiString str=message.SubString(5,message.Length()); const char separator[]=","; int i=0; char *Ptr=NULL; Ptr=strtok(str.c_str(),separator); while (Ptr) { //if(myname.AnsiCompare(Ptr)!=0) TabControl1->Tabs->Add(Ptr); strcpy(m[i],Ptr); Ptr=strtok(0,separator); i++; } } }
Source: https://habr.com/ru/post/259655/
All Articles