Previous Topic Next topic Print topic


PC_PRINTER_INFO_DOTNET

Enables the access to the native Hdc for a printer. Invokes a delegate with the current .NET Graphics object for the printer handle along with a Rectangle object and the PageSettings object.
Restriction:
  • This routine is supported in .NET COBOL only.
  • This routine is not currently supported on UNIX platforms.

Syntax:

    call "PC_PRINTER_INFO_DOTNET" using 
                                    by reference cblt-pi-printer-handle 
                                    by value cblt-printer-info-delegate 
                                    by value user-object 
                          returning status-code 
    end-call

Parameters:

Using call prototype Picture (32-bit systems) Picture (64-bit systems)
printer-handle cblt-pi-printer-handle pic x(4) comp-5 pic x(8) comp-5
delegate cblt-printer-info-delegate see delegate-id above see delegate-id above
user-object object object object
cblt-printer-info-delegate
A delegate defined as:
    delegate-id PrinterInfoDelegate. 
            procedure division using by value gr as type Graphics 
                                 by value pb as type Rectangle 
                                 by value ps as type PageSettings 
                                 by value uo as object 
                                . 
    end delegate. 
status-code
See Library Routines - Key

On Entry:

printer-handle
The printer handle returned when the printer was opened
delegate
A delegate that receives either the Graphics, Rectangle, PageSettings or the user-object
user-object
Any object you might want to use in the delegate.

On Exit:

delegate
The delegate parameter is invoked with the required parameters
status-code
Printer Handling Routines Return Codes

Accessing native resources:

The PC_PRINTER_INFO is unable to return the underlying Hdc attribute for a printer connection on the .NET platform as the attribute is only available during a page-event. You can use the PC_PRINTER_INFO_DOTNET API, however, to access the native Hdc for the printer.

In the delegate, you can use the GetHdc() and the ReleaseHdc() methods on the graphics object. For example:

    declare dn-hdc = gr::GetHdc() 
    try 
        *> use the dn-hdc 
    finally 
       invoke gr::ReleaseHdc() 
    end-try 

Examples:

The following example shows how to use the PC_PRINTER_INFO_DOTNET API:

        $set iltarget"x86" 
        $set ilref"System.Drawing" 
        $set ilusing"System.Drawing". 
        $set ilusing"System.Drawing.Printing". 
 
        program-id. pcid. 
        special-names. 
            call-convention 74 is winapi. 
        working-storage section. 
        copy "cbltypes.cpy". 
        01. 
            03 document-title. 
            05 title-len         pic x(2) comp-5. 
            05 title-text        pic x(20). 
                03  font-family. 
            05 font-family-namelen  pic x(2) comp-5 value 80. 
            05 font-family-name     pic x(80). 
            03 abort               pic x(4) comp-5 value 1. 
            03 ctrl                pic x(4) comp-5 value 2. 
            03 flags               pic x(4) comp-5 value 1. 
            03 handle              pic x(4) comp-5. 
        01 status-code cblt-os-size value zeroes. 
 
        procedure division. 
            move 30 to title-len 
            move "PC_PRINTER_INFO_DOTNET Example" to title-text 
 
            call "PC_PRINTER_OPEN" using by reference handle 
                                            by reference document-title 
                                            by value flags 
                                            by value 0 
                                            returning status-code 
            end-call 
            if status-code not equal 0 
                exhibit named status-code 
                stop run 
            end-if 
 
            declare pinfo-delegate as type PrinterInfoDelegate 
            set pinfo-delegate to 
                delegate(gr as type Graphics, 
                        pb as type Rectangle, 
                        ps as type PageSettings 
                        uo as object ) 
 
                *> create an Eclipse the side of the page 
                    declare customColor = type Color::FromArgb(50, type Color::Blue) 
                    declare shadowBrush = new SolidBrush(customColor) 
 
                    invoke gr::FillEllipse(shadowBrush, pb) 
 
                    declare bigText as string = uo as string 
                    declare drawFormat = new StringFormat 
                    set drawFormat::Alignment to type StringAlignment::Center 
                    set drawFormat::LineAlignment to type StringAlignment::Center 
 
                    invoke gr::DrawString(bigText, new Font("Courier New", 24), new SolidBrush(type Color::Red), pb, drawFormat) 
 
                end-delegate 
 
            declare nullObject as object = null 
 
            call "PC_PRINTER_INFO_DOTNET" using 
                    by reference handle 
                    by value pinfo-delegate 
                    by value "Big Red text in the middle" 
                    returning status-code 
            end-call 
            if status-code not equal 0 
                exhibit named status-code 
            end-if 
 
            call "PC_PRINTER_CLOSE" using 
                by reference handle 
                returning status-code 
            end-call 
            if status-code not equal 0 
                exhibit named status-code 
                stop run 
            end-if 
            goback. 
        end program. 
 
        delegate-id PrinterInfoDelegate. 
            procedure division using by value gr as type Graphics 
                                    by value pb as type Rectangle 
                                    by value ps as type PageSettings 
                                    by value uo as object 
                                    . 
        end delegate.

The following example shows how to create an anonymous delegate (without specifying a name for the delegate) and then use it with the PC_PRINTER_INFO_DOTNET API:

        declare pinfo-delegate as type PrinterInfoDelegate 
        set pinfo-delegate to 
                delegate(gr as type Graphics, 
                        pb as type Rectangle, 
                        ps as type PageSettings 
                        uo as object) 
 
                    display "DpiX = " gr::DpiX 
                    display "DpiY = " gr::DpiY 
 
                    display "Page Boundary : " pb 
                    display "Page Settings : " ps 
               end-delegate 

You can use this delegate with the PC_PRINTER_INFO_DOTNET API as follows:

        call "PC_PRINTER_INFO_DOTNET" using 
                    by reference handle 
                    by value pinfo-delegate 
                    by value self  *> user-object is the program itself 
                                    *> so you can do a pinfo-delegate to the entry-point 
        end-call 
Previous Topic Next topic Print topic