Written using C++ Builder 6
//---------------------------------------------------------------------------
#include <vcl.h>
#pragma hdrstop
#include "MsgForm.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TMsgDlg *MsgDlg;
//---------------------------------------------------------------------------
__fastcall TMsgDlg::TMsgDlg(TComponent* Owner)
: TForm(Owner)
{
}
//---------------------------------------------------------------------------
void __fastcall TMsgDlg::ExitBtnClick(TObject *Sender)
{
Close();
}
//---------------------------------------------------------------------------
void __fastcall TMsgDlg::SendBtnClick(TObject *Sender)
{
TStringList *MyStrings = new TStringList();
AnsiString s1,s2;//temp strings
s1 = AnsiQuotedStr(Edit1->Text,'"');//user
s2 = AnsiQuotedStr(Edit2->Text,'"');//message
try{
MyStrings->Clear();
MyStrings->Add("msg " + s1 + " " + s2);//command
MyStrings->Add("del SendMsg.bat");//cleanup
MyStrings->Add("exit");//close batch program
MyStrings->SaveToFile("SendMsg.bat");
}
__finally{ delete MyStrings;}
if(s1 != "\"\"")//we have a user
{
if(s2 != "\"\"")//we have a message
{
if(FileExists("SendMsg.bat"))//we have a batfile
{
AnsiString sExe = "SendMsg.bat";
SHELLEXECUTEINFO execinfo ;
memset (&execinfo, 0, sizeof (execinfo)) ;
execinfo.cbSize = sizeof (execinfo) ;
execinfo.lpVerb = "open" ;
execinfo.lpFile = sExe.c_str() ;
execinfo.lpParameters = "" ;
execinfo.fMask = SEE_MASK_NOCLOSEPROCESS ;
execinfo.nShow = SW_HIDE;
if (! ShellExecuteEx (&execinfo))//didn't execute
{
ShowMessage("ERROR::0x\\0010\nCould not create process - SendMsg");
return ;//error value
}
Label3->Caption = "Message sent.";//did execute
Label3->Visible = true;
}
if(bBeep)//confirmation menu item checked
{
ShowMessage("message: " + s2 + "\nsent to: " + s1);
}
}
if(s2 == "\"\"")//no message
{
Label3->Caption = "No message to send.";
}
}
Edit2->SetFocus();
Edit2->Clear();//ready for another message to same user
}
//---------------------------------------------------------------------------
void __fastcall TMsgDlg::Edit2KeyPress(TObject *Sender, char &Key)
{
Label3->Visible = false;
}
//---------------------------------------------------------------------------
void __fastcall TMsgDlg::FormClose(TObject *Sender, TCloseAction &Action)
{
DeleteFile("sendmsg.bat");//dbl-checking
}
//---------------------------------------------------------------------------
void __fastcall TMsgDlg::Beep1Click(TObject *Sender)
{
if(Beep1->Checked) //bool bBeep declared in .h
{
bBeep = true;
}
else
{
bBeep = false;
}
}
//---------------------------------------------------------------------------

No comments:
Post a Comment