freebasic.net Forum Index
FreeBASIC's Official Forums
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister   ProfileProfile   Log inLog in

FBWinPrint 0.10
Goto page 1, 2, 3, 4  Next
 
Post new topic   Reply to topic    freebasic.net Forum Index -> Projects
View previous topic :: View next topic  
Author Message
vdecampo
Hero
PostPosted: Sep 15, 2007 22:10    Post subject: FBWinPrint 0.10 Reply with quote

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:

'************************************************************************
' 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
 
Back to top
View user's profile Visit poster's website
vdecampo
Hero
PostPosted: Sep 16, 2007 2:24    Post subject: Reply with quote

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

FBWinPrint

Here is a sample of its use...
Code:

#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
 
Back to top
View user's profile Visit poster's website
Antoni
Master
PostPosted: Sep 17, 2007 7:44    Post subject: Reply with quote

Vince:
I have tried the example that comes in the zip in two printers and both print a white page.
 
Back to top
View user's profile Visit poster's website
vdecampo
Hero
PostPosted: Sep 17, 2007 12:21    Post subject: Reply with quote

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

-Vince
 
Back to top
View user's profile Visit poster's website
Antoni
Master
PostPosted: Sep 17, 2007 14:00    Post subject: Reply with quote

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.
 
Back to top
View user's profile Visit poster's website
vdecampo
Hero
PostPosted: Sep 18, 2007 0:03    Post subject: FBWinPrint 0.11 Reply with quote

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

Cheers!
-Vince
 
Back to top
View user's profile Visit poster's website
Antoni
Master
PostPosted: Sep 18, 2007 8:39    Post subject: Reply with quote

Ok, text printing works now.

I have another problem, I tried .PrintBmp and I get a crash..
 
Back to top
View user's profile Visit poster's website
vdecampo
Hero
PostPosted: Sep 18, 2007 23:05    Post subject: Reply with quote

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
 
Back to top
View user's profile Visit poster's website
notthecheatr
Master
PostPosted: Sep 18, 2007 23:31    Post subject: Reply with quote

Could you put the 'documentation' inside [ quote] [/ quote] tags?
 
Back to top
View user's profile Send e-mail Visit poster's website
vdecampo
Hero
PostPosted: Sep 18, 2007 23:43    Post subject: Reply with quote

Scroll button or down arrow broken? ;-)

Fixed!

-Vince
 
Back to top
View user's profile Visit poster's website
Antoni
Master
PostPosted: Sep 19, 2007 6:59    Post subject: Reply with quote

Code:

#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
 
 
Back to top
View user's profile Visit poster's website
vdecampo
Hero
PostPosted: Sep 19, 2007 18:32    Post subject: FBWinPrint .012 Reply with quote

I fixed stretching of images and some potential crash situations plus added some other functions...

Quote:

'************************************************************************
' 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
 
Back to top
View user's profile Visit poster's website
jbraden

PostPosted: Jan 07, 2008 18:54    Post subject: Reply with quote

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
 
Back to top
View user's profile
maddogg6
Sr. Member
PostPosted: Jan 07, 2008 19:19    Post subject: Reply with quote

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
 
Back to top
View user's profile Visit poster's website
vdecampo
Hero
PostPosted: Jan 07, 2008 19:22    Post subject: Reply with quote

@maddogg6

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

-Vince
 
Back to top
View user's profile Visit poster's website
Display posts from previous:   
Post new topic   Reply to topic    freebasic.net Forum Index -> Projects All times are GMT
Goto page 1, 2, 3, 4  Next
Page 1 of 4

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum



sf.net phatcode