Code archives/Miscellaneous/Print an image

This code has been declared by its author to be Public Domain code.

Download source code

Print an image by Kuron
(Posted 21 years ago)
If you just need to print a simple image that will fit on a normal sized piece of paper, you do not need to use a DLL or API calls.

MS Paint allows command line options. You can run MS Paint from the command line with the Print switch and it will print the image directly to the default printer without opening MS Paint.

You need to grab the directory for MS Paint (system/system32, etc) and grab the directory that the image you want to print is in and the file name, then add the "/p" switch.
ExecFile ("c:\windows\system32\mspaint.exe c:\tik.bmp /p")

Comments

Pedro
(Posted 21 years ago)
shorter !
ExecFile "c:\tik.bmp"

Automatically windows find the program linked to bmp extansion and open it => it is like a double click on the file.

Works with all the files ...

Mystik
(Posted 21 years ago)
shorter !

ExecFile "c:\tik.bmp"



Automatically windows find the program linked to bmp extansion and open it => it is like a double click on the file.

Works with all the files ...



The first example prints the picture by opening mspaint in the background. Your shorter one just loads the picture into whatever program is currently associated with .bmp


Steve.

cb43569
(Posted 21 years ago)
Clever. I'd never have suspected it.

But, Pedro, yeah, that only opens the file, it doesn't actually print it.

xlsior
(Posted 21 years ago)
Major problem: Many, MANY systems don't store mspaint.exe in the c:\windows\system32 folder.

Probably about a 3rd of the windows installs out there are in c:\winnt\ , for starters.
In addition windows doesn't even need to be installed on C:\, it can be any driver letter...

You can do some damage control, and increase the chances of it being correct by calling it like this:

ExecFile (GetEnv$("windir")+"\system32\mspaint.exe c:\tik.bmp /p")


You really ought to make sure that the mspaint.exe program even exists though, because it won't always be present either.

OJay
(Posted 21 years ago)
or even simpler:
ExecFile ("mspaint.exe c:\tik.bmp /p")

;)

Kuron
(Posted 21 years ago)
Major problem: Many, MANY systems don't store mspaint.exe in the c:\windows\system32 folder.
Duh, thats why I said:

You need to grab the directory for MS Paint (system/system32, etc) and grab the directory that the image you want to print is in and the file name, then add the "/p" switch.


Because MS Paint is not always in the same location and is not always installed. Use error checking when you grab the location for MS Paint. If MS Paint doesn't exist, then don't print the image ;c)

Bobysait
(Posted 20 years ago)
maybe a simple function like


Function MSPaint_Print(file$)
	App_Dir$=SystemProperty("systemdir")+"mspaint.exe"
	If FileType(app_dir)=1
		ExecFile( App_Dir+file+"/p")
		Return True
	Else
		Return False
	EndIf
End

could solve the problem.

Code Archives Forum