delphi - 如何调用打印机的驱动程序设置对话框
问题描述
我正在构建自己的对话框,而不是使用标准的 PrintDialog。
我希望能够调用打印机驱动程序自己的设置对话框,即好像有人单击了 PrintDialog 中的属性按钮。
你能建议一种方法吗?
解决方案
我以前没有使用过这个 API,但在我看来你可以使用这个DocumentProperties
函数。
一个最小的例子(使用默认打印机):
var
PrinterName: string;
BufLen: Cardinal;
PrinterHandle: THandle;
begin
GetDefaultPrinter(nil, @BufLen);
SetLength(PrinterName, BufLen);
GetDefaultPrinter(PChar(PrinterName), @BufLen);
SetLength(PrinterName, BufLen - 1);
if not OpenPrinter(PChar(PrinterName), PrinterHandle, nil) then
begin
ShowMessage('Could not open printer.');
Exit;
end;
try
DocumentProperties(Handle, PrinterHandle, PChar(PrinterName), nil, nil, DM_IN_PROMPT)
// possibly do other things that might raise an exception
finally
ClosePrinter(PrinterHandle);
end;
如果您还添加了相应的标志,则可以将nil
指针替换为DEVMODE
包含初始设置和用户在 GUI 中选择的设置的结构。有关详细信息,请参阅文档。
推荐阅读
- angular - Angular SyntaxError:输入意外结束
- c# - 在 C# asp.net core 2.1 中通过用户名和密码在 MQTT 服务器上对 MQTT 客户端进行身份验证
- excel - 数据输入表上的强制性字段检查
- javascript - 编写此代码的更简洁的方法[限制字符]
- javascript - 图像 (SandTimer) 动画 - HTML、CSS、Javascript
- c++ - C++ 标准是否允许未初始化的 bool 使程序崩溃?
- python - 当表格单元格为混合格式时,抓取维基百科信息框
- css - Safari 手机上的 React 应用程序扩展超过 100%
- python - 有什么方法可以在不使用 Python 中的任何字符串或数字的情况下打印一些东西?
- python - 秩 0 张量的输入层初始化 Keras