自己想做一个打印设置窗口
不知道如何获得以下信息打印机纸张类型打印方向确定后如何让这些选择生效?
多谢各位了!

解决方案 »

  1.   

    翻翻PrinterSetupDialog的源代码就知道了。
      

  2.   

    function TPrinterSetupDialog.Execute: Boolean;
    var
      PrintDlgRec: TPrintDlg;
      DevHandle: THandle;
    begin
      FillChar(PrintDlgRec, SizeOf(PrintDlgRec), 0);
      with PrintDlgRec do
      begin
        lStructSize := SizeOf(PrintDlgRec);
        hInstance := SysInit.HInstance;
        GetPrinter(DevHandle, hDevNames);
        hDevMode := CopyData(DevHandle);
        Flags := PD_ENABLESETUPHOOK or PD_PRINTSETUP;
        lpfnSetupHook := DialogHook;
        hWndOwner := Application.Handle;
        Result := TaskModalDialog(@PrintDlg, PrintDlgRec);
        if Result then
          SetPrinter(hDevMode, hDevNames)
        else begin
          if hDevMode <> 0 then GlobalFree(hDevMode);
          if hDevNames <> 0 then GlobalFree(hDevNames);
        end;
      end;
    end;{ TPrintDialog }procedure TPrintDialog.SetNumCopies(Value: Integer);
    begin
      FCopies := Value;
      Printer.Copies := Value;
    end;function TPrintDialog.Execute: Boolean;
    const
      PrintRanges: array[TPrintRange] of Integer =
        (PD_ALLPAGES, PD_SELECTION, PD_PAGENUMS);
    var
      PrintDlgRec: TPrintDlg;
      DevHandle: THandle;
    begin
      FillChar(PrintDlgRec, SizeOf(PrintDlgRec), 0);
      with PrintDlgRec do
      begin
        lStructSize := SizeOf(PrintDlgRec);
        hInstance := SysInit.HInstance;
        GetPrinter(DevHandle, hDevNames);
        hDevMode := CopyData(DevHandle);
        Flags := PrintRanges[FPrintRange] or (PD_ENABLEPRINTHOOK or
          PD_ENABLESETUPHOOK);
        if FCollate then Inc(Flags, PD_COLLATE);
        if not (poPrintToFile in FOptions) then Inc(Flags, PD_HIDEPRINTTOFILE);
        if not (poPageNums in FOptions) then Inc(Flags, PD_NOPAGENUMS);
        if not (poSelection in FOptions) then Inc(Flags, PD_NOSELECTION);
        if poDisablePrintToFile in FOptions then Inc(Flags, PD_DISABLEPRINTTOFILE);
        if FPrintToFile then Inc(Flags, PD_PRINTTOFILE);
        if poHelp in FOptions then Inc(Flags, PD_SHOWHELP);
        if not (poWarning in FOptions) then Inc(Flags, PD_NOWARNING);
        nFromPage := FFromPage;
        nToPage := FToPage;
        nMinPage := FMinPage;
        nMaxPage := FMaxPage;
        lpfnPrintHook := DialogHook;
        lpfnSetupHook := DialogHook;
        hWndOwner := Application.Handle;
        Result := TaskModalDialog(@PrintDlg, PrintDlgRec);
        if Result then
        begin
          SetPrinter(hDevMode, hDevNames);
          FCollate := Flags and PD_COLLATE <> 0;
          FPrintToFile := Flags and PD_PRINTTOFILE <> 0;
          if Flags and PD_SELECTION <> 0 then FPrintRange := prSelection else
            if Flags and PD_PAGENUMS <> 0 then FPrintRange := prPageNums else
              FPrintRange := prAllPages;
          FFromPage := nFromPage;
          FToPage := nToPage;
          if nCopies = 1 then
            Copies := Printer.Copies else
            Copies := nCopies;
        end
        else begin
          if hDevMode <> 0 then GlobalFree(hDevMode);
          if hDevNames <> 0 then GlobalFree(hDevNames);
        end;
      end;
    end;