非托管 C++ 中的默认打印机
我正在寻找一种使用非托管 C++ 查找 Windows 默认打印机名称的方法(找到了大量 .NET 示例,但非托管没有成功)。 谢谢。
I'm looking for a way to find the name of the Windows default printer using unmanaged C++ (found plenty of .NET examples, but no success unmanaged). Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
以下是如何获取当前打印机和默认打印机的列表(如果有一台设置为默认打印机)。
另请注意:如果用户没有打印机或未将打印机名称设置为默认值,则默认打印机名称长度为零是有效的。
还应该支持处理长打印机名称,因此首先使用 NULL 作为缓冲区指针调用 GetDefaultPrinter 将返回名称长度,然后您可以分配一个足够大的名称缓冲区来容纳该名称。
Here is how to get a list of current printers and the default one if there is one set as the default.
Also note: getting zero for the default printer name length is valid if the user has no printers or has not set one as default.
Also being able to handle long printer names should be supported so calling GetDefaultPrinter with NULL as a buffer pointer first will return the name length and then you can allocate a name buffer big enough to hold the name.
以下内容非常适合使用 C++ 中的 win32api 进行打印。
将来,不要在谷歌上搜索“非托管”,而是尝试在谷歌上搜索“win32 /subject/”或“win32 api /subject/”
The following works great for printing with the win32api from C++
In the future instead of googling "unmanaged" try googling "win32 /subject/" or "win32 api /subject/"
如何在 Windows 中检索和设置默认打印机:
http:// /support.microsoft.com/default.aspx?scid=kb;EN-US;246772
来自现在不可用的文章的代码:
How to retrieve and set the default printer in Windows:
http://support.microsoft.com/default.aspx?scid=kb;EN-US;246772
Code from now-unavailable article:
GetDefaultPrinter (MSDN) 应该可以解决问题。 这将为您提供传递给 CreateDC 进行打印的名称。
GetDefaultPrinter (MSDN) ought to do the trick. That will get you the name to pass to CreateDC for printing.
非托管 C++ 不存在(托管 C++ 现在是 C++/CLI),如果您指的是 C++,使用非托管作为标记只是令人难过......
Unmanaged C++ doesn't exist (and managed C++ is now C++/CLI), if you are referring to C++, using unmanaged as a tag is just sad...