如题:
假改系统有2个打印机: 1.canon 4650  (默认)
                      2.hp 1010 
现在想把默认打印机改为第二个,该怎么做?   又如何改变系统中指定打印机的默认参数?即改变HP1010的默认纸张大小。小弟先谢了

解决方案 »

  1.   

    Uses
      Printersbegin
      ComboBox1.Clear;
      ComboBox1.Items:=printer.Printers;
      QuickRep1.PrinterSettings.PrinterIndex:=ComboBox1.ItemIndex;//设置打印机
    end;
      

  2.   

    在打印前调用以下函数
    procedure SetPaperSize(X, Y: Integer);
    // 这段代码绝对可用。单位是0.1mm
    // A4时 Printer.Pagewidth:=1440;  A5时 Printer.Pagewidth:=1049;
    // B5时 Printer.Pagewidth:=1290;  16K时 Printer.Pagewidth:=1035;
    // lq1600宽行打印机这个值宽度最大为42cm左右, 长度大约2m。
    {Question:
    How can I change the papersize of my print job?
    Answer:
    One way to change printer settings at the start
    of a print job is to change the printer's devicemode
    structure.
    See: TDEVMODE in the Delphi 1.02 help file or DEVMODE
    in the Delphi 2.01 help file for other settings you can
    change (providing the print driver supports the change).
    The following example, contains code to change the papersize and
    the paper bin that is uses:}
    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
          if (x = 0) or (y = 0) then
          begin
            {Set to legal}
            pDMode^.dmFields := pDMode^.dmFields or dm_PaperSize;
            {pDMode^.dmPaperSize := DMPAPER_LEGAL; changed by wulianmin}
            pDMode^.dmPaperSize := DMPAPER_FANFOLD_US;
          end
          else
          begin
            {Set to custom size}
            pDMode^.dmFields := pDMode^.dmFields or
              DM_PAPERSIZE or
              DM_PAPERWIDTH or
              DM_PAPERLENGTH;
            pDMode^.dmPaperSize := DMPAPER_USER;
            pDMode^.dmPaperWidth := x {SomeValueInTenthsOfAMillimeter};
            pDMode^.dmPaperLength := y {SomeValueInTenthsOfAMillimeter};
          end;
          {Set the bin to use}
          pDMode^.dmFields := pDMode^.dmFields or DMBIN_MANUAL;
          pDMode^.dmDefaultSource := DMBIN_MANUAL;      GlobalUnlock(hDMode);
        end;
      end;
      Printer.PrinterIndex := Printer.PrinterIndex;
      //以下开始打印
    end;
      

  3.   

    两位朋友误解了,我意思是:直接用程序修改Windows中的默认打印机。让控制面板中的默认打印机由A改成B。该怎么做呢、???
      

  4.   

    To: // 这段代码绝对可用。单位是0.1mm
    // A4时 Printer.Pagewidth:=1440;  A5时 Printer.Pagewidth:=1049;
    // B5时 Printer.Pagewidth:=1290;  16K时 Printer.Pagewidth:=1035;
    // lq1600宽行打印机这个值宽度最大为42cm左右, 长度大约2m。A4不是2100 * 2970 吗??? 怎么A4,B4,A5等与实际纸张尺寸不一样???
      

  5.   

    使用QR的时候,如果系统有多台打印机,如果要使用某台指定的打印机的话,QR却把所有的打印人物都发送到默认的打印机上面去了,那么如何发送到指定的打印机呢?可以这样,直接指定输出打印机就可以了:Printer.PrinterIndex:=0; ///指定第一台打印机为输出设备Printer.PinnterIndex:=-1; ///默认打印机为输出设备
      

  6.   


    动态改变Windows的默认打印机
    在窗体中加入combobox和两个button
    procedure TForm1.Button1Click(Sender: TObject);
    begin
      ComboBox1.Items := Printer.Printers; {populates ComboBox}
      ComboBox1.ItemIndex := Printer.PrinterIndex; {sets display to current printer}
    end;procedure TForm1.Button2Click(Sender: TObject);
    var
      Device: array[0..255] of Char;
      Driver: array[0..255] of char;
      Port: array[0..255] of char;
      s : array[0..255] of Char;
      hDeviceMode: THandle;begin  Printer.PrinterIndex := ComboBox1.ItemIndex;
      Printer.GetPrinter (Device, Driver, Port, hDeviceMode);
      StrCopy (s, Device);
      StrCat (s, ',');
      StrCat (s, Driver);
      StrCat (s, ',');
      StrCat (s, Port);
      WriteProfileString ('windows', 'device', s);
      StrCopy (s, 'windows');
      SendMessage (HWND_BROADCAST, WM_WININICHANGE, 0, LongInt(@s));end;