怎样改变windows下的默认打印机,急!!!

解决方案 »

  1.   

    procedure TForm1.Button1Click(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
      //messagebeep(2);
      beep();
      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));
      ComboBox1.Items := Printer.Printers; {populates ComboBox}
      ComboBox1.ItemIndex := Printer.PrinterIndex; 
    end;procedure TForm1.ComboBox1Change(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;
      

  2.   

    ComboBox1Change即为改变默认打印机