Article View: borland.public.cppbuilder.nativeapi
Article #10786Re: How to activate application from inactive state
From: agus
Date: Mon, 15 Mar 2004 04:21
Date: Mon, 15 Mar 2004 04:21
139 lines
5586 bytes
5586 bytes
I am apologize if I didn't clearly explained my problem, because
English is not my nature language.
Let me try to explain again. What I want is like this :
1. I run my application, then minimized in tray icon.
2. I run another window's application, ex Notepad.
3. When there is incoming data in communication port,
my application aware of this data and do the task I want,
for ex show a message box that there is a new data,
even I still work in Notepad. This was not happened with
my application. It is only work it my application is the
active application.
Here are my actual code :
********* BEGIN of CODE ******
#include <vcl.h>
#pragma hdrstop
#include "SmsInterface.h"
#include "SmsUtility.h"
//--------------------------------------------------------------------------
-
#pragma package(smart_init)
#pragma link "MSCommLib_OCX"
#pragma link "trayicon"
#pragma resource "*.dfm"
TSmsInterfaceFrm *SmsInterfaceFrm;
//--------------------------------------------------------------------------
-
void __fastcall TSmsInterfaceFrm::AppIdle(TObject *Sender,
bool &Done)
{
SendCommand("Read New Mail","");
AnsiString I = ReadInput("at+cmgl=0");
if(ReadMail(I))
{
ShowMessage("Success");
}
}
//--------------------------------------------------------------------------
-
__fastcall TSmsInterfaceFrm::TSmsInterfaceFrm(TComponent* Owner)
: TForm(Owner)
{
if (!Comm->PortOpen) Comm->PortOpen = true;
MsgCentreNo = "07912618010000F0";
}
//--------------------------------------------------------------------------
-
__fastcall TSmsInterfaceFrm::~TSmsInterfaceFrm()
{
if (Comm->PortOpen) Comm->PortOpen = false;
}
//--------------------------------------------------------------------------
-
void TSmsInterfaceFrm::SendCommand(AnsiString Command, AnsiString Parameter)
{
while(Comm->InBufferCount > 0) {Comm->Input;}
if(Command == "Check Port") Comm->Output = "ate1\x0D";
else if (Command == "Read All Mail") Comm->Output = "at+cmgl=1\r" ;
else if (Command == "Read New Mail") Comm->Output = "at+cmgl=0\r" ;
else if (Command == "Delete Mail")
Comm->Output = "at+cmgd=" + Parameter + "\r" ;
else if (Command == "Send Mail Command")
{
Comm->Output = "at+cmgs=" + Parameter + "\r" ;
while(Comm->InBufferCount <= 0) {}
}
else if (Command == "Send Mail Content") Comm->Output = Parameter;
}
//--------------------------------------------------------------------------
-
AnsiString TSmsInterfaceFrm::ReadInput(AnsiString Command)
{
while(Comm->InBufferCount <= 0) {};
AnsiString Rsl = "";
AnsiString Tmp = "";
AnsiString Input = "";
while(Rsl != "OK")// && Rsl != "ERROR")
{
Tmp = Comm->Input;
if(Tmp == "O" || Tmp == "K") Rsl = Rsl + Tmp;
else if(Tmp != "\r") Input = Input + Tmp;
}
if(Input.TrimLeft().SubString(1,Command.Length()) == Command &&
Input.TrimLeft().TrimRight().Length() == Command.Length()) return
"";
Input = RemoveSMSCommandReceive(Input);
return Input.TrimRight();
}
//--------------------------------------------------------------------------
-
bool TSmsInterfaceFrm::ReadMail(AnsiString I)
{
if(!I.IsEmpty())
{
AnsiString Tmp;
AnsiString Order, Type, HpNo, Msg;
int NextSms = FindNextSMSTag(I);
while(!I.IsEmpty())
{
if(NextSms > 1)
{
Tmp = I.SubString(1, NextSms -1);
I = I.SubString(NextSms, I.Length() - (NextSms - 1));
}
else
{
Tmp = I; I = "";
}
Order=""; Type=""; HpNo=""; Msg="";
ParseSMSReceiveCommand(Tmp, &Order, &HpNo, &Type, &Msg);
Memo->Lines->Add("Message Order : " + Order);
Memo->Lines->Add("Message Type : " + Type);
if(Type == "Normal")
{
Memo->Lines->Add("Hp No : " + HpNo);
Memo->Lines->Add("Message is : " + DecodeToWord(Msg));
}
Memo->Lines->Add("");
NextSms = FindNextSMSTag(I);
}
return true;
}
else return false;
}
//--------------------------------------------------------------------------
-
********* END of CODE ******
Regards,
Agus
Technical Details
Message-ID:
<40552f34@newsgroups.borland.com>Path:
arc1-ca.pugleaf.net!archiver1.google.com!news2.google.com!news.maxwell.syr.edu!logbridge.uoregon.edu!newsfeeds.ihug.co.nz!ihug.co.nz!newsgroups.borland.com!not-for-mailReferences:
<40540e1e@newsgroups.borland.com> <40541298@newsgroups.borland.com> <405452ad@newsgroups.borland.com> <4054cd31@newsgroups.borland.com>Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 10cc67,ac78bb8d3f6ec5bf X-Google-Attributes: gid10cc67,public X-Google-ArrivalTime: 2004-03-14 20:34:59 PST From: "agus" <seim@bdg.centrin.net.id> Newsgroups: borland.public.cppbuilder.nativeapi References: <40540e1e@newsgroups.borland.com> <40541298@newsgroups.borland.com> <405452ad@newsgroups.borland.com> <4054cd31@newsgroups.borland.com> Subject: Re: How to activate application from inactive state Date: Mon, 15 Mar 2004 11:21:04 +0700 Lines: 141 X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.2800.1106 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1106 NNTP-Posting-Host: 202.146.228.176 Message-ID: <40552f34@newsgroups.borland.com> X-Trace: newsgroups.borland.com 1079324468 202.146.228.176 (14 Mar 2004 20:21:08 -0800) Path: arc1-ca.pugleaf.net!archiver1.google.com!news2.google.com!news.maxwell.syr.edu!logbridge.uoregon.edu!newsfeeds.ihug.co.nz!ihug.co.nz!newsgroups.borland.com!not-for-mail