home *** CD-ROM | disk | FTP | other *** search
- PROGRAM Print;
-
- {$R PRINT}
-
- USES WObjects, WinTypes, WinProcs, Strings, WinDos;
-
- CONST
- { Command ID }
- idm_About = 100;
- idm_Print = 110;
- idm_PrintOpt = 111;
- idm_DevCaps = 112;
- idm_GetDevCap= 113;
-
- idm_LoadBitmap = 201;
- idm_PrintBitmap = 202;
-
- TYPE
- PMyDialog = ^TMyDialog;
- TMyDialog = OBJECT (TDialog)
- END;
-
- PMyWindow = ^TMyWindow;
- TMyWindow = OBJECT (TWindow)
- CONSTRUCTOR Init (AParent: PWindowsObject; ATitle: PChar);
- PROCEDURE GetWindowClass (VAR AWndClass: TWndClass); VIRTUAL;
- PROCEDURE WMRButtonDown (VAR Msg: TMessage); VIRTUAL wm_First + wm_RButtonDown;
- PROCEDURE About (VAR Msg: TMessage); VIRTUAL cm_First + idm_About;
- PROCEDURE Print (VAR Msg: TMessage); VIRTUAL cm_First + idm_Print;
- PROCEDURE DevCaps (VAR Msg: TMessage); VIRTUAL cm_First + idm_DevCaps;
- PROCEDURE GetDevCaps (VAR Msg: TMessage); VIRTUAL cm_First + idm_GetDevCap;
- PROCEDURE Options (VAR Msg: TMessage); VIRTUAL cm_First + idm_PrintOpt;
- PROCEDURE LoadABitmap (VAR Msg: TMessage); VIRTUAL cm_First + idm_LoadBitmap;
- PROCEDURE PrintBitmap (VAR Msg: TMessage); VIRTUAL cm_First + idm_PrintBitmap;
- END;
-
- TMyApplication = OBJECT (TApplication)
- PROCEDURE InitMainWindow; VIRTUAL;
- END;
-
- PChar39 = ARRAY [0..39] OF CHAR;
-
- VAR
- DruckerName, TreiberName, DruckerPort: PChar39;
- DeviceMode: TDevMode;
-
- FUNCTION AbortProc (Window: HWnd; Msg, wParam: WORD; lParam: Longint): BOOL; EXPORT;
- BEGIN
- MessageBeep(0);
- IF (Msg = wm_Command) THEN BEGIN
- DestroyWindow(Window);
- AbortProc := TRUE;
- END
- ELSE IF (Msg = wm_InitDialog) THEN BEGIN
- SetFocus(Window);
- AbortProc := TRUE;
- END ELSE AbortProc := FALSE;
- END;
-
- FUNCTION CallMeNames: BOOLEAN;
- VAR
- Printer: ARRAY [0..80] OF CHAR;
- KommaPtr, KommaPos: PChar;
- BEGIN
- GetProfileString ('windows', 'device', NIL, Printer, SizeOf(Printer));
- KommaPtr := Printer;
- KommaPos := StrScan (KommaPtr, ',');
- StrLCopy (DruckerName, KommaPtr, (KommaPos - KommaPtr));
- KommaPtr := KommaPos +1;
- KommaPos := StrScan (KommaPtr, ',');
- StrLCopy (TreiberName, KommaPtr, (KommaPos - KommaPtr));
- KommaPtr := KommaPos +1;
- StrLCopy (DruckerPort, KommaPtr, StrLen(KommaPtr));
- END;
-
- FUNCTION GetPrinterDC : HDC;
- BEGIN
- CallMeNames;
- GetPrinterDC := CreateDC (TreiberName, DruckerName, DruckerPort, NIL);
- END;
-
-
- CONSTRUCTOR TMyWindow.Init (AParent: PWindowsObject; ATitle: PChar);
- BEGIN
- TWindow.Init (AParent, ATitle);
- Attr.Menu := LoadMenu(HInstance, 'Generic');
- Attr.w := 400;
- Attr.h := 300;
- END;
-
- PROCEDURE TMyWindow.GetWindowClass (VAR AWndClass: TWndClass);
- BEGIN
- TWindow.GetWindowClass (AWndClass);
- AWndClass.hIcon := LoadIcon (HInstance, 'MYICON');
- END;
-
- PROCEDURE TMyWindow.WMRButtonDown (VAR Msg: TMessage);
- BEGIN
- InvalidateRect (HWindow, NIL, True);
- END;
-
- PROCEDURE TMyWindow.About (VAR Msg: TMessage);
- VAR
- Dialog: TDialog;
- BEGIN
- Dialog.Init(@Self, 'AboutBox');
- Dialog.Execute;
- Dialog.Done;
- END;
-
- PROCEDURE TMyWindow.Print (VAR Msg: TMessage);
- VAR
- AbortDialog: PMyDialog;
- lpAbortProc: TFarProc;
- lpTemp: Pointer;
- PrinterDC: HDC;
- hAbortDlgWindow: HWnd;
- BEGIN
- PrinterDC := GetPrinterDC;
- IF (PrinterDC < 32) THEN BEGIN
- MessageBox (HWindow, 'Cannot print this file', NIL, mb_Ok OR mb_IconHand);
- Exit;
- END;
- Escape (PrinterDC, SetAbortProc, 0, MakeProcInstance(@AbortProc, hInstance), NIL);
- IF (Escape(PrinterDC, StartDoc, 0, NIL, NIL) < 0) THEN BEGIN
- MessageBox (HWindow, 'Unable to start print job', NIL, mb_Ok OR mb_IconHand);
- FreeProcInstance (lpAbortProc);
- DeleteDC (PrinterDC);
- EXIT;
- END;
- AbortDialog := New(PMyDialog, Init(@Self, 'AbortDlg'));
- Application^.ExecDialog(AbortDialog);
- MessageBeep(0);
- END;
-
- PROCEDURE TMyWindow.Options (VAR Msg: TMessage);
- VAR
- PrinterLibHandle: THandle;
- DriverFileName: PChar39;
- ProcAddress: TFarProc;
- BEGIN
- CallMeNames;
- DriverFileName := TreiberName;
- StrCat (DriverFileName, '.DRV');
- PrinterLibHandle := LoadLibrary (DriverFileName);
- ProcAddress := GetProcAddress (PrinterLibHandle, 'ExtDeviceMode');
- IF (ProcAddress <> NIL) THEN
- TExtDeviceMode(ProcAddress) (Application^.MainWindow^.HWindow,
- PrinterLibHandle, DeviceMode, DriverFileName, DruckerPort, DeviceMode,
- NIL, dm_Prompt OR dm_Update)
- ELSE BEGIN
- ProcAddress := GetProcAddress(PrinterLibHandle, 'DEVICEMODE');
- IF (ProcAddress <> NIL)
- THEN TDeviceMode(ProcAddress) (Application^.MainWindow^.HWindow,
- PrinterLibHandle, DriverFileName, DruckerPort);
- END;
- FreeLibrary (PrinterLibHandle);
- END;
-
- PROCEDURE TMyWindow.DevCaps (VAR Msg: TMessage);
- VAR
- Dialog: PDialog;
- DestStr: ARRAY [0..79] OF CHAR;
- DataSize: Longint;
- Information: ARRAY [0..1] OF WORD;
- DC: HDC;
- DeviceMode: TDevMode;
- DeviceModePtr: PDevMode;
- ProcAddress: TFarProc;
- DriverFileName: PChar39;
- PrinterLibHandle: THandle;
- BEGIN
- CallMeNames;
- DriverFileName := TreiberName;
- StrCat (DriverFileName, '.DRV');
- PrinterLibHandle := LoadLibrary (DriverFileName);
- ProcAddress := GetProcAddress (PrinterLibHandle, 'ExtDeviceMode');
- IF (ProcAddress <> NIL) THEN
- BEGIN
- DataSize := TExtDeviceMode(ProcAddress) (0, PrinterLibHandle, DeviceMode,
- DruckerName, DruckerPort, DeviceMode, NIL, 0);
- GetMem (DeviceModePtr, DataSize);
- TExtDeviceMode(ProcAddress) (HWindow, PrinterLibHandle, DeviceModePtr^,
- DruckerName, DruckerPort, DeviceMode, NIL, dm_Copy);
- DC := GetDC (HWindow);
-
- DeviceModePtr^.dmCopies := 1;
- DeviceModePtr^.dmDefaultSource := dmBin_Upper;
- DeviceModePtr^.dmPrintQuality := dmRes_High;
- Information[0] := Ofs(DeviceModePtr^.dmDeviceName);
- Information[1] := Seg(DeviceModePtr^.dmDeviceName);
- WVSPrintF (DestStr, 'Druckername : %s', Information);
- TextOut(DC, 10, 10, DestStr, StrLen(DestStr));
-
- Information[0] := Hi(DeviceModePtr^.dmSpecVersion);
- Information[1] := Lo(DeviceModePtr^.dmSpecVersion);
- WVSPrintF (DestStr, 'Versionsnummer des Druckertreibers : %2x.%02x', Information);
- TextOut (DC, 10, 30, DestStr, StrLen(DestStr));
-
- Information[0] := DeviceModePtr^.dmSize;
- WVSPrintF (DestStr, 'Gr÷▀e von TDevMode : %4u Bytes', Information);
- TextOut (DC, 10, 50, DestStr, StrLen(DestStr));
-
- Information[0] := DeviceModePtr^.dmOrientation;
- WVSPrintF (DestStr, 'Papierausrichung : %4u = Portrait', Information);
- TextOut (DC, 10, 70, DestStr, StrLen(DestStr));
-
- Information[0] := DeviceModePtr^.dmPaperSize;
- WVSPrintF (DestStr, 'Papergr÷▀e : %4u = DIN A 4 (210 x 297 mm)', Information);
- TextOut (DC, 10, 90, DestStr, StrLen(DestStr));
-
- Information[0] := DeviceModePtr^.dmCopies;
- WVSPrintF (DestStr, 'Anzahl der Kopien : %4u', Information);
- TextOut (DC, 10, 110, DestStr, StrLen(DestStr));
-
- Information[0] := DeviceModePtr^.dmDefaultSource;
- WVSPrintF (DestStr, 'eingestellter Papierschacht : %4u = dmBin_Upper', Information);
- TextOut (DC, 10, 130, DestStr, StrLen(DestStr));
-
- Information[0] := DeviceModePtr^.dmPrintQuality;
- WVSPrintF (DestStr, 'DruckqualitΣt : %4i = dmRes_High', Information);
- TextOut (DC, 10, 150, DestStr, StrLen(DestStr));
-
- ReleaseDC (HWindow, DC);
- FreeLibrary (PrinterLibHandle);
- END;
- END;
-
- PROCEDURE TMyWindow.GetDevCaps (VAR Msg: TMessage);
- VAR
- PrtDC, ScrDC: HDC;
- DestStr: ARRAY [0..79] OF CHAR;
- Information: ARRAY [0..1] OF WORD;
- BEGIN
- PrtDC := GetPrinterDC;
- ScrDC := GetDC (HWindow);
- Information[0] := Hi(GetDeviceCaps (PrtDC, DriverVersion));
- Information[1] := Lo(GetDeviceCaps (PrtDC, DriverVersion));
- WVSPrintF (DestStr, 'Treiberversion : %2x.%2x', Information);
- TextOut (ScrDC, 10, 10, DestStr, StrLen(DestStr));
-
- Information[0] := GetDeviceCaps (PrtDC, Technology);
- WVSPrintF (DestStr, 'Druckertechnologie : %4u', Information);
- TextOut (ScrDC, 10, 30, DestStr, StrLen(DestStr));
-
- Information[0] := GetDeviceCaps (PrtDC, HorzRes);
- Information[1] := GetDeviceCaps (PrtDC, VertRes);
- WVSPrintF (DestStr, 'Aufl÷sung in Pixel : %4u x %4u', Information);
- TextOut (ScrDC, 10, 50, DestStr, StrLen(DestStr));
-
- Information[0] := GetDeviceCaps (PrtDC, HorzSize);
- Information[1] := GetDeviceCaps (PrtDC, VertSize);
- WVSPrintF (DestStr, 'Aufl÷sung in mm : %4u x %4u', Information);
- TextOut (ScrDC, 10, 70, DestStr, StrLen(DestStr));
-
- Information[0] := GetDeviceCaps (PrtDC, LogPixelsX);
- Information[1] := GetDeviceCaps (PrtDC, LogPixelsY);
- WVSPrintF (DestStr, 'Pixel pro Zoll : %4u x %4u', Information);
- TextOut (ScrDC, 10, 90, DestStr, StrLen(DestStr));
-
- Information[0] := GetDeviceCaps (PrtDC, NumColors);
- WVSPrintF (DestStr, 'Farbaufl÷sung des GerΣtes : %4u', Information);
- TextOut (ScrDC, 10, 110, DestStr, StrLen(DestStr));
-
- Information[0] := GetDeviceCaps (PrtDC, NumFonts);
- WVSPrintF (DestStr, 'Anzahl der Schriften : %4u', Information);
- TextOut (ScrDC, 10, 130, DestStr, StrLen(DestStr));
-
- Information[0] := GetDeviceCaps (PrtDC, RasterCaps);
- WVSPrintF (DestStr, 'RasterfΣhigkeiten : %4u', Information);
- TextOut (ScrDC, 10, 150, DestStr, StrLen(DestStr));
-
- Information[0] := GetDeviceCaps (PrtDC, TextCaps);
- WVSPrintF (DestStr, 'TextdarstellungsfΣhigkeiten : %4u', Information);
- TextOut (ScrDC, 10, 170, DestStr, StrLen(DestStr));
-
- ReleaseDC (HWindow, ScrDC);
- DeleteDC (PrtDC);
- END;
-
- PROCEDURE TMyWindow.LoadABitmap (VAR Msg: TMessage);
- VAR
- MemDC, ScreenDC: HDC;
- Bitmap: TBitmap;
- OldBitmap, NewBitmap: HBitmap;
- BEGIN
- ScreenDC := GetDC (HWindow);
- MemDC := CreateCompatibleDC (ScreenDC);
- NewBitmap := LoadBitmap (HInstance, 'Blaise');
- OldBitmap := SelectObject (MemDC, NewBitmap);
- GetObject (NewBitmap, SizeOf (TBitmap), @Bitmap);
- BitBlt (ScreenDC, 0, 0, Bitmap.bmWidth, Bitmap.bmHeight, MemDC, 0, 0, SRCCopy);
- DeleteDC (MemDC);
- ReleaseDC (HWindow, ScreenDC);
- DeleteObject (NewBitmap);
- END;
-
- PROCEDURE TMyWindow.PrintBitmap (VAR Msg: TMessage);
- VAR
- MemDC, ScreenDC, PrtDC: HDC;
- OldBitmap, NewBitmap: HBitmap;
- Bitmap: TBitmap;
- JobName: PChar;
- BEGIN
- ScreenDC := GetDC (HWindow);
- MemDC := CreateCompatibleDC (ScreenDC);
- ReleaseDC (HWindow, ScreenDC);
-
- NewBitmap := LoadBitmap (HInstance, 'Blaise');
- GetObject (NewBitmap, SizeOf (TBitmap), @Bitmap);
- OldBitmap := SelectObject (MemDC, NewBitmap);
-
- PrtDC := GetPrinterDC;
- IF (PrtDC <> 0) THEN BEGIN
- GetMem (JobName, 8);
- StrPCopy (JobName, 'Blaise');
- Escape (PrtDC, StartDoc, 7, JobName, NIL);
- BitBlt (PrtDC, 10, 30, Bitmap.bmWidth, Bitmap.bmHeight,
- MemDC, 0, 0, SRCCopy);
- Escape (PrtDC, NewFrame, 0, NIL, NIL);
- Escape (PrtDC, EndDoc, 0, NIL, NIL);
- DeleteDC (PrtDC);
- MessageBox (HWindow, 'Druckauftrag abgeschickt', 'Information', mb_Ok);
- END;
- SelectObject (MemDC, OldBitmap);
- DeleteDC (MemDC);
- DeleteObject (NewBitmap);
- END;
-
- PROCEDURE TMyApplication.InitMainWindow;
- BEGIN
- MainWindow := New (PMyWindow, Init(NIL, 'Drucken in Windows'));
- END;
-
- VAR
- GenericApp: TMyApplication;
-
- BEGIN
- GenericApp.Init ('GenericApp');
- GenericApp.Run;
- GenericApp.Done;
- END.