FBWinPrint 0.10

User contributed sources that have become inactive, deprecated, or generally unusable. But ... we don't really want to throw them away either.
vdecampo
Posts: 2992
Joined: Aug 07, 2007 23:20
Location: Maryland, USA
Contact:

FBWinPrint 0.10

Post by vdecampo »

I am almost ready to release the first BETA of my FreeBASIC Windows Printing Library. It allows the creation of a PrinterObject which helps in dealing with printing to the printer. It also has some ancillary features like quick access to common dialogs like open/save/printer/pagesetup/fonts/colors.

Here is the documentation thus far...

Code: Select all

'************************************************************************
' FBWinPrint v 0.12 - Windows Printing Library for FreeBASIC
'                           by Vincent DeCampo			 
'													 
' Rev 0.12 (09/19/2007)
'
' - Fixed using StretchBlt with printer DC
' - Added DrawBox, PrintWindow
' - Fixed PrintBMP Crash
'
' Rev 0.11 (09/17/2007)
'
' - Corrected scaling of font to device context
'
' Rev 0.10 (09/15/2007)
' PrintObj (Printer Object)		
'	
'	-Properties	
'		.PrinterDC		(the device context of the currently selected printer.)
'						 	(This updates when the printer changes via Dialog method)
'
'		.PrinterName 	(The Name of the currently selected printer.)
'						 	(This updates when the printer changes via Dialog method)
'
'		.PageWidth		(The width of the page in device units
'							(This updates when the printer changes via Dialog method)
'
'		.PageHeight		(The width of the page in device units
'							(This updates when the printer changes via Dialog method)
'	
'	-Methods
'		OpenFile() As String	
'			(Opens an OpenFile window and returns Selected Filename.)
'			(Returns an empty ("") string when CANCEL is selected) 
'
'		SaveFile() As String 
'			(Opens a SaveFile window and returns Selected Filename.)
'			(Returns an empty ("") string when CANCEL is selected)
'
'		ColorPicker() As Integer
'			(Opens a Color Picker window and returns Selected RGB value.)
'			(Returns -1 when CANCEL is selected)
'
'		Font(ByRef FontName As String, ByRef FontSize As Integer) As String
'			(Opens a Font window and returns Selected Font Name.)
'			(Returns an empty ("") string when CANCEL is selected)
'
'		Dialog() As String
'			(Opens a Print Dialog window and returns selected Printer.)
'			(This method will update the .PrinterName And .PrinterDC properties)
'			(Returns an empty ("") string when CANCEL is selected)
'
'		PageSetup() As Integer
'			(Opens a Page Setup window.)
'			(Returns -1 when CANCEL is selected)
'
'		DocStart(DOCTitle As String = "Untitled")
'			(Begins a print job)
'
'		PageStart()
'			(Begins a new page of a print job)
'
'		PageEnd()
'			(Ends current page of a print job)
'
'		DocEnd()
'			(Sends print job to printer)
'
'		DocAbort()
'			(Aborts current print job)
'
'		BltImageDC (srcDC As HDC, srcRECT As RECT Ptr, dstRECT As RECT Ptr)
'			(Draws an image to the printer from an existing Bitmap DC)
'        (dstRECT.Right/.Bottom contain destination width and height)
'
'		PrintBMP	(Filename As String, dstRECT As RECT)
'			(Draws an image to the printer from an existing Bitmap Image File)
'        (dstRECT.Right/.Bottom contain destination width and height)
'
'	   PPrint (X As Integer, Y As Integer, Text As String)
'        (Prints Text to the printer at the specified x,y using the font
'        (specified by the SetFont method.)
' 
'	   SetFont(FontName As String, FontSize As Integer, FontColor As Integer)
'        (Sets the Font, Size and Color to use with the PPrint method)
'
'		DrawBox (X1 As Integer, Y1 As Integer, X2 As Integer, Y2 As Integer, LineColor As Integer)
'        (Draws a colored box from X1,Y1 (upper left) to X2,Y2 (Lower Right)
'        (Box is white filled and should be drawn first before adding internal text)
'
'		PrintWindow (hWnd As HANDLE, X As Integer, Y As Integer, dX As Integer, dY As Integer)
'			(Draws an copy of a window to the printer from an existing hWnd)
'        (dX/dY contain destination width and height)
'
'************************************************************************
-Vince
Last edited by vdecampo on Sep 19, 2007 18:35, edited 3 times in total.
vdecampo
Posts: 2992
Joined: Aug 07, 2007 23:20
Location: Maryland, USA
Contact:

Post by vdecampo »

Ok, the current version of the printing library is available here...

FBWinPrint

Here is a sample of its use...

Code: Select all

#Include "windows.bi"
#Include "FBWinPrint.bi"

Dim PO As PrinterObj
Dim FontName As String
Dim FontSize As Integer

	With PO
	
		Print .Dialog
		Print .PrinterDC,.PrinterName,.PageWidth,.PageHeight
	
		Print .Font(FontName, FontSize)	
	
		.DocStart
		.PageStart
		.SetFont (FontName, FontSize, 0)
		.PPrint (10,10,"Test")
		.PageEnd
		.DocEnd
	
	End With

	Print "Print Job Sent To Printer."
	Print "Press any key to exit."
		
Sleep
End

Cheers!
-Vince
Last edited by vdecampo on May 12, 2009 20:04, edited 2 times in total.
Antoni
Posts: 1393
Joined: May 27, 2005 15:40
Location: Barcelona, Spain

Post by Antoni »

Vince:
I have tried the example that comes in the zip in two printers and both print a white page.
vdecampo
Posts: 2992
Joined: Aug 07, 2007 23:20
Location: Maryland, USA
Contact:

Post by vdecampo »

Hmmm...I was having an issue with scaling. Try changing the font size to 120 instead of 12 and see of that works...

-Vince
Antoni
Posts: 1393
Joined: May 27, 2005 15:40
Location: Barcelona, Spain

Post by Antoni »

Vince:
Ok, this the problem. If I .SetFont with a size of 72, the text is barely readable in the top left corner of the page.
vdecampo
Posts: 2992
Joined: Aug 07, 2007 23:20
Location: Maryland, USA
Contact:

FBWinPrint 0.11

Post by vdecampo »

Ok, I should have the scaling issue resolved. Download and try it again...

Cheers!
-Vince
Antoni
Posts: 1393
Joined: May 27, 2005 15:40
Location: Barcelona, Spain

Post by Antoni »

Ok, text printing works now.

I have another problem, I tried .PrintBmp and I get a crash..
vdecampo
Posts: 2992
Joined: Aug 07, 2007 23:20
Location: Maryland, USA
Contact:

Post by vdecampo »

I have found an issue with using StretchBlt and the printer DC. I will find a resolution and fix the PrintBMP function. Could you post a snippet of your call to the function?

-Vince
notthecheatr
Posts: 1759
Joined: May 23, 2007 21:52
Location: Cut Bank, MT
Contact:

Post by notthecheatr »

Could you put the 'documentation' inside [ quote] [/ quote] tags?
vdecampo
Posts: 2992
Joined: Aug 07, 2007 23:20
Location: Maryland, USA
Contact:

Post by vdecampo »

Scroll button or down arrow broken? ;-)

Fixed!

-Vince
Antoni
Posts: 1393
Joined: May 27, 2005 15:40
Location: Barcelona, Spain

Post by Antoni »

Code: Select all

#Include "windows.bi"
#Include "FBWinPrint.bi"

Dim PO As PrinterObj
Dim FontName As String
Dim FontSize As Integer
Dim r As rect
r.top=10
r.left=10
r.bottom=400
r.right=600

	With PO
	
		Print .Dialog
		Print .PrinterDC,.PrinterName,.PageWidth,.PageHeight
	
		'Print .Font(FontName, FontSize)	
	
		.DocStart
		.PageStart
		.printbmp("setup.bmp",r)
		'.SetFont (FontName, FontSize, 0)
		'.PPrint (10,10,"Printer Error")
		.PageEnd
		.DocEnd
	
	End With

	Print "Print Job Sent To Printer."
	Print "Press any key to exit."
		
Sleep
End
vdecampo
Posts: 2992
Joined: Aug 07, 2007 23:20
Location: Maryland, USA
Contact:

FBWinPrint .012

Post by vdecampo »

I fixed stretching of images and some potential crash situations plus added some other functions...
'************************************************************************
' FBWinPrint v 0.12 - Windows Printing Library for FreeBASIC
' by Vincent DeCampo
'
' Rev 0.12 (09/19/2007)
'
' - Fixed using StretchBlt with printer DC
' - Added DrawBox, PrintWindow
' - Fixed PrintBMP Crash
The new sample program uses a complete pathname to the BMP for the PrintBMP function. This seems to be necessary although I'm not sure why. If the file is in the EXE directory, it should find it, but it doesn't.

More to come... :-)

-Vince
jbraden
Posts: 9
Joined: Feb 06, 2007 4:05

Post by jbraden »

Vince,

I am a newbie on FB. I downloaded the zip file and put the two coded files into the same directory. When I attempt to run it, I get a compile failure:

Command executed:
"C:\FreeBasic\fbc.exe" "C:\FreeBasic\NSCHOOL\FBWinPrint.bas" -lang qb

Compiler output:
C:/FreeBasic/inc/win/windef.bi(61) error 3: Expected End-of-Line, found 'ptr'
type PWINBOOL as integer ptr
^
C:/FreeBasic/inc/win/windef.bi(62) error 3: Expected End-of-Line, found 'ptr'
type LPWINBOOL as integer ptr
^
C:/FreeBasic/inc/win/windef.bi(64) error 3: Expected End-of-Line, found 'ptr'
type PBOOL as BOOL ptr
^
C:/FreeBasic/inc/win/windef.bi(65) error 3: Expected End-of-Line, found 'ptr'
type LPBOOL as BOOL ptr
^
C:/FreeBasic/inc/win/windef.bi(68) error 3: Expected End-of-Line, found 'ptr'
type PFLOAT as FLOAT ptr
^
C:/FreeBasic/inc/win/windef.bi(69) error 3: Expected End-of-Line, found 'ptr'
type PBYTE as UBYTE ptr
^
C:/FreeBasic/inc/win/windef.bi(70) error 3: Expected End-of-Line, found 'ptr'
type LPBYTE as UBYTE ptr
^
C:/FreeBasic/inc/win/windef.bi(71) error 3: Expected End-of-Line, found 'ptr'
type PINT as integer ptr
^
C:/FreeBasic/inc/win/windef.bi(72) error 3: Expected End-of-Line, found 'ptr'
type LPINT as integer ptr
^
C:/FreeBasic/inc/win/windef.bi(73) error 66: Incomplete type, before 'ptr'
type PWORD as WORD ptr
^
C:/FreeBasic/inc/win/windef.bi(73) error 123: Too many errors, exiting

Results:
Compilation failed

System:
FBIde: 0.4.6
fbc: FreeBASIC Compiler - Version 0.18.3 (12-28-2007) for win32 (target:win32)
OS: Windows XP (build 2600, Service Pack 2)


Any idea why it is doing this?

John
maddogg6
Posts: 824
Joined: Dec 07, 2005 22:58
Contact:

Post by maddogg6 »

jbraden wrote:Vince,

I am a newbie on FB. I downloaded the zip file and put the two coded files into the same directory. When I attempt to run it, I get a compile failure:

Command executed:
"C:\FreeBasic\fbc.exe" "C:\FreeBasic\NSCHOOL\FBWinPrint.bas" -lang qb

...

Any idea why it is doing this?

John
I think you need to remove the '-lang qb' in FBIde settings
vdecampo
Posts: 2992
Joined: Aug 07, 2007 23:20
Location: Maryland, USA
Contact:

Post by vdecampo »

@maddogg6

Yes that is correct. This lib will only work in -lang FB.

-Vince
Post Reply