Author Topic: foxpro to whatshap  (Read 176 times)

0 Members and 1 Guest are viewing this topic.

Offline s4ry4n4

  • Newbie
  • *
  • Posts: 36
foxpro to whatshap
« on: November 21, 2020, 09:30:14 PM »
hai guys, selamat malam semuanya nampaknya makin sepi nieh forum kita sudah pada hijrah ya rekan-rekan semua :) terlepas dari hal tersebut beberapa hari ini saya sering jalan-jalan ke foxite dan tidak sengaja menemukan sedikit artikel yang dibuat oleh Tariq Mehmood tentang mengirim dari foxpro ke whatshap, mungkin bisa di coba dan sayapun baru mau mencobanya. Berikut script yang dibuat oleh Tariq Mehmood programmer dari pakistan, menurutnya ngga pakai macam-macam untuk mengirim ke whatshap cukup instal aplikasi whatshap ke komputer dan foxpro bisa di gunakan untuk mengirim ke whatshap, selamat mencoba, salam

sumber :      https://www.foxite.com/archives/0000477843.htm


Before testing any method, you must have Whatsapp installed on your system

https://www.whatsapp.com/download

Please enter whatsapp number on International format like 92......
Do not include + or 00 in starting.

Update 1: How to send Customized School Result Cards as bulk SMS?
Please see Method No. 6


*------------------------------------------------------------
Method:1- How to send simple message
*------------------------------------------------------------

Declare  Integer FindWindow In WIN32API String , String
Declare  Integer SetForegroundWindow In WIN32API Integer
Declare  Integer  ShowWindow  In WIN32API Integer , Integer
Declare Integer ShellExecute In shell32.Dll ;
   INTEGER hndWin, ;
   STRING cAction, ;
   STRING cFileName, ;
   STRING cParams, ;
   STRING cDir, ;
   INTEGER nShowWin

Local lt, lhwnd
cPhone=[923000000000]
ccMessage=[How are you sir?]
cmd='whatsapp://send?phone=&cPhone&text='+ccMessage
=ShellExecute(0, 'open', cmd,'', '', 1)
Wait "" Timeout 3
lt = "Whatsapp"
lhwnd = FindWindow (0, lt)
If lhwnd!= 0
   SetForegroundWindow (lhwnd)
   ShowWindow (lhwnd, 1)
   ox = Createobject ( "Wscript.Shell" )
   ox.sendKeys ( '{ENTER}' )
Else
   Messagebox ( "Whatsapp is not activated!" )
Endif



*------------------------------------------------------------
Method:2- How to send an image file
*------------------------------------------------------------

Do image_to_clip
** Declare Sleep
Declare Sleep In kernel32 Integer

Declare  Integer FindWindow In WIN32API String , String
Declare  Integer SetForegroundWindow In WIN32API Integer
Declare  Integer  ShowWindow  In WIN32API Integer , Integer
Declare Integer ShellExecute In shell32.Dll ;
   INTEGER hndWin, ;
   STRING cAction, ;
   STRING cFileName, ;
   STRING cParams, ;
   STRING cDir, ;
   INTEGER nShowWin

Local lt, lhwnd
cPhone=[923000000000]
cmd='whatsapp://send?phone=&cPhone'
=ShellExecute(0, 'open', cmd,'', '', 1)
Wait "" Timeout 3
lt = "Whatsapp"
lhwnd = FindWindow (0, lt)
If lhwnd!= 0
   SetForegroundWindow (lhwnd)
   ShowWindow (lhwnd, 1)
   ox = Createobject ( "Wscript.Shell" )
   ox.sendKeys ("^{v}")
sleep(2000)
   ox.sendKeys ( '{ENTER}' )

Else
   Messagebox ("Whatsapp is not activated!" )
Endif

Procedure image_to_clip
Declare Integer Sleep In kernel32 Integer
Declare Integer OpenClipboard In User32 Integer
Declare Integer CloseClipboard In User32
Declare Integer EmptyClipboard In User32
Declare Integer SetClipboardData In User32 Integer,Integer
Declare Integer LoadImage In WIN32API Integer,String,Integer,Integer,Integer,Integer
Declare Integer GetClipboardData In User32 Integer
Declare Integer GdipCreateBitmapFromHBITMAP In GDIPlus.Dll Integer, Integer, Integer @
Declare Integer GdipSaveImageToFile In GDIPlus.Dll Integer,String,String @,String @
Declare Long GdipCreateHBITMAPFromBitmap In GDIPlus.Dll Long nativeImage, Long @, Long
Declare Long GdipCreateBitmapFromFile In GDIPlus.Dll String FileName, Long @nBitmap
Declare Long    GdipCreateBitmapFromFile    In GDIPlus.Dll String FileName, Long @nBitmap
Declare Long CopyImage In WIN32API Long hImage, Long, Long, Long , Long

#Define CF_BITMAP 2
#Define CF_DIB 8
#Define IMAGE_BITMAP 0
#Define LR_LOADFROMFILE 16
#Define LR_MONOCHROME 0x00000001

Local xpict
m.xpict=Getpict()
If !Empty(m.xpict)
   m.ext=Proper(Justext(m.xpict))
   If !Inlist(m.ext,"Png","Jpg","Bmp","Gif","Tif")
      Messagebox('Please select only images',0+16,'Whatsapp',3000)
      Return
   Endif
Else
   Messagebox('Image not selected',0+64,'Whatsapp',3000)
   Return
Endif

Local m.oo
m.oo=Newobject("image")
m.oo.Picture=m.xpict
Local lnWidth,lnHeight
lnWidth=m.oo.Width
lnHeight=m.oo.Height

nBitmap=0
hbm=0
GdipCreateBitmapFromFile(Strconv(m.xpict+0h00,5),@nBitmap)
GdipCreateHBITMAPFromBitmap(nBitmap,@hbm,0)
lhBmp = CopyImage(hbm, 0, m.lnWidth, m.lnHeight,0)
If OpenClipboard(0)!= 0
   EmptyClipboard()
   SetClipboardData(CF_BITMAP, lhBmp)
   CloseClipboard()
Endif
Endproc



*------------------------------------------------------------
Method:3- How to send Excel file as image
*------------------------------------------------------------

Suppose I have this Excel File
C:\XLS\daily.xlsx
https://www.foxite.com/uploads/a1d81361-fc21-44fc-af7f-dae4e3ddc4a2.zip

I shall convert this file into image without loosing format first then later send to whatsapp
You must have following 3 file in same folder
gpimage.FXP,gpimage.h,gpimage.prg
https://www.foxite.com/uploads/72917469-c72e-489e-95f6-2b9b263a5b0b.zip
The following codes will generate a bmp file like this



Do excel2image

Function excel2image
xflname="" && Get image file name
ahour=Padl(Alltrim(Str(Hour(Datetime()))),2,'0')
amin=Padl(Alltrim(Str(Minute(Datetime()))),2,'0')
xflname=Alltrim("Tailor_")+Alltrim(Dtos(Date()))+"_"+ahour+amin

lcXLS =[C:\xls\daily.xlsx]
If Empty(lcXLS)
   Messagebox('Excel file not found',0+16,'System')
   Return
Endif

Local oForm
oForm = Createobject("Form")

With oForm
   .Height = 550
   .Width = 360
   .AutoCenter=.T.
   .Caption=m.xflname
   .MinButton=.F.
   .MaxButton=.F.
   .AlwaysOnTop=.T.
   .Newobject("ExcelObject","oleExcelObject")
   With .ExcelObject
      .Left = 0
      .Top = 0
      .Width = .Parent.Width - 10
      .Height = .Parent.Height - 10
      .Visible = .T.
   Endwith
   .Newobject("Timer1","oTimer")
Endwith

oForm.Show(1)
Define Class oleExcelObject As OleControl
   OleClass ="Excel.Sheet"  && Server name
   OLETypeAllowed = 0      && Linked
   DocumentFile = lcXLS && This file should exist
Enddefine

Define Class oTimer As Timer
   Interval=8000
   Procedure Timer
   This.Enabled = .F.
   Do ScreenShot With This.Parent
   This.Enabled = .T.
Enddefine

Procedure ScreenShot
Lparameters oForm

#INCLUDE gpImage.h

If Not "gpImage" $ Set("Procedure")
   Set Procedure To gpImage Additive
Endif

GDIP = Createobject("gpInit")
img = Createobject("gpImage")
img.Capture(oForm.HWnd)
Local lnTitleHeight, lnLeftBorder, lnTopBorder
lnTitleHeight = Sysmetric(9)
lnLeftBorder = Sysmetric(3)
lnTopBorder = Sysmetric(4)
img.Crop(lnLeftBorder, lnTitleHeight + lnTopBorder, ;
   img.ImageWidth - (lnLeftBorder * 2), ;
   img.ImageHeight - (lnTitleHeight + (lnTopBorder * 2)))
img.SaveasBMP('C:\Xls'+'\'+m.xflname)
img = Null
oForm.Release

Do image2Clip
Do send2whatsapp

Endfunc

Function image2Clip
Declare Integer Sleep In kernel32 Integer
Declare Integer OpenClipboard In User32 Integer
Declare Integer CloseClipboard In User32
Declare Integer EmptyClipboard In User32
Declare Integer SetClipboardData In User32 Integer,Integer
Declare Integer LoadImage In WIN32API Integer,String,Integer,Integer,Integer,Integer
Declare Integer GetClipboardData In User32 Integer
Declare Integer GdipCreateBitmapFromHBITMAP In GDIPlus.Dll Integer, Integer, Integer @
Declare Integer GdipSaveImageToFile In GDIPlus.Dll Integer,String,String @,String @
Declare Long GdipCreateHBITMAPFromBitmap In GDIPlus.Dll Long nativeImage, Long @, Long
Declare Long GdipCreateBitmapFromFile In GDIPlus.Dll String FileName, Long @nBitmap
Declare Long  GdipCreateBitmapFromFile    In GDIPlus.Dll String FileName, Long @nBitmap
Declare Long CopyImage In WIN32API Long hImage, Long, Long, Long , Long

#Define CF_BITMAP 2
#Define CF_DIB 8
#Define IMAGE_BITMAP 0
#Define LR_LOADFROMFILE 16
#Define LR_MONOCHROME 0x00000001 && Creates a new monochrome image. if used
Local m.xpict

m.xpict='C:\XLS'+'\'+m.xflname+'.bmp'
Messagebox(m.xpict)

If !Empty(m.xpict)
   m.ext=Proper(Justext(m.xpict))
   If !Inlist(m.ext,"Png","Jpg","Bmp","Gif","Tif")
      Messagebox('Please select only images')
      Return
   Endif
Else
   Messagebox('Image not selected')
   Return
Endif

Local m.oo
m.oo=Newobject("image")
m.oo.Picture=m.xpict
Local lnWidth,lnHeight
lnWidth=m.oo.Width
lnHeight=m.oo.Height

*Save the bitmap file to the clipboard
nBitmap=0
hbm=0
GdipCreateBitmapFromFile(Strconv(m.xpict+0h00,5),@nBitmap)
GdipCreateHBITMAPFromBitmap(nBitmap,@hbm,0)
lhBmp = CopyImage(hbm, 0, m.lnWidth, m.lnHeight,0)
If OpenClipboard(0)!= 0
   EmptyClipboard()
   SetClipboardData(CF_BITMAP, lhBmp)
   CloseClipboard()
Endif
Endfunc

Function send2whatsapp
* Finally send this newly created image to whatsapp
Declare  Integer FindWindow In WIN32API String , String
Declare  Integer SetForegroundWindow In WIN32API Integer
Declare  Integer  ShowWindow  In WIN32API Integer , Integer
Declare Integer ShellExecute In shell32.Dll ;
   INTEGER hndWin, ;
   STRING cAction, ;
   STRING cFileName, ;
   STRING cParams, ;
   STRING cDir, ;
   INTEGER nShowWin

Local lt, lhwnd
cPhone=[923000000000]
cmd='whatsapp://send?phone=&cPhone'
=ShellExecute(0, 'open', cmd,'', '', 1)
Wait "" Timeout 3
lt = "Whatsapp"
lhwnd = FindWindow (0, lt)
If lhwnd!= 0
   SetForegroundWindow (lhwnd)
   ShowWindow (lhwnd, 1)
   ox = Createobject ( "Wscript.Shell" )
   ox.SendKeys ("^{v}")
   ox.SendKeys ( '{ENTER}' )
Else
   Messagebox ( "Whatsapp is not activated!" )
Endif
Endfunc



*------------------------------------------------------------
Method:4- How to send Bulk messages
*------------------------------------------------------------
We shall create some data first

Create Cursor clients(mobile c(12))
Insert Into clients Values('923000000000')
Insert Into clients Values('923000000000')
Insert Into clients Values('923000000000')
Go Top
Scan
   Scatter Memv
   cPhone=ALLTRIM(m.mobile)
   cMessage=Alltrim('This is sales promotion message')

   Declare  Integer FindWindow In WIN32API String , String
   Declare  Integer SetForegroundWindow In WIN32API Integer
   Declare  Integer  ShowWindow  In WIN32API Integer , Integer
   Declare Integer ShellExecute In shell32.Dll ;
      INTEGER hndWin, ;
      STRING cAction, ;
      STRING cFileName, ;
      STRING cParams, ;
      STRING cDir, ;
      INTEGER nShowWin
   Local lt, lhwnd
   cmd='whatsapp://send?phone=&cPhone&text=' + cMessage
   =ShellExecute(0, 'open', cmd,'', '', 1)
   Wait "" Timeout 8 && 8 seconds internal in every message
   lt = "Whatsapp"
   lhwnd = FindWindow (0, lt)
   If lhwnd!= 0
      SetForegroundWindow (lhwnd)
      ShowWindow (lhwnd, 1)
      ox = Createobject ( "Wscript.Shell" )
      ox.sendKeys ( '{ENTER}' )
   Else
      Messagebox ( "Whatsapp is not activated!" )
   Endif
Endscan



*------------------------------------------------------------
Method:5- How to send contents of text file
*------------------------------------------------------------

cFile=Getfile('txt')
_Cliptext=Filetostr(cFile)

Declare  Integer FindWindow In WIN32API String , String
Declare  Integer SetForegroundWindow In WIN32API Integer
Declare  Integer  ShowWindow  In WIN32API Integer , Integer
Declare Integer ShellExecute In shell32.Dll ;
   INTEGER hndWin, ;
   STRING cAction, ;
   STRING cFileName, ;
   STRING cParams, ;
   STRING cDir, ;
   INTEGER nShowWin

Local lt, lhwnd
cPhone=[923000000000]
cmd='whatsapp://send?phone=&cPhone'
=ShellExecute(0, 'open', cmd,'', '', 1)
Wait "" Timeout 3
lt = "Whatsapp"
lhwnd = FindWindow (0, lt)
If lhwnd!= 0
   SetForegroundWindow (lhwnd)
   ShowWindow (lhwnd, 1)
   ox = Createobject ( "Wscript.Shell" )
   ox.sendKeys ("^{v}")
   ox.sendKeys ( '{ENTER}' )
Else
   Messagebox ( "Whatsapp is not activated!" )
Endif


*------------------------------------------------------------
Method:6- How to send Result Cards
*------------------------------------------------------------
Suppose you are a principal of a school and want to send customized result card to parents.


Create Cursor result(rollno N(3),student c(15),Chem N(3),phy N(3),bio N(3),;
   eng N(3),math N(3),t_marks N(3),o_marks N(3),rem c(10),mobile c(13))
Insert Into result Values(1,'Ahmad Ali',78,25,33,85,50,500,271,'Pass','923000000000')
Insert Into result Values(1,'Zahid Mahmood',36,74,66,55,80,500,311,'Pass','92345000000')


Go Top
Scan
   Scatter Memv
   cPhone=Alltrim(m.mobile)

   cMessage='*Result Card*';
      + '%0A'+'%0A';
      + m.student;
      + '%0A'+'%0A'+'Chem='+transform(m.Chem);
      + '%0A'+'Bio='+transform(m.bio);
      + '%0A'+'Phy='+transform(m.phy);
      + '%0A'+'Eng='+transform(m.eng);
      + '%0A'+'Math='+transform(m.math);
      + '%0A'+'%0A'+'Total='+transform(m.t_marks);
      + '%0A'+'Obtained='+Alltrim(Str(m.o_marks));
      +  '%0A' +'%0A'+'Remarks='+'*'+Alltrim(m.rem)+'*';
      + '%0A' ;
      + Replicate('-',20);
      + '%0A'+'Principal:';
      + '%0A'+'Allied Public School'

   Declare Sleep In kernel32 Integer
   Declare  Integer FindWindow In WIN32API String , String
   Declare  Integer SetForegroundWindow In WIN32API Integer
   Declare  Integer  ShowWindow  In WIN32API Integer , Integer
   Declare Integer ShellExecute In shell32.Dll ;
      INTEGER hndWin, ;
      STRING cAction, ;
      STRING cFileName, ;
      STRING cParams, ;
      STRING cDir, ;
      INTEGER nShowWin
   Local lt, lhwnd
   cmd='whatsapp://send?phone=&cPhone&text=' + cMessage
   =ShellExecute(0, 'open', cmd,'', '', 1)
   Sleep(2000)
   lt = "Whatsapp"
   lhwnd = FindWindow (0, lt)
   If lhwnd!= 0
      SetForegroundWindow (lhwnd)
      ShowWindow (lhwnd, 1)
      ox = Createobject ( "Wscript.Shell" )
      ox.sendKeys ( '{ENTER}' )
   Else
      Messagebox ("Whatsapp is not activated!" )
   Endif
Endscan



 
« Last Edit: November 21, 2020, 09:36:39 PM by s4ry4n4 »

Offline AmirS

  • Junior Member
  • *
  • Posts: 117
Re: foxpro to whatshap
« Reply #1 on: November 23, 2020, 09:13:16 PM »
Before testing any method, you must have Whatsapp installed on your system
https://www.whatsapp.com/download

Saya mau download kok gak bisa yah mas...kalo mas udah bisa info yah ini WA saya 081355949499 ada dah biaya untuk explorasinya tapi gak banyak
Tks



Offline agooze

  • Junior Member
  • *
  • Posts: 135
Re: foxpro to whatshap
« Reply #2 on: November 25, 2020, 08:44:58 PM »
ada yang sudah punya logicnya jika yang di kirim file pdf ke whatapp ?