// FiveWin Phone - (c) FiveTech 1993-5
// A.Linares
#include "FiveWin.ch"
#include "Folder.ch"
#include "Phone.ch"
#define FULL_SIZE 405
#define HALF_SIZE 260
#define IN_BUFFER 254 //20
#define TERM_SIZE 300
//extern Set, GetTextWidth // Blinker stuff
static nComm, cTerminal, oTerminal, cComm
static cNumber
static oSpeaker, oHangDown, oLocalNum, oNumber
static aPredefined, cCadena
//----------------------------------------------------------------------------//
function Main()
local oDlg, oBrw
local cLocalNum := "123456789"
local oHand
local lOpened := .t.
cCadena := ""
IF ISEXERUNNING( CFILENAME( HB_ARGV( 0 ) ) ) // evita el doble arranque
MsgWait("Phone está en Ejecución","---",2)
Return(Nil)
ENDIF
cComm := "COM3"
cNumber = Space( 20 )
SET _3DLOOK ON
//MsgLogo( "FwPhone", 2 )
LoadPredPhones()
if ! File( "phone.dbf" )
DbCreate( "Phone", { { "LAST", "C", 30, 0 },;
{ "FIRST", "C", 30, 0 },;
{ "NUMBER", "C", 20, 0 } } )
endif
USE Phone
DEFINE CURSOR oHand RESOURCE "Catch"
DEFINE DIALOG oDlg RESOURCE "Phone"
oDlg:bCommNotify = { | nComm, nStatus | BytesAtPort( nComm, nStatus ) }
REDEFINE BITMAP oSpeaker ID ID_SPEAKER OF oDlg RESOURCE "Speaker" ;
ON CLICK HangUp( .t. )
oSpeaker:oCursor = oHand
REDEFINE BUTTON oHangDown ID ID_HANGDOWN OF oDlg ACTION HangDown()
REDEFINE GET oLocalNum VAR cLocalNum ID ID_LOCALNUM OF oDlg
REDEFINE GET oNumber VAR cNumber ID ID_NUMBER OF oDlg
REDEFINE GET oTerminal VAR cTerminal MEMO ID ID_TERMINAL OF oDlg
REDEFINE BUTTON ID ID_ONE OF oDlg ;
ACTION ( cNumber := PadR( AllTrim( cNumber ) + "1", 20 ),;
oNumber:Refresh() )
REDEFINE BUTTON ID ID_TWO OF oDlg ;
ACTION ( cNumber := PadR( AllTrim( cNumber ) + "2", 20 ),;
oNumber:Refresh() )
REDEFINE BUTTON ID ID_THREE OF oDlg ;
ACTION ( cNumber := PadR( AllTrim( cNumber ) + "3", 20 ),;
oNumber:Refresh() )
REDEFINE BUTTON ID ID_FOUR OF oDlg ;
ACTION ( cNumber := PadR( AllTrim( cNumber ) + "4", 20 ),;
oNumber:Refresh() )
REDEFINE BUTTON ID ID_FIVE OF oDlg ;
ACTION ( cNumber := PadR( AllTrim( cNumber ) + "5", 20 ),;
oNumber:Refresh() )
REDEFINE BUTTON ID ID_SIX OF oDlg ;
ACTION ( cNumber := PadR( AllTrim( cNumber ) + "6", 20 ),;
oNumber:Refresh() )
REDEFINE BUTTON ID ID_SEVEN OF oDlg ;
ACTION ( cNumber := PadR( AllTrim( cNumber ) + "7", 20 ),;
oNumber:Refresh() )
REDEFINE BUTTON ID ID_EIGHT OF oDlg ;
ACTION ( cNumber := PadR( AllTrim( cNumber ) + "8", 20 ),;
oNumber:Refresh() )
REDEFINE BUTTON ID ID_NINE OF oDlg ;
ACTION ( cNumber := PadR( AllTrim( cNumber ) + "9", 20 ),;
oNumber:Refresh() )
REDEFINE BUTTON ID ID_ZERO OF oDlg ;
ACTION ( cNumber := PadR( AllTrim( cNumber ) + "0", 20 ),;
oNumber:Refresh() )
REDEFINE BUTTON ID ID_MORE OF oDlg ;
ACTION ( If( ! lOpened,;
( lOpened := .t., oDlg:SetSize( 0, FULL_SIZE ) ),;
( lOpened := .f., oDlg:SetSize( 0, HALF_SIZE ) ) ), oDlg:Refresh() )
REDEFINE BUTTON ID ID_PLAY OF oDlg ;
ACTION If( ! Empty( cNumber ), ( HangUp( .f. ), DialNumber( cNumber ) ),)
REDEFINE BUTTON ID ID_CLOSE OF oDlg ACTION oDlg:End()
REDEFINE BUTTON ID ID_BLANK OF oDlg ;
ACTION ( cNumber := Space( 20 ), oNumber:Refresh(),;
cTerminal := Space( 50 ), oTerminal:Refresh() )
REDEFINE BUTTON PROMPT aPredefined[ 1 ] ID ID_PRED1 OF oDlg ;
ACTION Predefined( 1 )
REDEFINE BUTTON PROMPT aPredefined[ 2 ] ID ID_PRED2 OF oDlg ;
ACTION Predefined( 2 )
REDEFINE BUTTON PROMPT aPredefined[ 3 ] ID ID_PRED3 OF oDlg ;
ACTION Predefined( 3 )
REDEFINE BUTTON PROMPT aPredefined[ 4 ] ID ID_PRED4 OF oDlg ;
ACTION Predefined( 4 )
REDEFINE BUTTON PROMPT aPredefined[ 5 ] ID ID_PRED5 OF oDlg ;
ACTION Predefined( 5 )
REDEFINE BUTTON PROMPT aPredefined[ 6 ] ID ID_PRED6 OF oDlg ;
ACTION Predefined( 6 )
REDEFINE BUTTON PROMPT aPredefined[ 7 ] ID ID_PRED7 OF oDlg ;
ACTION Predefined( 7 )
REDEFINE BUTTON PROMPT aPredefined[ 8 ] ID ID_PRED8 OF oDlg ;
ACTION Predefined( 8 )
REDEFINE LISTBOX oBrw ;
FIELDS AllTrim( Phone->Last ) + ", " + AllTrim( Phone->First ),;
Phone->Number ;
HEADERS "Name", "Number" ;
ID ID_DATABASE OF oDlg ;
ON DBLCLICK ( cNumber := Phone->Number, oNumber:Refresh(),;
HangUp( .f. ), DialNumber( cNumber ) )
REDEFINE TABS ID ID_SECTIONS OF oDlg ;
PROMPTS "&Personal", "&Bussiness", "&Home" ;
ACTION MsgBeep()
REDEFINE BUTTON ID ID_ADD OF oDlg ;
ACTION ( Phone->( DbAppend() ), oBrw:GoTop() )
ACTIVATE DIALOG oDlg ;
ON INIT ( oDlg:SetSize( 0, FULL_SIZE ),; //HALF_SIZE ),;
oHangDown:Hide(), oLocalNum:Hide(),;
If( ! lInitModem(), oDlg:End(),),;
EnableCommNotification( nComm, oDlg:hWnd, IN_BUFFER, IN_BUFFER ) );
VALID ( CloseComm( nComm ), .t. )
//escribetxt(cCadena)
return nil
//----------------------------------------------------------------------------//
function lInitModem()
local cDcb, nError, nBytes
nComm = OpenComm( cComm, 1024, 128 )
if ! BuildCommDcb( cComm + ":2400,n,8,1", @cDcb )
nError = GetCommError( nComm )
MsgStop( "Error initializing modem!", "1" )
return .f.
endif
#ifdef __CLIPPER__
if ! SetCommState( cDcb )
#else
if ! SetCommState( nComm, cDcb )
#endif
nError = GetCommError( nComm )
MsgStop( "Error initializing modem!","2" )
return .f.
endif
if ( nBytes := WriteComm( nComm, "ATZ0" + Chr( 13 ) ) ) < 0
nError = GetCommError( nComm )
MsgStop( "Error initializing modem!","3" )
return .f.
endif
WriteComm(nComm, "AT S0=0 X4" + Chr( 13 ) ) // S0=n n=numero de RINGs para contestar automaticamente
WriteComm(nComm, "AT #CID=2" + Chr( 13 ) ) // "AT #CID=1" Activar identificacion de llamada
return .t.
//----------------------------------------------------------------------------//
function DialNumber( cNumber )
local nBytes := WriteComm( nComm, AllTrim( cNumber ) + Chr( 13 ) )
if nBytes < 0
MsgStop( "Modem error: " + Str( GetCommError( nComm ) ) )
endif
return nil
//----------------------------------------------------------------------------//
function SendModem( cMsg )
local nBytes := WriteComm( nComm, cMsg )
if nBytes < 0
MsgStop( "Modem error: " + Str( GetCommError( nComm ) ) )
endif
return nil
//----------------------------------------------------------------------------//
function HangUp( lOpen )
oSpeaker:Hide()
oHangDown:Show()
oLocalNum:Show()
SendModem( "ATDT" + If( lOpen, Chr( 13 ), " " ) )
SysRefresh()
return nil
//----------------------------------------------------------------------------//
function HangDown()
SendModem( "ATH" + Chr( 13 ) )
oHangDown:Hide()
oLocalNum:Hide()
oSpeaker:Show()
return nil
//----------------------------------------------------------------------------//
function LoadPredPhones()
local oIni
aPredefined = Array( 8 )
INI oIni FILENAME ".\phone.ini"
GET aPredefined[ 1 ] SECTION "Predefined" ENTRY "1" OF oIni DEFAULT ""
GET aPredefined[ 2 ] SECTION "Predefined" ENTRY "2" OF oIni DEFAULT ""
GET aPredefined[ 3 ] SECTION "Predefined" ENTRY "3" OF oIni DEFAULT ""
GET aPredefined[ 4 ] SECTION "Predefined" ENTRY "4" OF oIni DEFAULT ""
GET aPredefined[ 5 ] SECTION "Predefined" ENTRY "5" OF oIni DEFAULT ""
GET aPredefined[ 6 ] SECTION "Predefined" ENTRY "6" OF oIni DEFAULT ""
GET aPredefined[ 7 ] SECTION "Predefined" ENTRY "7" OF oIni DEFAULT ""
GET aPredefined[ 8 ] SECTION "Predefined" ENTRY "8" OF oIni DEFAULT ""
ENDINI
return nil
//----------------------------------------------------------------------------//
function Predefined( nOrder )
if ! Empty( aPredefined[ nOrder ] )
cNumber = PadR( aPredefined[ nOrder ], 20 )
oNumber:Refresh()
HangUp( .f. )
DialNumber( aPredefined[ nOrder ] )
endif
return nil
//-------------------------------------------------------------------------------------------
function BytesAtPort( nComm, nStatus )
local cBuffer := Space( IN_BUFFER ), cBusy, cFech, cHora, cNmro, cTmp
DEFAULT cTerminal := Space( TERM_SIZE )
ReadComm( nComm, @cBuffer )
cBusy := ALLTRIM(cBuffer )
cCadena += If(!EMPTY(cBusy), cBusy, "")
cTerminal := PadR( AllTrim( cTerminal ) + AllTrim( cBuffer ), TERM_SIZE )
oTerminal:Refresh()
If cBusy = "BUSY"
SYSWAIT(2)
HangDown()
EndIf
IF SUBSTR(cBusy,1,5) = "DATE="
cTmp := MEMOTRAN(cBusy)
cTmp := STRTRAN(cTmp,";","")
cTmp := STRTRAN(cTmp," ","")
cFech := SUBSTR(cTmp, AT("DATE=", cTmp), AT("TIME=", cTmp) -1)
cTmp := SUBSTR(cTmp, AT("TIME=", cTmp), 256)
cHora := SUBSTR(cTmp, AT("TIME=", cTmp), AT("NMBR=", cTmp) -1)
cTmp := SUBSTR(cTmp, AT("NMBR=", cTmp), 256)
cNmro := SUBSTR(cTmp, AT("NMBR=", cTmp), 256)
escribetxt( cFech + " " + cHora + " " + cNmro )
EndIf
return nil
//----------------------------------------------------------------------------//
Function EscribeTxt(cTxt, cFile, lModo, cRuta)
local hHandle, cTxTmp, lOk
DEFAULT cFile := "llamadas.txt"
DEFAULT lModo := .f.
DEFAULT cRuta := ""
lOk := .f.
If lModo
cTxTmp := " "
If File(cFile)
hHandle := FOpen(cFile)
FRead(hHandle, @cTxTmp, 64000)
FCLose(hHandle)
cTxt := ALLTRIM(cTxTmp) + CHR(13) + CHR(10) + cTxt
EndIf
EndIf
hHandle := FCREATE(cFile)
FWrite(hHandle,cTxt)
FClose(hHandle)
Return(lOk)