FBWinPrint 0.10

User projects written in or related to FreeBASIC.
spodhaje
Posts: 38
Joined: Oct 25, 2007 14:05

Postby spodhaje » Feb 07, 2008 16:48

Hi Vince,

The link for the zip redirects to a drupal setup page. Is there a mirror where I can find the download?

-- Steve
vdecampo
Posts: 2982
Joined: Aug 07, 2007 23:20
Location: Maryland, USA
Contact:

Postby vdecampo » Feb 07, 2008 17:10

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


Here is a new link....

http://www.ftpisland.com/files/FBWinPrint.zip

Cheers!
-Vince
CommanderRaven
Posts: 86
Joined: Jan 22, 2009 18:52
Location: Houston, tx

Re: FBWinPrint 0.10

Postby CommanderRaven » Oct 03, 2009 9:36

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


Hi 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
vdecampo
Posts: 2982
Joined: Aug 07, 2007 23:20
Location: Maryland, USA
Contact:

Postby vdecampo » Oct 03, 2009 11:00

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
CommanderRaven
Posts: 86
Joined: Jan 22, 2009 18:52
Location: Houston, tx

Postby CommanderRaven » Oct 03, 2009 16:01

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

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
CommanderRaven
Posts: 86
Joined: Jan 22, 2009 18:52
Location: Houston, tx

Postby CommanderRaven » Oct 03, 2009 17:50

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


Hey dude, I figured it out. I made two lines of code change to your FBWinPrint.bi code.

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/ms646294(VS.85).aspx

So I looked at the GetForegroundWindow function

http://msdn.microsoft.com/en-us/library/ms633505(VS.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()


I modified your test code so that it would not print the raw numbers for the printer selection. In affect making it transparent when you print. I also used ScreenRes open a standard 1024x768 window.

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


That will allow a graphic screen to be used, and you can print using your awesome code.

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 dude!
Antoni
Posts: 1393
Joined: May 27, 2005 15:40
Location: Barcelona, Spain

Postby Antoni » Oct 18, 2009 14:42

Is this the inteded output of the example?
Image
I guess the screenshots are too small and should mot overlap anything. Trying to print to a pdf using Acrobat 6.0 distiller drivers...
Could anyone suggest a solution?
vdecampo
Posts: 2982
Joined: Aug 07, 2007 23:20
Location: Maryland, USA
Contact:

Postby vdecampo » Oct 18, 2009 15:06

@Antoni

You actually have to scale your images to the width and height of your particular printer using the .pagewidth, .pageheight properties. The example is using an arbitrary widht/height.

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

Postby Antoni » Oct 18, 2009 16:01

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.
vdecampo
Posts: 2982
Joined: Aug 07, 2007 23:20
Location: Maryland, USA
Contact:

Postby vdecampo » Oct 18, 2009 21:09

Antoni wrote: 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).


I look forward to seeing your changes! ;)

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

Postby Antoni » Oct 19, 2009 18:12

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
bethell
Posts: 44
Joined: Sep 26, 2009 22:02

Postby bethell » Dec 22, 2009 4:24

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.
vdecampo
Posts: 2982
Joined: Aug 07, 2007 23:20
Location: Maryland, USA
Contact:

Postby vdecampo » Jan 29, 2010 2:45

Wow! I did not even realize I missed a post here. Sorry. I got injured recently and couldn't spend much time at the computer. I will look into this ASAP.

-Vince
bethell
Posts: 44
Joined: Sep 26, 2009 22:02

Postby bethell » Jan 29, 2010 7:51

Hi Vdecampo,

Thanks for acknowledging my post.

Sorry to hear about your injury - nothing serious I hope.

I hope to use FBWinprint soon in my project.

Currently I'm not able to provide USB printer functionality, due to my lack of knowledge , & time to learn, Windows APIs.

Thanks again, & regards.
SL
Posts: 5
Joined: Jan 28, 2010 17:29

Postby SL » Jan 30, 2010 14:11

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.

Return to “Projects”

Who is online

Users browsing this forum: No registered users and 4 guests