How to print an image without a DLL/API

BlitzPlus Forums/BlitzPlus Programming/How to print an image without a DLL/API

Blue Steel(Posted 2003) [#1]
Kanati (sp?) made an awesome DLL for printing, (really useful for my text stuff).

But I have seen a newbie post or two about printing images and some folks may not be aware how to do this without using a DLL or API calls.

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.

I am doing a program where the user needs to be able to print the image they have made.

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.

For example:

ExecFile ("c:\windows\system32\mspaint.exe c:\tik.bmp /p")


(I have tested this on 95,98/98se/NT/XP and it works fine)

I figured this may be helpful to a few folks.


Kanati(Posted 2003) [#2]
Good tip Brice. I wasn't aware of this. :)

Kanati


Beaker(Posted 2003) [#3]
Nice idea. Only problem is that I don't have MSPAINT installed.


Blue Steel(Posted 2003) [#4]
>Only problem is that I don't have MSPAINT installed.<

probably good to error trap and make sure MS Paint is installed, in case you do encounter that one in a million who have uninstalled it.


FlameDuck(Posted 2003) [#5]
(I have tested this on 95,98/98se/NT/XP and it works fine)
No it doesn't. The path is winnt on NT/XP machines. :o>


Blue Steel(Posted 2003) [#6]
No it doesn't. The path is winnt on NT/XP machines.


I grabbed the appropiate path for each OS. :c) BTW, My store bought XP disc always default installs to c:\windows


EOF(Posted 2003) [#7]
Does ExecFile "MSPaint.exe" work?
It launches on my system without any path info.
Also, what about these:

ExecFile "calc.exe"
ExecFile "notepad.exe"
ExecFile "appwiz.cpl" ; Add/Remove programs
ExecFile "C:\Windows\" ; open the folder


I use these on a QuickLaunch application written in Blitz+
It's handy for running common programs/tasks and opening regular folders.


Beaker(Posted 2003) [#8]
Syntax - once I put your code through a spell-checker (:D) they all worked apart from the "appwiz.cpl" one.

(Not forgetting MSPaint didn't work cos it's not installed here.)


EOF(Posted 2003) [#9]
once I put your code through a spell-checker (:D)
Wot spilling misttackes? ;-)

they all worked apart from the "appwiz.cpl" one.
Try these:
ExecFile Chr$(34)+"appwiz.cpl"+Chr$(34)        ; add/remove programs
ExecFile Chr$(34)+"timedate.cpl"+Chr$(34)      ; time/date
ExecFile Chr$(34)+"sysdm.cpl"+Chr$(34)         ; system properties
ExecFile Chr$(34)+"main.cpl"+Chr$(34)+" @1"    ; keyboard
ExecFile Chr$(34)+"joy.cpl"+Chr$(34)           ; joystick



Oh, and use ExecFile as a function to determine whether the application launched ok ...
Returns TRUE (1) if launched else 0
If ExecFile("MSPaint.exe") Print "launched!!!"



Blue Steel(Posted 2003) [#10]
Does ExecFile "MSPaint.exe" work?
It launches on my system without any path info.


It "should" always work, but to be safe, I always grab the system path anyway. An ounce of prevention is worth a pound of cure.

I have been using this method for printing images for many years and have yet to run into any problems.


Tricky(Posted 2003) [#11]
You could do some error trapping like this:

If FileExists("c:\windows\system32\mspaint.exe c:\tik.bmp /p") Then
   ExecFile ("c:\windows\system32\mspaint.exe c:\tik.bmp /p")
   Else
   Print "Error! Need MS-Paint to print, which appears not to be installed on your system"
   End If


That's the kind of error trapping I would use... :)


Blue Steel(Posted 2003) [#12]
That's the kind of error trapping I would use... :)
You are assuming that windows will be on the "C" drive. Much better to take the extra step and be safe and grab the system directory than hardcode a directory,

For example, on my DEV system, Windows is on the "K" drive.