home *** CD-ROM | disk | FTP | other *** search
- PROGRAM MyPrint;
-
- {$R MYPRINT}
- {$X+}
-
- USES WinTypes, WinProcs, OWindows, ODialogs, Strings, WinDos;
-
- CONST
- { Command ID }
- cm_About = 100;
- cm_ExtDevMode = 111;
- cm_DevCaps = 112;
- cm_GetDevCap = 113;
- cm_ShowPrinter = 114;
- cm_DeviceMode = 115;
-
- cm_LoadBitmap = 201;
- cm_PrintBitmap = 202;
-
- id_ListBox = 101;
-
- TYPE
- pSetupDialog = ^tSetupDialog;
- tSetupDialog = OBJECT (tDialog)
- Auswahl: pChar;
- CONSTRUCTOR Init (aParent: pWindowsObject; aName: pChar; STD: pChar);
- PROCEDURE SetupWindow; VIRTUAL;
- 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 + cm_About;
- PROCEDURE DevCaps (VAR Msg: tMessage); VIRTUAL cm_First + cm_DevCaps;
- PROCEDURE GetDevCaps (VAR Msg: tMessage); VIRTUAL cm_First + cm_GetDevCap;
- PROCEDURE Options (VAR Msg: tMessage); VIRTUAL cm_First + cm_ExtDevMode;
- PROCEDURE Options2 (VAR Msg: tMessage); VIRTUAL cm_First + cm_DeviceMode;
-
- PROCEDURE LoadABitmap (VAR Msg: tMessage); VIRTUAL cm_First + cm_LoadBitmap;
- PROCEDURE PrintBitmap (VAR Msg: tMessage); VIRTUAL cm_First + cm_PrintBitmap;
- PROCEDURE ShowPrinter (VAR Msg: tMessage); VIRTUAL cm_First + cm_ShowPrinter;
- END;
-
- tMyApplication = OBJECT (tApplication)
- PROCEDURE InitMainWindow; VIRTUAL;
- END;
-
- pChar39 = ARRAY [0..39] OF CHAR;
-
- VAR
- DruckerName, TreiberName, DruckerPort: pChar39;
- DeviceMode: tDevMode;
-
-
- (**********************************************************************************)
-
- TYPE
- pAbortDlg = ^tAbortDlg;
- tAbortDlg = OBJECT (tDialog)
- PROCEDURE SetupWindow; VIRTUAL;
- PROCEDURE wmCommand(VAR Msg: tMessage); VIRTUAL wm_First + wm_Command;
- END;
-
- VAR
- Abort: BOOLEAN;
- AbortWindow: hWND;
-
- PROCEDURE tAbortDlg.SetupWindow;
- BEGIN
- Abort:= FALSE;
- SetFocus(hWindow);
- AbortWindow:= hWindow;
- END;
-
- PROCEDURE tAbortDlg.wmCommand(VAR Msg: tMessage);
- BEGIN
- Abort:= TRUE;
- END;
-
- FUNCTION AbortProc(DC: hDC; Code: INTEGER): Bool; EXPORT;
- VAR
- Msg: tMsg;
- BEGIN
- WHILE (NOT Abort) AND PeekMessage(Msg, 0, 0, 0, pm_Remove) DO
- IF NOT IsDialogMessage(AbortWindow, Msg) THEN
- BEGIN
- TranslateMessage(Msg);
- DispatchMessage(Msg);
- END;
- IF Abort THEN AbortProc:= FALSE ELSE AbortProc:= TRUE;
- 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;
-
- (**************************** TSetupDlg *******************************************)
- {- Return pointer to next token in P or previous P if P = nil }
- FUNCTION NextToken(P: pChar; C: CHAR): pChar;
- CONST
- Next: pChar = NIL;
- BEGIN
- IF P = NIL THEN P := Next;
- Next := StrScan(P, C);
- IF Next <> NIL THEN
- BEGIN
- Next^ := #0;
- Next := @Next[1]
- END;
- NextToken := P
- END;
-
- CONSTRUCTOR tSetupDialog.Init (aParent: pWindowsObject; aName: pChar; STD: pChar);
- BEGIN
- tDialog.Init (aParent, aName);
- Auswahl := STD;
- END;
-
- PROCEDURE tSetupDialog.SetupWindow;
- VAR
- i: INTEGER;
- P: pChar;
- Buffer: ARRAY [0..4096] OF CHAR;
- BEGIN
- GetProfileString ('devices', NIL, #0'', Buffer, SizeOf(Buffer));
- i := 0;
- P := NextToken (Buffer, #0);
- WHILE (StrLen(P) <> 0) DO
- BEGIN
- SendDlgItemMsg (id_ListBox, lb_AddString, 0, LONGINT(P));
- IF (StrComp(Auswahl, P) = 0) THEN
- SendDlgItemMsg (id_ListBox, lb_SetCurSel, i, 0);
- P := NextToken (NIL, #0);
- Inc(i);
- END;
- END;
-
- (************************** TMyWindow *********************************************)
- CONSTRUCTOR tMyWindow.Init (aParent: pWindowsObject; aTitle: pChar);
- BEGIN
- tWindow.Init (aParent, aTitle);
- Attr.Menu := LoadMenu(hInstance, 'PrtMenu');
- Attr.w := 550;
- Attr.h := 400;
- 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.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.Options2 (VAR Msg: tMessage);
- VAR
- PrinterLibHandle: tHandle;
- DriverFileName: pChar39;
- ProcAddress: tFarProc;
- BEGIN
- CallMeNames;
- DriverFileName := TreiberName;
- StrCat (DriverFileName, '.DRV');
- PrinterLibHandle := LoadLibrary (DriverFileName);
- ProcAddress := GetProcAddress(PrinterLibHandle, 'DEVICEMODE');
- IF (ProcAddress <> NIL)
- THEN tDeviceMode(ProcAddress) (Application^.MainWindow^.hWindow,
- PrinterLibHandle, DriverFileName, DruckerPort);
- 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;
- (* normalerweise sollte das Minuszeichen nicht notwendig sein! *)
- (* Aber es geht wirklich nicht ohne...! *)
- 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;
- AbortDlg: pAbortDlg;
- AbortCallBack: tFarProc;
- EscapErr: INTEGER;
- 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');
- MessageBox (hWindow, 'Ab mit der Abort-Box','Information',mb_OK);
- New (AbortDlg, Init(Application^.MainWindow, 'ABORTBOX'));
- AbortDlg^.Create;
- AbortCallBack := MakeProcInstance(@AbortProc, hInstance);
-
- EscapErr := Escape(PrtDC, SetAbortProc, 0, AbortCallBack, NIL);
- Escape (PrtDC, StartDoc, StrLen(JobName), 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);
- AbortDlg^.CloseWindow;
- MessageBox (hWindow, 'Druckauftrag abgeschickt', 'Information', mb_OK);
- END;
- SelectObject (MemDC, OldBitmap);
- DeleteDC (MemDC);
- DeleteObject (NewBitmap);
- END;
-
- PROCEDURE tMyWindow.ShowPrinter (VAR Msg: tMessage);
- BEGIN
- CallMeNames;
- Application^.ExecDialog (New(pSetupDialog,
- Init(@Self, 'SetupDlg', DruckerName)));
- 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.
-