Announcement

Collapse
No announcement yet.

DeviceCapabilities

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • DeviceCapabilities

    An Andreas Kosch: Sie haben gezeigt, wie man die WIN32API-Funktion DeviceCapabilities richtig anwendet ( Schacht, Papiergröße,...). Meine Frage und Bitte: wie verwendet man DeviceCapabilities mit dem Parameter DC_MINEXTENT und DC_MAXEXTENT um richtige Wertpaare zu erhalten?

    In der Hoffnung auf eine Antwort MFG aus Südtirol Johann Steiner

  • #2
    Hallo,

    von <i>Joe C. Hecht</i> (Borland) stammt das folgende Beispiel für Delphi 3, das ich selbst jedoch noch nicht ausprobiert habe:

    If you are in 32 bit land, you can try using the DC_MINEXTENT flag. Some printers might not support it.
    <pre>
    procedure TForm1.Button1Click(Sender: TObject);
    var
    Device : array[0..255] of char;
    Driver : array[0..255] of char;
    Port : array[0..255] of char;
    hDMode : THandle;
    PDMode : PDEVMODE;
    begin
    Printer.PrinterIndex := Printer.PrinterIndex;
    Printer.GetPrinter(Device, Driver, Port, hDMode);
    if hDMode <> 0 then begin
    pDMode := GlobalLock(hDMode);
    if pDMode <> nil then begin

    {Set to legal}
    pDMode^.dmFields := pDMode^.dmFields or dm_PaperSize;
    pDMode^.dmPaperSize := DMPAPER_LEGAL;

    {Set to custom size}
    pDMode^.dmFields := pDMode^.dmFields or
    DM_PAPERSIZE or
    DM_PAPERWIDTH or
    DM_PAPERLENGTH;
    pDMode^.dmPaperSize := DMPAPER_USER;
    pDMode^.dmPaperWidth := 100 {SomeValueInTenthsOfAMillimeter};
    pDMode^.dmPaperLength := 100 {SomeValueInTenthsOfAMillimeter};

    {Set the bin to use}
    pDMode^.dmFields := pDMode^.dmFields or DMBIN_MANUAL;
    pDMode^.dmDefaultSource := DMBIN_MANUAL;

    GlobalUnlock(hDMode);
    end;
    end;
    Printer.PrinterIndex := Printer.PrinterIndex;
    Printer.BeginDoc;
    Printer.Canvas.TextOut(100,100, 'Test 1');
    Printer.EndDoc;
    end;

    Q) How can I call the DeviceCapabilities functions without getting an
    application error?

    A) The prototypes for the DeviceCapabilities() function where
    incorrectly
    documented in Delphi 2.0. The following is an example of the correct
    method of calling the function. The example returns the bin names of
    the given printer.

    Example:

    const cchBinName = 24;

    function DeviceCapabilitiesA(pDevice : PAnsiChar;
    pPort : PAnsiChar;
    fwCapability : Word;
    pOutput : PAnsiChar;
    DevMode : PDeviceModeA): Integer; stdcall;
    stdcall; external 'winspool.drv' name 'DeviceCapabilitiesA';

    function DeviceCapabilitiesW(pDevice : PWideChar;
    pPort : PWideChar;
    fwCapability: Word;
    pOutput: PWideChar;
    DevMode: PDeviceModeW): Integer; stdcall;
    stdcall; external 'winspool.drv' name 'DeviceCapabilitiesW';

    function DeviceCapabilities(pDevice : PChar;
    pPort : PChar;
    fwCapability : Word;
    pOutput : PChar;
    DevMode: PDeviceMode): Integer;
    stdcall; external 'winspool.drv' name 'DeviceCapabilitiesA';

    procedure TForm1.Button1Click(Sender: TObject);
    var
    NumBins : integer;
    i : integer;
    p : pChar;
    pNames : pChar;
    begin
    NumBins := DeviceCapabilities('HP LaserJet Series II',
    'LPT1',
    DC_BINNAMES,
    nil,
    nil);
    if NumBins > 0 then begin
    GetMem(p, NumBins * cchBinName);
    DeviceCapabilities('HP LaserJet Series II',
    'LPT1',
    DC_BINNAMES,
    p,
    nil);
    PNames := p;
    for i := 0 to (NumBins - 1) do begin
    Memo1.Lines.Add(PNames);
    pNames := @pNames[i * cchBinName]
    end;
    FreeMem(p, NumBins * cchBinName);
    end;
    end;

    end.
    </pre&gt

    Comment


    • #3
      Hallo,

      das Problem mit DC_MINEXTENT liegt darin, dass nicht alle Druckertreiber diese Daten liefern

      Comment


      • #4
        Danke A. Kosch für die Antwort.
        Wenn ich die Papierformate (DC_PAPERNAMES) aufliste, kann ich sehen, ob ein "User defined" oder "Benutzerdefiniert" dabei ist und trotzdem erhalte ich keine brauchbaren Rückgabewerte, vor allem nicht unter W2K.
        Wenn also ein Druckertreiber die Daten liefern kann, wie muss ich es dann machen?

        MFG Johann Steine

        Comment

        Working...
        X