• (转)设置默认打印机


    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;

  • 相关阅读:
    并发编程 ~~~ 多进程~~~进程创建的两种方式, 进程pid, 验证进程之间的空间隔离, 进程对象join方法, 进程对象其他属性
    并发编程 ~~~ 多进程
    网络编程~~~~socketserver服务端
    网络编程~~~~粘包
    聊聊主流加密算法及该如何设计我们的用户密码
    Spring Boot Security 保护你的程序
    Spring Boot接口如何设计防篡改、防重放攻击
    Spring Boot 整合 Shiro实现认证及授权管理
    Spring Boot Quartz 分布式集群任务调度实现
    Spring Boot Redis 解析
  • 原文地址:https://www.cnblogs.com/bestlove/p/6613600.html
Copyright © 2020-2023  润新知