1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33: 34: 35: 36: 37: 38: 39: 40: 41: 42: 43: 44: 45: 46: 47: 48: 49: 50: 51: 52: 53: 54: 55: 56: 57: 58: 59: 60: 61: 62: 63: 64: 65: 66: 67: 68: 69: 70: 71: 72: 73: 74: 75: 76: 77: 78: 79: 80: 81: 82: 83: 84: 85: 86: 87: 88: 89: 90: 91: 92: 93: 94: 95: 96: 97: 98: 99: 100: 101: 102: 103: 104: 105: 106: 107: 108: 109: 110: 111: 112: 113: 114: 115: 116: 117: 118: 119: 120: 121: 122: 123: 124: 125: 126: 127: 128: 129: 130: 131: 132: 133: 134: 135: 136: 137: 138: 139: 140: 141: 142: 143: 144: 145: 146: 147: 148: 149: 150: 151: 152:
| unit MAIN;
interface
uses Windows, SysUtils, Printers, Winspool, Classes, Graphics, Forms, Controls, Menus, StdCtrls, Dialogs, Buttons, Messages, ExtCtrls, ComCtrls, StdActns, ActnList, ToolWin, ImgList;
type TMainForm = class(TForm) MainMenu1: TMainMenu; File1: TMenuItem; Help1: TMenuItem; FileExitItem: TMenuItem; HelpAboutItem: TMenuItem; OpenDialog: TOpenDialog; StatusBar: TStatusBar; ActionList1: TActionList; EditCut1: TEditCut; EditCopy1: TEditCopy; EditPaste1: TEditPaste; FileNew1: TAction; FileSave1: TAction; FileExit1: TAction; FileOpen1: TAction; FileSaveAs1: TAction; WindowCascade1: TWindowCascade; WindowTileHorizontal1: TWindowTileHorizontal; WindowArrangeAll1: TWindowArrange; WindowMinimizeAll1: TWindowMinimizeAll; HelpAbout1: TAction; FileClose1: TWindowClose; WindowTileVertical1: TWindowTileVertical; ToolBar2: TToolBar; ToolButton1: TToolButton; ToolButton2: TToolButton; ToolButton3: TToolButton; ToolButton4: TToolButton; ToolButton5: TToolButton; ToolButton6: TToolButton; ToolButton9: TToolButton; ToolButton7: TToolButton; ToolButton8: TToolButton; ToolButton10: TToolButton; ToolButton11: TToolButton; ImageList1: TImageList; Memo1: TMemo; Button1: TButton; SaveDialog1: TSaveDialog; procedure Button1Click(Sender: TObject); procedure FileNew1Execute(Sender: TObject); procedure FileOpen1Execute(Sender: TObject); procedure HelpAbout1Execute(Sender: TObject); procedure FileExit1Execute(Sender: TObject); private procedure CreateMDIChild(const Name: string); public end;
var MainForm: TMainForm;
implementation
{$R *.dfm}
uses CHILDWIN, about;
procedure TMainForm.CreateMDIChild(const Name: string); var Child: TMDIChild; begin Child := TMDIChild.Create(Application); Child.Caption := Name; if FileExists(Name) then Child.Memo1.Lines.LoadFromFile(Name); end;
procedure TMainForm.FileNew1Execute(Sender: TObject); begin CreateMDIChild('NONAME' + IntToStr(MDIChildCount + 1)); end;
procedure TMainForm.FileOpen1Execute(Sender: TObject); begin if OpenDialog.Execute then CreateMDIChild(OpenDialog.FileName); end;
procedure TMainForm.HelpAbout1Execute(Sender: TObject); begin AboutBox.ShowModal; end;
procedure TMainForm.FileExit1Execute(Sender: TObject); begin Close; end; function GetCurrentPrinterHandle: THandle; var Device, Driver, Port: array[0..255] of Char; hDeviceMode: THandle; begin Printer.GetPrinter(Device, Driver, Port, hDeviceMode); if not OpenPrinter(@Device, Result, nil) then RaiseLastWin32Error; end;
function SavePChar(p: PChar): PChar; const error: PChar = 'Nil'; begin if not Assigned(p) then Result := error else Result := p; end;
procedure TMainform.Button1Click(Sender: TObject); type TJobs = array [0..1000] of JOB_INFO_1; PJobs = ^TJobs; var hPrinter: THandle; bytesNeeded, numJobs, i: Cardinal; pJ: PJobs; begin hPrinter := GetCurrentPrinterHandle; try EnumJobs(hPrinter, 0, 1000, 1, nil, 0, bytesNeeded, numJobs); pJ := AllocMem(bytesNeeded); if not EnumJobs(hPrinter, 0, 1000, 1, pJ, bytesNeeded, bytesNeeded, numJobs) then RaiseLastWin32Error;
memo1.Clear; if numJobs = 0 then memo1.Lines.Add('No jobs in queue') else for i := 0 to Pred(numJobs) do memo1.Lines.Add(Format('Dokument %s, Status (%d): %s, Benutzer: %s, Seiten: %d', [SavePChar(pJ^[i].pDocument), pJ^[i].Status, SavePChar(pJ^[i].pStatus),SavePChar(pJ^[i].pUserName),pJ^[i].TotalPages])); memo1.lines.SaveToFile('C:\princost.log'); finally ClosePrinter(hPrinter); end; end; end. |