`
tiandirensoon
  • 浏览: 598227 次
文章分类
社区版块
存档分类
最新评论

调用API弹出打印机属性对话框

 
阅读更多

调用api弹出打印机属性对话框
Author:vitoriatang
From:Internet
.NETFramework封装了很多关于打印的对话框,比如说PrintDialog,PageSetupDialog.
但是有的时候我们还需要关心打印机属性对话框,那么就可以调用API来解决这个问题。有几个API函数与之相关
PrinterProperties
DocumentProperties
OpenPrinter
ClosePrinter
逐一介绍

printerproperties
显示打印机属性对话框。

documentproperties
显示打印机配置对话框。

openprinter
打开打印机

closeprinter
关闭打印机

在调用printerproperties或者documentproperties的时候,都需要先调用openprinter,并在结束后调用closeprinter。

至于打印机属性和打印机配置有什么不同,就自己领会了。更为详尽的信息可以查阅msdn

samplecodes:
1.声明API函数
[System.Runtime.InteropServices.DllImportAttribute("winspool.drv",SetLastError=true)]
publicexternstaticintDocumentProperties(
IntPtrhWnd,//handletoparentwindow
IntPtrhPrinter,//handletoprinterobject
stringpDeviceName,//devicename
refIntPtrpDevModeOutput,//modifieddevicemode
refIntPtrpDevModeInput,//originaldevicemode
intfMode);//modeoptions

[System.Runtime.InteropServices.DllImportAttribute("winspool.drv")]
publicstaticexternintPrinterProperties(
IntPtrhwnd,//handletoparentwindow
IntPtrhPrinter);//handletoprinterobject

[System.Runtime.InteropServices.DllImportAttribute("winspool.drv",SetLastError=true)]
publicexternstaticintOpenPrinter(
stringpPrinterName,//printername
refIntPtrhPrinter,//handletoprinterobject
refIntPtrpDefault);//handletodefaultprinterobject.

[System.Runtime.InteropServices.DllImportAttribute("winspool.drv",SetLastError=true)]
publicstaticexternintClosePrinter(
IntPtrphPrinter);//handletoprinterobject


2.调用DocumentProperties
privatevoiddocumentPropButton_Click(objectsender,EventArgse)
{
stringprinterName=_document.PrinterSettings.PrinterName;

if(printerName!=null&&printerName.Length>0)
{
IntPtrpPrinter=IntPtr.Zero;
IntPtrpDevModeOutput=IntPtr.Zero;
IntPtrpDevModeInput=IntPtr.Zero;
IntPtrnullPointer=IntPtr.Zero;

OpenPrinter(printerName,refpPrinter,refnullPointer);

intiNeeded=DocumentProperties(this.Handle,pPrinter,printerName,refpDevModeOutput,refpDevModeInput,0);
pDevModeOutput=System.Runtime.InteropServices.Marshal.AllocHGlobal(iNeeded);
DocumentProperties(this.Handle,pPrinter,printerName,refpDevModeOutput,refpDevModeInput,DM_PROMPT);
ClosePrinter(pPrinter);
}
}

3.调用PrinterProperties
privatevoidprintPropButton_Click(objectsender,EventArgse)
{
stringprinterName=_document.PrinterSettings.PrinterName;

if(printerName!=null&&printerName.Length>0)
{
IntPtrpPrinter=IntPtr.Zero;
IntPtrpDevModeOutput=IntPtr.Zero;
IntPtrpDevModeInput=IntPtr.Zero;
IntPtrnullPointer=IntPtr.Zero;

OpenPrinter(printerName,refpPrinter,refnullPointer);

intiNeeded=PrinterProperties(this.Handle,pPrinter);
ClosePrinter(pPrinter);
}


分享到:
评论

相关推荐

    Windows API函数大全

    ConnectToPrinterDlg 启动连接打印机对话框,用它同访问网络的打印机连接 DeleteForm 从打印机可用表单列表中删除一个表单 DeleteMonitor 删除指定的打印监视器 DeletePort 启动"删除端口"对话框,允许用户从当前...

    API之网络函数---整理网络函数及功能

    ConnectToPrinterDlg 启动连接打印机对话框,用它同访问网络的打印机连接 DeleteForm 从打印机可用表单列表中删除一个表单 DeleteMonitor 删除指定的打印监视器 DeletePort 启动“删除端口”对话框,允许用户从...

    Windows 程序设计(第5版)(上、下册)--详细书签版

    10.2.9 浮动弹出式菜单 10.2.10 使用系统菜单 10. 2.11更改菜单 10.2.12 其他菜单命令 10.2.13 创建菜单的非正规方法 10.3 键盘加速键 10.3.1 为什么要使用加速键 10.3.2 安排加速键的几条规则...

    易语言程序免安装版下载

    修改扩展界面支持库三,解决单击卷帘菜单后导致日期框不能弹出下拉窗口的BUG。 4. 修改XP风格支持库,解决GDI资源泄露,以及在使用通用组件库六时组合框标题出现重影的BUG。 5. 修改扩展界面支持库一,解决树形框...

    C++MFC教程

    用于弹出一个消息框 第二章 图形输出 2.1 和GUI有关的各种对象 在Windows中有各种GUI对象(不要和C++对象混淆),当你在进行绘图就需要利用这些对象。而各种对象都拥有各种属性,下面分别讲述各种GUI对象和拥有的...

    delphi 开发经验技巧宝典源码

    0223 怎样弹出ConnectionString设置页 148 0224 利用ADO获取DELETE后所影响的记录数 148 7.3 业务实现数据处理技术 149 0225 随机产生中奖号码 149 0226 使用快捷键保存数据 150 0227 密码只允许输入8位...

    delphi 开发经验技巧宝典源码06

    0223 怎样弹出ConnectionString设置页 148 0224 利用ADO获取DELETE后所影响的记录数 148 7.3 业务实现数据处理技术 149 0225 随机产生中奖号码 149 0226 使用快捷键保存数据 150 0227 密码只允许输入8位...

    DELPHI 5编程实例与技巧

    4.1.2 鼠标右键弹出式菜单 99 4.1.3 使用菜单模板 99 4.2 工具栏 100 4.2.1 ToolBar 100 4.2.2 CoolBar 100 4.2.3 ControlBar 101 4.3 状态栏 101 4.4 方法与技巧 106 4.4.1 动态创建菜单 106 4.4.2 为菜单动态定义...

    Delphi 5编程实例与技巧

    4.1.2 鼠标右键弹出式菜单 99 4.1.3 使用菜单模板 99 4.2 工具栏 100 4.2.1 ToolBar 100 4.2.2 CoolBar 100 4.2.3 ControlBar 101 4.3 状态栏 101 4.4 方法与技巧 106 4.4.1 动态创建菜单 106 4.4.2 为菜单动态定义...

    1345个易语言模块

    API 设置颜色对话框模块.ec ard.ec Arhz_自动更新.ec Base64编解码.ec BASE64编解码模块.ec Bios.ec Bios 信息.ec BMP加密数据.ec BMP滤镜模块.ec BOX.EC BPL专用更新模块.ec BPL综合模 块.ec BPL高级模块.ec ...

    1350多个精品易语言模块

    API 设置颜色对话框模块.ec ard.ec Arhz_自动更新.ec Base64编解码.ec BASE64编解码模块.ec Bios.ec Bios 信息.ec BMP加密数据.ec BMP滤镜模块.ec BOX.EC BPL专用更新模块.ec BPL综合模 块.ec BPL高级模块.ec ...

Global site tag (gtag.js) - Google Analytics