Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Whatsapp attachment 1

Status
Not open for further replies.

TariqMehmod

Programmer
Mar 4, 2004
100
PK
Sir I am using these code to send text message on whatsapp.

Code:
 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=[9203000000000]
cMessage='How are you sir?'

cmd='whatsapp://send?phone=&cPhone&text=&cMessage'


=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 no activated!" )
Endif]

There is no issue.

But now I want to send PDF document or image on whatsapp

to do this, I visited these links

Link
Link

But could not found how to modify this line of code
Code:
cmd='whatsapp://send?phone=&cPhone&text=&cMessage'

I mean what to add in api string to send document?

Update:
While using codes from this link

I modified my string like this
Code:
mediaName="conversational-commerce"
mediaUri="[URL unfurl="true"]https://www.cm.com/cdn/web/nl-nl/blog/conversational-commerce.jpg"[/URL]
mimeType= "image/jpg"
cmd='whatsapp://send?phone=&cPhone&media=&mediaName&Url=&mediaUri&type=mimeType'

but it still not work


Please help
 
I think your mimeType is not being expanded, to prevent this kind of confusion I would code it like this:

Code:
cmd='whatsapp://send?phone='+cPhone+'&media='+mediaName+'&Url='+mediaUri+'&type='+mimeType



Regards

Griff
Keep [Smile]ing

There are 10 kinds of people in the world, those who understand binary and those who don't.

I'm trying to cut down on the use of shrieks (exclamation marks), I'm told they are !good for you.
 
Thanks sir for reply but it still does not work.

Sir I found following 2 more links which are sending images to whatsapp with PHP

Link
Link
May be someone translate codes to vfp.

Here is simple coding

Link



Regards
 
After a very long study and experiments, I have finalized these codes to send text message + image file to WHATSAPP.

Code work fine, no issue.
Please give a try and send me feedback.

You will have to install whatsapp on you system first.

Code:
 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=Getpict()
If !Empty(m.xpict)
	m.ext=Justext(m.xpict)

	If !Inlist(m.ext,"PNG","JPG","BMP","GIF","TIF")
		Messagebox('Please select only images')
	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
*Messagebox("Width="+Trans(m.lnWidth)+" px Height="+Trans(m.lnHeight)+" px .....can resize image in code !",0+32+4096,'',2000)

*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) &&resize if
If OpenClipboard(0)!= 0
	EmptyClipboard()
	SetClipboardData(CF_BITMAP, lhBmp)
	CloseClipboard()
Endif

*----------------------------------------------------------

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] & International format
cMessage='How are you sir?'

comando='whatsapp://send?phone=&cPhone&text=&cMessage'

=ShellExecute(0, 'open', comando,'', '', 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}' )
	ox.SendKeys ( '{ENTER}' )
Else
	Messagebox ("Whatsapp not found on your system!" )
Endif
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top