FBWinPrint 0.10
Here is a new link....spodhaje wrote:Hi Vince,
The link for the zip redirects to a drupal setup page. Is there a mirror where I can find the download?
-- Steve
http://www.ftpisland.com/files/FBWinPrint.zip
Cheers!
-Vince
-
- Posts: 86
- Joined: Jan 22, 2009 18:52
- Location: Houston, tx
Re: FBWinPrint 0.10
Hi Vince,vdecampo wrote: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...
[
-Vince
I just found your printer code, and i got to say thanks for it! Save me all kinds of trouble.
One question for you though. I'm not a very good windows programmer, so I wasn't able to figure this out. When I use your awesome code, the print popup dialog box appears in the background. I have to minimize my app, to get to the print dialog. Any ideas on how I can make your print screen pop up to the front?
thanks,
John
-
- Posts: 86
- Joined: Jan 22, 2009 18:52
- Location: Houston, tx
I haven't tried it on XP yet, but I'm wondering if this is a Vista thing. I'm using a GFX window, not the console.vdecampo wrote:Hi CommanderRaven!
I'm glad you found the code useful. Are you using a console window or a gfx window? The Printer Dialog is supposed to use the window handle from the window that currently has keyboard focus, but I am not sure if a console window will return a proper hWnd or not.
-Vince
I added a GFX window to your code on the same, and I noticed the same behavior.
Strange. I'll keep tinkering with it. Maybe I can find code to move a windows back....
Thanks,
John
-
- Posts: 86
- Joined: Jan 22, 2009 18:52
- Location: Houston, tx
Hey dude, I figured it out. I made two lines of code change to your FBWinPrint.bi code.vdecampo wrote:Hi CommanderRaven!
I'm glad you found the code useful. Are you using a console window or a gfx window? The Printer Dialog is supposed to use the window handle from the window that currently has keyboard focus, but I am not sure if a console window will return a proper hWnd or not.
-Vince
I did some checking and I was looking at the getfocus function on msdn.
Sorry you will have to cut and paste the whole URL below to see the pages I was looking at.
http://msdn.microsoft.com/en-us/library ... S.85).aspx
So I looked at the GetForegroundWindow function
http://msdn.microsoft.com/en-us/library ... S.85).aspx
They suggest using the GetForeGroundWindow for the current window.
Since both windows returned the same HWND values, I figured that I try the other command and see what happens. Bingo, now it shows up in the same active window!
So I change your function. I changed the getfocus to Getforeground.
Code: Select all
Function _ShowPrinter() As String
Dim PDlg As PRINTDLG_TYPE
Dim DevMode As DEVMODE_TYPE
Dim DevName As DEVNAMES_TYPE
Dim lpDevMode As Integer Ptr
Dim lpDevName As Integer Ptr
Dim bReturn As Integer
'Use PrintDialog to get the handle to a memory
'block with a DevMode and DevName structures
PDlg.lStructSize = SizeOf(PrintDlg)
'PDlg.hwndOwner = GetFocus()
PDlg.hwndOwner = GetForegroundWindow()
Code: Select all
#Include "windows.bi"
#Include "FBWinPrint.bi"
#Include "fbgfx.bi"
#if __FB_LANG__ = "fb"
Using FB '' Screen mode flags are in the FB namespace in lang FB
#EndIf
ScreenRes 1024,768,32,1,GFX_WINDOWED Or gfx_no_switch
Width 1024/8,768/16
Dim PO As PrinterObj
Dim FontName As String
Dim FontSize As Integer
Dim tempstring As String
Dim tempnum As Integer
Dim tempval As HDC
fontname="Courier New"
fontsize=30
With PO
tempstring =.Dialog
tempval =.PrinterDC
tempstring =.PrinterName
tempnum =.PageWidth
tempnum =.PageHeight
'Print .Font(FontName, FontSize)
.DocStart
.PageStart
.SetFont (FontName, FontSize, RGBA (255,0,0,0))
.DrawBox (90,90,900,900,RGBA(255,0,0,0))
.PPrint (100,100,"Test")
.PrintWindow GetDesktopWindow ,500,500,1000,750
.PrintWindow GetDesktopWindow ,500,1500,1000,750
.PrintBMP (ExePath & "\test.bmp", 0,0,500,1500)
.PageEnd
.DocEnd
End With
Print "Print Job Sent To Printer."
Print "Press any key to exit."
Sleep
End
Although I don't need this dialog box for what I'm doing, I figure the same change should be made.
Code: Select all
Function _ShowPageSetupDlg() As Integer
Dim PSD As PAGESETUPDLG
'Set the structure size
PSD.lStructSize = Len(PSD)
'Set the owner window
'PSD.hwndOwner = GetFocus()
PSD.hwndOwner = GetForegroundWindow()
'Set the application instance
PSD.hInstance = NULL
'no extra flags
PSD.flags = PSD_DISABLEPRINTER
'Show the pagesetup dialog
If PAGESETUPDLG(@PSD) Then
_ShowPageSetupDlg = 0
Else
_ShowPageSetupDlg = -1
End If
End Function
Thanks, Vince, it worked!
Any hint about why it prints with red text but draws a blue box, while the color value passed is red for both?
EDITED: Nevermind, I found it : setFont is reversing the color number to the windows format while drawbox is not. I'm afraid it's a bug.
EDIT2:
I suggest to change the PageWidth / PageHeight properties by passing to GetDeviceCaps HORZRES / VERTRES as those are the properties that return the resolutions of the true printable area (unprintable area removed).
Now we're asking PHYSICALWIDTH / PHYSICALHEIGHT that refer to the whole sheet of paper, not accounting for the unprintable area.
Any hint about why it prints with red text but draws a blue box, while the color value passed is red for both?
EDITED: Nevermind, I found it : setFont is reversing the color number to the windows format while drawbox is not. I'm afraid it's a bug.
EDIT2:
I suggest to change the PageWidth / PageHeight properties by passing to GetDeviceCaps HORZRES / VERTRES as those are the properties that return the resolutions of the true printable area (unprintable area removed).
Now we're asking PHYSICALWIDTH / PHYSICALHEIGHT that refer to the whole sheet of paper, not accounting for the unprintable area.
Ok, here it is
http://antonigual.phatcode.net/fbsources/fbwinprint.zip
-Corrected bug with PrintBox color
- Changed PageWidth and PageHeight properties to use the printable size of the sheet
- Addded scaling to Pprint,PrintBox, PrinBMP and PrintWindow to make them printer independent. Now coordinates are 0-10000, being 10000 the printable width/height of the page
- Tested with HP4000 and Panasonic DPC322 printers and PDF and Djvu converters
-The demo generates a simple bmp to test
http://antonigual.phatcode.net/fbsources/fbwinprint.zip
-Corrected bug with PrintBox color
- Changed PageWidth and PageHeight properties to use the printable size of the sheet
- Addded scaling to Pprint,PrintBox, PrinBMP and PrintWindow to make them printer independent. Now coordinates are 0-10000, being 10000 the printable width/height of the page
- Tested with HP4000 and Panasonic DPC322 printers and PDF and Djvu converters
-The demo generates a simple bmp to test
Hi,
Just came across FBWinprint, and was trying to use it in my current project.
In the printer dialog I selected "Landscape" mode.
However, the output is still printed in portrait mode.
Can I do anything about this ?
My Background : I am a beginner, with no knowledge of Windows APIs, etc.
Thanks & Regards.
Just came across FBWinprint, and was trying to use it in my current project.
In the printer dialog I selected "Landscape" mode.
However, the output is still printed in portrait mode.
Can I do anything about this ?
My Background : I am a beginner, with no knowledge of Windows APIs, etc.
Thanks & Regards.
I have the same problem as bethel: I want to control a standard Windows-Printer (or PDF-Print) and have nearly no knowledge about API or similar instruments. I posted my problem recently here: http://www.freebasic.net/forum/viewtopic.php?t=15064
I repeat what I miss in FreeBasic: A “fool-proof” solution for fundamental control-commands to a printer.
AFAIK only ASCII control characters (8 / BS, 10 / LF, 12 / FF, 13 / CR) are possible in FB for controlling a printer. But when I send a string (text) to a printer, I don’t know how to control font, font-size, margins and text-effects like bold or underlined characters.
I repeat what I miss in FreeBasic: A “fool-proof” solution for fundamental control-commands to a printer.
AFAIK only ASCII control characters (8 / BS, 10 / LF, 12 / FF, 13 / CR) are possible in FB for controlling a printer. But when I send a string (text) to a printer, I don’t know how to control font, font-size, margins and text-effects like bold or underlined characters.