Einzelnen Beitrag anzeigen

r29d43

Registriert seit: 18. Jan 2007
289 Beiträge
 
Delphi 10.4 Sydney
 
#7

Re: Drucken mittels des PrintDlgEx-Dialogs

  Alt 23. Nov 2008, 15:26
Also, habe es jetzt doch mal versucht, die Funktion selbst zu definieren. Leider aber gibt's bei der Zeile des eigentlichen Funktionsaufrufes dann eine Exception. Hier erstmal der bis dahin nötige Code:

Delphi-Quellcode:
const
  PD_ALLPAGES = $00000000;
  PD_SELECTION = $00000001;
  PD_PAGENUMS = $00000002;
  PD_NOSELECTION = $00000004;
  PD_NOPAGENUMS = $00000008;
  PD_COLLATE = $00000010;
  PD_PRINTTOFILE = $00000020;
  PD_PRINTSETUP = $00000040;
  PD_NOWARNING = $00000080;
  PD_RETURNDC = $00000100;
  PD_RETURNIC = $00000200;
  PD_RETURNDEFAULT = $00000400;
  PD_SHOWHELP = $00000800;
  PD_ENABLEPRINTHOOK = $00001000;
  PD_ENABLESETUPHOOK = $00002000;
  PD_ENABLEPRINTTEMPLATE = $00004000;
  PD_ENABLESETUPTEMPLATE = $00008000;
  PD_ENABLEPRINTTEMPLATEHANDLE = $00010000;
  PD_ENABLESETUPTEMPLATEHANDLE = $00020000;
  PD_USEDEVMODECOPIES = $00040000;
  PD_USEDEVMODECOPIESANDCOLLATE = $00040000;
  PD_DISABLEPRINTTOFILE = $00080000;
  PD_HIDEPRINTTOFILE = $00100000;
  PD_NONETWORKBUTTON = $00200000;
  PD_CURRENTPAGE = $00400000;
  PD_NOCURRENTPAGE = $00800000;
  PD_EXCLUSIONFLAGS = $01000000;
  PD_USELARGETEMPLATE = $10000000;

type
  TPrintDlgEx = record
    lStructSize : Cardinal;
    hWndOwner : HWnd;
    hDevMode : Cardinal;
    hDevNames : Cardinal;
    hDC : HDC;
    Flags : Cardinal;
    Flags2 : Cardinal;
    ExclusionFlags : Cardinal;
    nPageRanges : Word;
    nMaxPageRanges : Word;
    lpPageRanges : Pointer;
    nMinPage : Word;
    nMaxPage : Word;
    nCopies : Word;
    hInstance : Cardinal;
    lpPrintTemplateName : PAnsiChar;
    lpCallback : Pointer;
    nPropertyPages : Cardinal;
    lphPropertyPages : Cardinal;
    nStartPage : Cardinal;
    dwResultAction : Cardinal;
  end;

type TPrintDlgExFunc = function (Pdex : TPrintDlgEx): DWord; stdcall;


procedure TForm1.Button1Click(Sender: TObject);
var hComDlg32 : THandle;
    PrintDlgEx : TPrintDlgExFunc;
    pdex : TPrintDlgEx;
begin

  hComDlg32 := LoadLibrary('comdlg32.dll');
  if hComDlg32 <> 0 then begin
    @PrintDlgEx := GetProcAddress(hComDlg32,'PrintDlgExA');
    if Assigned(PrintDlgEx) then begin


        ZeroMemory(@pdex, sizeof(TPrintDlgEx));
        pdex.lStructSize := sizeof(TPrintDlgEx);
        pdex.hWndOwner := Handle;
        pdex.Flags := PD_ALLPAGES
                            or PD_NOPAGENUMS
        ;
        pdex.nCopies := 1;

        PrintDlgEx (pdex); // <--- Exception hier!!!
    end;
    FreeLibrary(hComDlg32);
  end;

end;

Event. sieht ja irgendjemand, wo da ein Fehler sein könnte
  Mit Zitat antworten Zitat