This function creates a device context.

[C++Builder/Visual C++]     HDC IKPrintCreateDCEx(LPCTSTR PrinterName, LPCTSTR PrintFileName, HANDLE hDevMode, HANDLE hDevNames, short Mode);
[Delphi]         function IKPrintCreateDCEx(PrinterName, PrintFileName: PChar; hDevMode, hDevNames: THandle; Mode: Smallint): HDC;
[Visual Basic]   Function IKPrintCreateDCEx(ByVal PrinterName As String, ByVal PrintFileName As String, ByVal hDevMode As Long, ByVal hDevNames As Long, ByVal Mode As Integer) As Long

Parameters

Name Explanation
PrinterName The name of the printer
PrintFileName The filename of the file storing the printer settings (The filename saved by the IKSaveDevModeHandle, IKSaveDevModeHandleEx, or IKSetPrint function)
hDevMode The handle of the DEVMODE structure (The handle retrieved by the IKGetDevModeHandle or the IKGetDevModeHandleEx function)
hDevNames The handle of DEVNAMES structure (The handle retrieved by the IKGetDevModeHandleEx function)
Mode The method for creating the device context (from 0 to 2)

Return Value

Returns the device context if successful. Returns null (0) if unsuccessful.

Explanation

The IKPrintCreateDC function creates a device context in one of three ways.

When the Mode parameter is 0:
The device context is created for the printer that has its name set in the PrinterName parameter.
The PrintFileName, hDevMode, and hDevNames are disabled.
When the Mode parameter is 1:
The device context is created for the printer that is listed in the file set in the PrintFileName parameter.
The PrinterName and hDevMode are disabled.
When the Mode parameter is 2:
The device context is created from the handle of the DEVMODE structure that is set in the hDevMode parameter.
The PrinterName and PrintFileName are disabled.

To print with the default printer using the current settings, set the Mode parameter to 1 and in the PrintFileName parameter set, "Default".

When the device context is created and returned in the return value, the IKPrintStartDoc, IKPrintStartPage, IKPrintEndPage, IKPrintEndDoc functions can be used. The device context is freed using the IKPrintDeleteDC function.

As an extension to the PrintFileName, it is possible to set and save a other printer settings using the PrintFileName. Before executing the IKPrintCreateDC function, it is possible to save not only the file name but also the number of copies, the paper orientation, and the paper size (in that order) in the PrintFileName. The delimiter for the settings is a semicolon (;). Note: Enter a zero (0) into the settings that you do not want to change.


Orientation: The values in parentheses are the same as the constants used in WindowsAPI
1: Vertical (DMORIENT_PORTRAIT)            2: Horizontal (DMORIENT_LANDSCAPE)

PaperSize: The values in parentheses are the same as the constants used in WindowsAPI

  1. Letter, 8.5 x 11 in (DMPAPER_LETTER)
  2. Letter Small, 8.5 x 11 in (DMPAPER_LETTERSMALL)
  3. Tabloid, 11 x 17 in (DMPAPER_TABLOID)
  4. Ledger, 17 x 11 in (DMPAPER_LEDGER)
  5. Legal, 8.5 x 14 in (DMPAPER_LEGAL)
  6. Statement, 5.5 x 8.5 in (DMPAPER_STATEMENT)
  7. Executive, 7.25 x 10.5 in (DMPAPER_EXECUTIVE)
  8. A3, 297 x 420 mm (DMPAPER_A3)
  9. A4, 210 x 297 mm (DMPAPER_A4)
  10. A4 Small, 210 x 297 mm (DMPAPER_A4SMALL)
  11. A5, 148 x 210 mm (DMPAPER_A5)
  12. B4, 250 x 354 mm (DMPAPER_B4)
  13. B5, 182 x 257 mm (DMPAPER_B5)

For paper sizes other than those listed above, please refer to the WindowsAPI reference for your development container.


Sample Code: Using a printer setting file (IKPrn.IK) to print (VisualBasic)

(1) Standard case

     PrintFileName = "C:\Test\IKPrint.IK"

(2) Using the extended functions of the printer setting file

     A) Number of copies= 3, Orientation = Horizontal, PaperSize = B5

         PrintFileName = "C:\Test\IKPrint.IK;3;2;13"

     B) Retrieve the number of copies and paper size from the printer file but the orientation to horizontal

         PrintFileName = "C:\Test\IKPrint.IK;0;2;0" or PrintFileName = "C:\Test\IKPrint.IK;0;2"


Sample Code: Using a printer setting file (IKPrn.IK) to print

(1)C++Builder/Visual C++

    HDC hDC;


    hDC = IKPrintCreateDC(NULL, "C:\\Test\\IKPrn.IK", NULL, 1);

    if (hDC == NULL) return;


    //In Visual C++ pass Form1->Handle into m_hWnd

    if (IKPrintStartDoc(hDC, Form1->Handle, "", "", "", "ImageKit Print Sample") != FALSE) {

        IKPrintStartPage(hDC);


        // Display image, draw text or shapes, etc.


        IKPrintEndPage(hDC);

        IKPrintEndDoc(hDC);

     }

     IKPrintDeleteDC(hDC);


(2)Delphi

    DC: HDC;


    DC := IKPrintCreateDC(nil, 'C:\Test\IKPrn.IK', 0, 1);

    if DC = 0 then Exit;

    if (IKPrintStartDoc(DC, Form1.Handle, '', '', '', 'ImageKit Print Sample') <> False) then

    begin

        IKPrintStartPage(DC);


        // Display image, draw text or shapes, etc.


        IKPrintEndPage(DC);

        IKPrintEndDoc(DC);

    end;

    IKPrintDeleteDC(DC);


(3)Visual Basic

    Dim hDC As Long


    hDC = IKPrintCreateDC(vbNullString, "C:\Test\IKPrn.IK", 0, 1)

    If hDC = 0 Then Exit Sub

    If (IKPrintStartDoc(hDC, Form1.hWnd, "", "", "", "ImageKit Print Sample") <> False) Then

        IKPrintStartPage(hDC)


        'Display image, draw text or shapes, etc.


        IKPrintEndPage(hDC)

        IKPrintEndDoc(hDC)

    End If

    IKPrintDeleteDC(hDC)

 

The ImageKit10 ActiveX is a product created by Newtone Corporation