• Welcome to PlanetSquires Forums.
 

Cprint Question

Started by Petrus Vorster, August 12, 2022, 05:25:03 PM

Previous topic - Next topic

Petrus Vorster

Hi All

How am I supposed to create the CWSTR to use the Getdefaultprinter function?

It is clear I am missing something in the DIM statement.
I am getting all kinds of errors.
I am not yet clued up on this CWSTR use.

And how would I create a list of printers parsed into a combobox?

Your help will be really appreciated.

-Peter
-Regards
Peter

Paul Squires

I am on my Linux machine right now so I can't produce a working example, but the code would look something like this:

' Create an instance of the CPrint class
DIM pPrint AS CPrint

' Call the class method to get the default printer and store it in a dynamic unicode string (CWSTR)
DIM wszDefault AS CWSTR = pPrint.GetDefaultPrinter

' Display the printer name that was returned
PRINT wszDefault

Here is Jose's online documentation for the class that should be the very latest. I also have this documentation built into WinFBE's help system.

https://github.com/JoseRoca/WinFBX/blob/master/docs/Printing/CPrint%20Class.md




Paul Squires
PlanetSquires Software
WinFBE Editor and Visual Designer

Paul Squires

To get a list of printer names you would use the EnumPrinterNames method and parse out the CHR(13,10) that separates each entry in the returned CWSTR string. Jose probably already has an example of this somewhere on this site. Not sure.

You would use the AfxParse() function from Jose's library. There are many VERY useful string manipulation functions in his AfxStr.inc file. Here is a list of the functions. Get to know them.  :)
https://github.com/JoseRoca/WinFBX/blob/master/docs/String%20Management/String%20Procedures.md
Paul Squires
PlanetSquires Software
WinFBE Editor and Visual Designer

Petrus Vorster

I just missed this : pPrint.GetDefaultPrinter
I am very happy that I got that far already!!!

Thanks a million.

-Peter
-Regards
Peter

Petrus Vorster

https://github.com/JoseRoca/WinFBX/blob/master/docs/String%20Management/String%20Procedures.md

That is a lot of work right there.
Without you two I still would be at Print "Hello World".

-Regards, Peter
-Regards
Peter

Bumblebee

DIM cws AS CWSTR = AfxStrRetain("abacadabra","b")   ' -> "bb"
DIM cws AS CWSTR = AfxStrRetain("Brigitte Bardot","B")   ' -> "BB"

Sorry, couldn't help myself  ;D
Failed pollinator.

Petrus Vorster

-Regards
Peter