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 Kuron2005
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

Pedro2005
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 ...


Mystik2005
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.


zcbeaton2006
Clever. I'd never have suspected it.

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


xlsior2006
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.


OJay2006
or even simpler:
ExecFile ("mspaint.exe c:\tik.bmp /p")

;)


Kuron2006
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)


Bobysait2006
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.


ThePict2010
Would the same thing work with Notepad for printing text or ASCII files?


ShadowTurtle2010
you can save the text as bitmap and run the MSPaint_Print function :)


Serpent2010
zombie thread :P
I'm not sure if something like notepad would accept the '/p' switch in its command-line arguments and actually print a text file...


_PJ_2010
Notepad doesn't print here on XP when I use the /p switch.


Code Archives Forum