• (转)设置默认打印机


    type
    TForm1 = class(TForm)
    Button1: TButton;
    ComboBox1: TComboBox;
    procedure Button1Click(Sender: TObject);
    procedure FormCreate(Sender: TObject);
    private
    { Private declarations }
    public
    { Public declarations }
    end;

    {...}

    procedure TForm1.FormCreate(Sender: TObject);
    begin
    { tell printer to go to the default by setting
    the PrinterIndex value to -1 告诉打印机到默认设置
    到 printerindex=-1}
    Printer.PrinterIndex := -1;

    { make our combobox non-editable 让我们的组合框不可编辑的}
    ComboBox1.Style := csDropDownList;

    { set our combobox items to the printer printers 设置我们的组合框项显示打印机打印机}
    ComboBox1.Items := Printer.Printers;

    { set combobox to view the default printer according to printer printerindex as set above 设置组合框查看默认打印机
    根据以上printerindex设置打印机}
    ComboBox1.ItemIndex := Printer.PrinterIndex;
    end;

    procedure TForm1.Button1Click(Sender: TObject);
    var
    MyHandle : THandle;
    MyDevice,
    MyDriver,
    MyPort: array [0..255] of Char;
    begin
    { set printer to the selected according to the
    combobox itemendex 将打印机设置为根据
    组合框itemendex}
    Printer.PrinterIndex := ComboBox1.ItemIndex;

    { get our printer properties 获取打印机属性}
    Printer.GetPrinter(MyDevice,
    MyDriver,
    MyPort,
    MyHandle);

    { create string of exactly what WriteProfileString()
    wants to see by concat each of the above received
    character arrays 创建接收WriteProfileString()字符串到的字符数组 }
    StrCat( MyDevice, ',');
    StrCat( MyDevice, MyDriver );
    StrCat( MyDevice, ',');
    StrCat( MyDevice, MyPort );

    { copy our new default printer into our windows ini file
    to the [WINDOWS] section under DEVICE=
    复制我们的新默认打印机到我们的Windows INI文件到windows部分下的DEVICE}
    WriteProfileString('WINDOWS',
    'DEVICE',
    MyDevice );

    { tell all applications that the windows ini file has
    changed, this will cause them all to recheck default
    printer 告诉所有的Windows INI文件的应用程序
    改变,这将使他们所有的核对默认
    打印机}
    SendMessage(HWND_BROADCAST, WM_WININICHANGE, 0, LongInt(pChar('windows')));
    end;
    end;

  • 相关阅读:
    GL线程
    Texture,TextureRegion,Sprite,SpriteBatch
    设置壁纸
    CentOS7下安装MySQL,修改端口
    读《大道至简》有感
    课程作业01汇总整理
    读《大道至简》有感(伪代码)
    01实验性问题总结归纳
    oracle日期时间的加减法
    C# 根据年、月、周、星期获得日期等
  • 原文地址:https://www.cnblogs.com/bestlove/p/6613600.html
Copyright © 2020-2023  润新知