UnderwareDESIGN

PlayBASIC => Resources => Source Codes => Topic started by: kevin on February 12, 2011, 06:33:28 PM

Title: Using ShellExecute To Print Images & Open Web Pages
Post by: kevin on February 12, 2011, 06:33:28 PM
 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.  


[pbcode]

   #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



[/pbcode]



Title: Re: Using ShellExecute To Print Images & Open Web Pages
Post by: kevin on April 27, 2014, 11:18:54 AM

Using ShellExecute To Open Web Pages


[pbcode]

  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

[/pbcode]
Title: Re: Using ShellExecute To Print Images & Open Web Pages
Post by: kevin on November 18, 2020, 10:36:17 PM
   open Text File with default text editor on windows


[pbcode]

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


[/pbcode]

  -  NotePad.exe