This function creates a device context.
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 or IKSetPrint function) |
hDevMode | The handle of the DEVMODE structure (The handle retrieved by the IKGetDevModeHandle 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 and DevMode 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 DevMode 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
- Letter, 8.5 x 11 in (DMPAPER_LETTER)
- Letter Small, 8.5 x 11 in (DMPAPER_LETTERSMALL)
- Tabloid, 11 x 17 in (DMPAPER_TABLOID)
- Ledger, 17 x 11 in (DMPAPER_LEDGER)
- Legal, 8.5 x 14 in (DMPAPER_LEGAL)
- Statement, 5.5 x 8.5 in (DMPAPER_STATEMENT)
- Executive, 7.25 x 10.5 in (DMPAPER_EXECUTIVE)
- A3, 297 x 420 mm (DMPAPER_A3)
- A4, 210 x 297 mm (DMPAPER_A4)
- A4 Small, 210 x 297 mm (DMPAPER_A4SMALL)
- A5, 148 x 210 mm (DMPAPER_A5)
- B4, 250 x 354 mm (DMPAPER_B4)
- 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)