• Welcome to PlanetSquires Forums.
 

José, if you're bored...

Started by Paul Squires, August 02, 2018, 09:19:19 PM

Previous topic - Next topic

José Roca

GDI+ would be one of the best options to draw the memory bitmap because you can use any kind of fonts and color, draw images and text, and also make it DPI aware (in this case PPI aware), getting the same results no matter the resolution of the printer. Of course, the users will have to learn to use GDI+, but with it you can go much more far than with the few XPRINT GDI methods to draw lines of boxes.


José Roca

#31
> Not sure that a Print Preview would be an absolute necessity but it would be cool also.

Because I'm a lazy Mediterranean enduring a very hot summer, I try to use more my mind that my fingers. Therefore, I'm thinking of Base64 encode these memory bitmaps, add them to a web page built on the fly and display them in the Preview of Internet Explorer (it can be called separately using COM without having to launch IE).

José Roca

A pity that no one else participates. Later, when they will try to use the framework, they will be more lost than a prawn in the desert. There are so many wrappers that the only way is to practice with them little by little and step by step. Testing is also essential to bring to light possible bugs and make suggestions.

SeaVipe

Hi José,
I've been working with CTime64 and I must say that it was a bit of a learning curve at first but once I had the basics figured out it all started to fall into place.
Initially WinFBE crashed repeatedly but that was just me not understanding what I was doing (not that I do now). I'm using snippets of code from a large FireFly project that utilizes Format() to display dates and time in a specific format like "08-Aug-2018" and "01:23:45". As suggested, I reviewed the Microsoft documentation on-line; the following (from the example) not only works but is much more elegant than my earlier code:
DIM ct AS CTime64

ct = ct.GetCurrentTime()

ct.Format("%Y-%m-%d")

I need print functions so that is my next challenge.
Thanks for all your hard work, José, this is really good stuff!
Clive Richey

Paul Squires

Quote from: José Roca on August 08, 2018, 02:49:09 PM
Because I'm a lazy Mediterranean enduring a very hot summer, I try to use more my mind that my fingers.

LOL, that made me smile :)
Paul Squires
PlanetSquires Software
WinFBE Editor and Visual Designer

Paul Squires

Quote from: José Roca on August 08, 2018, 02:17:00 PM
A first try.

The idea is to create an instance of the CPrint class and attach a printer to it with AttachPrinter or ChoosePrinter.


'#CONSOLE ON
#define UNICODE
#INCLUDE ONCE "Afx/CPrint.inc"
USING Afx

DIM pPrint AS CPrint
pPrint.AttachPrinter("Bullzip PDF Printer")


Then we can use the CMemBmp class to create a memory bitmap (with the dimensions returned by the GetHorizontalResolution and GetVerticalResolution methods of the CPrint class), draw its contents using GDI or GDI+ and send it to the PrintBitmap method.

For documents with more than one page, we could build an array of memory bitpamps and send it to a future new method of the CPrint class that will print them.

Holy smokes! Awesome! I have saved the class and started looking through it. I have access to a few different types of printers so I will test them to see how the class reacts. Great job  :)
Paul Squires
PlanetSquires Software
WinFBE Editor and Visual Designer

José Roca

Quote from: SeaVipe on August 08, 2018, 04:14:36 PM
Hi José,
I've been working with CTime64 and I must say that it was a bit of a learning curve at first but once I had the basics figured out it all started to fall into place.
Initially WinFBE crashed repeatedly but that was just me not understanding what I was doing (not that I do now). I'm using snippets of code from a large FireFly project that utilizes Format() to display dates and time in a specific format like "08-Aug-2018" and "01:23:45". As suggested, I reviewed the Microsoft documentation on-line; the following (from the example) not only works but is much more elegant than my earlier code:
DIM ct AS CTime64

ct = ct.GetCurrentTime()

ct.Format("%Y-%m-%d")

I need print functions so that is my next challenge.
Thanks for all your hard work, José, this is really good stuff!


This is what everybody interested in using my framework should do. You don't need to learn everything, but you should become familiar in what interests you for future use and try it.

Paul Squires

I think that if people would just browse your library and then compare it to their own code they'll see that they have been missing out on a vast array of incredibly useful functionality. 

I bet that if a user took your library and did this one thing (this is what I did)....... convert their existing program to be fully unicode and high dpi aware..... then they'd instantly see the benefit of your library and the universality it opens up across the winapi and languages across the world. I will never write anything anymore that is not fully unicode by default nor high dpi aware. These are two core things that Jose himself and his code has taught me. The CWSTR dynamic unicode string class alone is worth its weight in gold.

Paul Squires
PlanetSquires Software
WinFBE Editor and Visual Designer

SeaVipe

Indeed,A few examples would be helpful. I spent hours trying to figure out how to get a handle to a bitmap just so I could try CPrint (which is going to be very useful). Looking forward to Print Preview.
I got stumped here:
    Dim as ???? h
    Dim as boolean b = pPrint.PrintBitmap ( _
        wsz, _
        h, _
        FALSE, _
        InterpolationModeHighQualityBicubic )

The above returns False as h is not defined.
Clive Richey

José Roca

CPrint is still preliminary work. I have made an small test using a PDF printer driver and the PrintBitmap method is not working well yet. It would have been a miracle if I had got everything right at the first try.


'#CONSOLE ON
#define UNICODE
#INCLUDE ONCE "Afx/CPrint.inc"
#INCLUDE ONCE "Afx/CMemBmp.inc"
USING Afx

DIM pPrint AS CPrint
pPrint.AttachPrinter("Bullzip PDF Printer")
DIM pMemBmp AS CMemBmp = CMemBmp("MyImage.jpg")
pPrint.PrintBitmap("Test", pMemBmp.GethBmp)

PRINT
PRINT "Press any key..."
SLEEP


José Roca

This works, so the problem must be in CMemBmp when loading an image.


'#CONSOLE ON
#define UNICODE
#INCLUDE ONCE "Afx/CPrint.inc"
#INCLUDE ONCE "Afx/CMemBmp.inc"
USING Afx

DIM pPrint AS CPrint
pPrint.AttachPrinter("Bullzip PDF Printer")
DIM pMemBmp AS CMemBmp = CMemBmp(pPrint.GetHorizontalResolution, pPrint.GetVerticalResolution)
Rectangle pMemBmp.GetMemDC, 10, 10, 150, 150
LineTo pMemBmp.GetMemDC, 30, 180
pPrint.PrintBitmap("Test", pMemBmp.GethBmp)

PRINT
PRINT "Press any key..."
SLEEP


José Roca

Not sure which is the problem with CMemBmp when loading an image from a file, but if you just want to load a file and print it, this works:


'#CONSOLE ON
#define UNICODE
#INCLUDE ONCE "Afx/CPrint.inc"
#INCLUDE ONCE "Afx/AfxGdiplus.inc"
USING Afx

AfxSetProcessDPIAware
DIM pPrint AS CPrint
pPrint.AttachPrinter("Bullzip PDF Printer")
DIM wszFileName AS WSTRING * MAX_PATH = ExePath & "\VEGA_PAZ_01.jpg"
pPrint.PrintBitmap("Test", AfxGdipBitmapFromFile(wszFileName))

PRINT
PRINT "Press any key..."
SLEEP


José Roca

New file. I had forgot to delete the graphic object in the PrintBitmap method.

Joerg B.

Hello José
Thank you for your tirelessness in taking up and implementing new ideas. What you do for the FreeBasic community is indescribable for me. Your WinFBX offers possibilities in programming for everyone, which are normally only available to professionals with corresponding experience. Maybe the feedback doesn't come in the crowd. Maybe it's because your level needs to be understood first. Well, I can't.
Thank you again.
Greeting from Germany

Joerg

Paul Squires

I'm working on doing the conversion of the FB file handling routines to your stream classes. Not sure if I'll get to the print class today but I'll try.

Using the WinFBX help file, I'm thinking that you might need to explain what the HRESULT code is. I remember it from your COM programming but I'm not sure if others would readily identify it. Maybe put a hyperlink in the help file to a general page that describes HRESULT and lists some common codes like are specified at https://docs.microsoft.com/en-us/windows/desktop/seccrypto/common-hresult-values

I realize that your GetErrorInfo will return an empty string if no error but it is cleaner to do an inline error result check when opening a file. Like this:

   dim pStream AS CTextStream
   if pStream.OpenUnicode(wszFileName, IOMode_ForReading) <> S_OK then exit function

Maybe even if you indicate that the Return Value of Open/OpenUnicode is a non-zero HRESULT value. At least then users can do this:

   if pStream.OpenUnicode(wszFileName, IOMode_ForReading) <> 0 then exit function

Just a suggestion... as I think of stuff when I'm working through the conversion, I'll post them for you to consider.

Paul Squires
PlanetSquires Software
WinFBE Editor and Visual Designer