Using ShellExecute To Print Images & Open Web Pages

Started by kevin, February 12, 2011, 06:33:28 PM

Previous topic - Next topic

kevin

 Using ShellExecute To Print Image & Documents

 The shellexecute function is part of the windows API,  it's normally used in PB programs to launch a web site or something,  but you can also use it to print documents.   You have no real control over the printer mind you, but it's an easy out.  


PlayBASIC Code: [Select]
   #include "savebitmap"
Constant SW_SHOWNORMAL = 1

LinkDll "Shell32.dll"
ShellExecute(hwnd, lpOperation$, lpFile$, lpParameters$, lpDirectory$, nShowCmd) alias "ShellExecuteA" as Integer
EndLinkDLL



; Make an image
Image=NewImage(256,256,2)

rendertoimage Image
circle 100,100,100,true
rendertoscreen




; Save this image to C drive
filename$="C:\TestPIcture.bmp"
savebitmap(Filename$,IMage)

; filename$="C:\Music_DreamTheater_2011_Feb_12th.png"

path$=getfoldername$(filename$)


; reload image and display it
Image2=LoadNewimage(Filename$)
DrawImage Image2,200,200,false


; Call shell print to have windows print this file
ShellExecute(0 , "print", filename$, "",path$, SW_SHOWNORMAL)


print "done"

Sync
waitkey









kevin


Using ShellExecute To Open Web Pages


PlayBASIC Code: [Select]
  Constant SW_SHOWNORMAL = 1

LinkDll "Shell32.dll"
ShellExecute(hwnd, lpOperation$, lpFile$, lpParameters$, lpDirectory$, nShowCmd) alias "ShellExecuteA" as Integer
EndLinkDLL



FUnction OpenWebSite(URL$)

// screen url a little
if lower$(left$(URL$,7))<> "http://"
url$="http://"+URL$
endif

hwnd=GetScreenHandle()
if hwnd
ShellExecute hwnd, "open", URL$, "", "", SW_SHOWNORMAL
endif

EndFunction



OpenWebSite("playbasic.com")

print "Done"

Sync
waitkey



kevin

   open Text File with default text editor on windows


PlayBASIC Code: [Select]
 Constant SW_SHOWNORMAL = 1

LinkDll "Shell32.dll"
ShellExecute(hwnd, lpOperation$, lpFile$, lpParameters$, lpDirectory$, nShowCmd) alias "ShellExecuteA" as Integer
EndLinkDLL



Function OpenTextFile(FILENAME$)

if Fileexist(FILENAME$)
hwnd=GetScreenHandle()
if hwnd
ShellExecute hwnd, "EDIT", FILENAME$, "", "", SW_SHOWNORMAL
wait 1
endif
else
#print "openTextFile: File doesn't exist:"+Filename$
endif

EndFunction




OpenTextFile("g:Calculator Performance Index(1).txt")

print "Done"

Sync
waitkey





  -  NotePad.exe