- android - RelativeLayout 背景可绘制重叠内容
- android - 如何链接 cpufeatures lib 以获取 native android 库?
- java - OnItemClickListener 不起作用,但 OnLongItemClickListener 在自定义 ListView 中起作用
- java - Android 文件转字符串
我正在尝试模拟 MS Office 打印对话框的打印机选择组合框。下拉列表包含左侧带有大打印机图标的打印机名称。在 Vista 上,传真打印机有一个漂亮的传真图标,共享打印机被标记,默认打印机也是如此。最好也能查看更多打印机信息,就像资源管理器查看控制面板->打印机一样。
有什么从哪里开始的想法吗?
SHGetFileInfo
取得了一定的成功,但我们非常欢迎您提出意见。
[操作系统:windows,代码语言:任何]
最佳答案
这是我最终想到的。你需要 IShellFolder Extended Type Library v1.2用于各种 OLE 接口(interface)。我很肯定这个类型库可以以更好的方式移植到 VB6,但无论如何结果如下:
Option Explicit
Private Const CSIDL_PRINTERS As Long = &H4
Private Const SHGFI_PIDL As Long = &H8
Private Const SHGFI_ICON As Long = &H100
Private Const SHGFI_DISPLAYNAME As Long = &H200
Private Const MAX_PATH As Long = 260
Private Declare Function SHGetDesktopFolder Lib "shell32" (ppshf As IShellFolder) As Long
Private Declare Function SHGetSpecialFolderLocation Lib "shell32.dll" (ByVal hwndOwner As Long, ByVal nFolder As Long, pidl As Long) As Long
Private Declare Sub CoTaskMemFree Lib "ole32.dll" (ByVal pv As Long)
Private Declare Function SHGetFileInfo Lib "shell32" Alias "SHGetFileInfoA" (pszPath As Any, ByVal dwFileAttributes As Long, psfi As SHFILEINFO, ByVal cbFileInfo As Long, ByVal uFlags As Long) As Long
Private Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (pDest As Any, pSource As Any, ByVal dwLength As Long)
Private Declare Function OleCreatePictureIndirect Lib "olepro32.dll" (lpPictDesc As PICTDESC, riid As Any, ByVal fPictureOwnsHandle As Long, ppRet As IPicture) As Long
Private Type SHFILEINFO
hIcon As Long
iIcon As Long
dwAttributes As Long
szDisplayName As String * MAX_PATH
szTypeName As String * 80
End Type
Private Type PICTDESC
Size As Long
Type As Long
hBmpOrIcon As Long
hPal As Long
End Type
Private Sub Command1_Click()
Dim IID_IShellFolder As IShellFolderEx_TLB.GUID
Dim IID_IPicture(0 To 3) As Long
Dim pidlPrinters() As Byte
Dim pidlCurrent() As Byte
Dim pidlAbsolute() As Byte
Dim pDesktopFolder As IShellFolder
Dim pPrintersFolder As IShellFolder
Dim pEnumIds As IEnumIDList
Dim lPtr As Long
Dim uInfo As SHFILEINFO
Dim uPict As PICTDESC
Dim sPrinterName As String
Dim oPrinterIcon As StdPicture
'--- init consts
IID_IShellFolder.Data1 = &H214E6 '--- {000214E6-0000-0000-C000-000000000046}
IID_IShellFolder.Data4(0) = &HC0
IID_IShellFolder.Data4(7) = &H46
IID_IPicture(0) = &H7BF80980 '--- {7BF80980-BF32-101A-8BBB-00AA00300CAB}
IID_IPicture(1) = &H101ABF32
IID_IPicture(2) = &HAA00BB8B
IID_IPicture(3) = &HAB0C3000
'--- init local vars
uPict.Size = Len(uPict)
uPict.Type = vbPicTypeIcon
Call SHGetDesktopFolder(pDesktopFolder)
'--- retrieve enumerator of Printers virtual folder
Call SHGetSpecialFolderLocation(0, CSIDL_PRINTERS, lPtr)
pidlPrinters = pvToPidl(lPtr)
Call pDesktopFolder.BindToObject(VarPtr(pidlPrinters(0)), 0, IID_IShellFolder, pPrintersFolder)
Call pPrintersFolder.EnumObjects(0, SHCONTF_NONFOLDERS, pEnumIds)
'--- loop printers
Do While pEnumIds.Next(1, lPtr, 0) = 0 '--- S_OK
pidlCurrent = pvToPidl(lPtr)
'--- combine pidls: Printers + Current
ReDim pidlAbsolute(0 To UBound(pidlPrinters) + UBound(pidlCurrent))
Call CopyMemory(pidlAbsolute(0), pidlPrinters(0), UBound(pidlPrinters) - 1)
Call CopyMemory(pidlAbsolute(UBound(pidlPrinters) - 1), pidlCurrent(0), UBound(pidlCurrent) - 1)
'--- retrieve info
Call SHGetFileInfo(pidlAbsolute(0), 0, uInfo, Len(uInfo), SHGFI_PIDL Or SHGFI_DISPLAYNAME Or SHGFI_ICON)
sPrinterName = Left(uInfo.szDisplayName, InStr(uInfo.szDisplayName, Chr$(0)) - 1)
'--- extract icon
uPict.hBmpOrIcon = uInfo.hIcon
Call OleCreatePictureIndirect(uPict, IID_IPicture(0), True, oPrinterIcon)
'--- show
Set Picture = oPrinterIcon
MsgBox sPrinterName
Loop
End Sub
Private Function pvToPidl(ByVal lPtr As Long) As Byte()
Dim lTotal As Long
Dim nSize As Integer
Dim baPidl() As Byte
Do
Call CopyMemory(nSize, ByVal (lPtr + lTotal), 2)
lTotal = lTotal + nSize
Loop While nSize <> 0
ReDim baPidl(0 To lTotal + 1)
Call CopyMemory(baPidl(0), ByVal lPtr, lTotal + 2)
Call CoTaskMemFree(lPtr)
pvToPidl = baPidl
End Function
关于windows - 检索当前用户打印机的图标,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1063874/
如果我使用下面的代码,数据将为零 dispatch_async(dispatch_get_global_queue(0,0), ^{ UIImage *img = [[UIImage allo
fread来自 data.table包一般可以在读取文件时自动确定列分隔符( sep )。 例如,这里fread自动检测 |作为列分隔符: library(data.table) fread(past
因此,如果我有一个如下所示的数据框: A B C rowname1 4.5 4 3.2 rowname2 3 23
我有一个汽车模型的搜索数据库:“日产Gtr”,“Huynday Elantra”,“Honda Accord”等。 现在我还有一个用户列表和他们喜欢的汽车类型 user1喜欢:carId:1234,c
我正在使用 Javamail 来获取一些电子邮件数据。我将用户输入作为电子邮件 ID、imap 地址和密码并连接到 imap。然后我监视收件箱的电子邮件并查明此人是否在“收件人”或“抄送”中。 Ema
我有一些数据,我想根据差距统计来评估最佳簇数。 我阅读了 gap statistic 上的页面在 r 中给出了以下示例: gs.pam.RU Number of clusters (method '
我有一个用户名和密码组合,我将使用它通过 java 代码访问安全服务器。 我的想法是: 在外部存储加密凭据 执行时提示用户输入解密密码 在使用前将解密的凭据直接存储在字符数组中 使用凭据连接到数据库
这是 Firebase 数据:[Firebase 数据][1] 我必须从员工那里检索所有字段并将其存储在一个数组中。 现在数据更改 toast 消息即将到来,但已经很晚了。 Firebase.setA
我是 iOS 的新手,正在开发一个基本的应用程序,它目前正在使用 SSKeychain 和 AFNetworking 与 API 进行交互。当您使用我检索的应用程序登录并在我的 CredentialS
编辑:这个问题已经在 apphacker 和 ConcernedOfTunbridgeWells 的帮助下得到解决。我已更新代码以反射(reflect)我将使用的解决方案。 我目前正在编写一个群体智能
我是 C 的新手,我想编写一个程序来检查用户输入的单词是否合法。我已经在 stackoverflow 上搜索了建议,但很多都是针对特定情况的。请在我被激怒之前,我知道这个语法不正确,但正在寻找一些关于
我相信你们中的一些人编写过 C# 类,这些类必须从数据库设置密码/从数据库获取密码。 我假设敏感细节不会以明文形式显示。处理此类数据的推荐程序是什么?检索到的文本是否加密?您是否将 pws 存储在加密
我在 linux 上使用 2.7 之前的 python 版本,想知道如何检索 RUID? 2.7 及更高版本从 os 包中获得了 getresuid,但我似乎找不到 2.6 的等效项 最佳答案 您可以
我已经在 Android 中实现了一个存储对象的标准 LRUCache。每个键都是与存储的对象关联的唯一 ObjectId。我的问题是从缓存中检索对象的唯一方法是通过 ObjectId(无迭代器)。实
这已经被问过很多次了。解决方案(对我有用)是从 packages.config 文件(这就足够了)和 packages 文件夹中删除 *** 包。 这对我来说是一个糟糕的解决方案,因为每次我想安装一些
我有以下文字: #{king} for a ##{day}, ##{fool} for a #{lifetime} 以及以下(损坏的)正则表达式: [^#]#{[a-z]+} 我想匹配所有#{word
我正在寻找一种快速(如高性能,而不是快速修复)解决方案来持久化和检索数千万个小型(大约 1k)二进制对象。每个对象都应该有一个用于检索的唯一 ID(最好是 GUID 或 SHA)。额外的要求是它应该可
有没有办法获取 RegInit 的重置值?通过探测产生的类型的成员?我可以看到 RegInit 将返回类型(例如 UInt )。例如,我将有一个寄存器,我想通过 regmap 对其进行控制。 val
Iv 目前接手了一个项目,其中开发人员在某些表的 json 数组列中存储了 has many 关系。 产品表 ---------------------------- id | product | c
Git 会在任何地方记录推送到远程的历史吗? 我注意到我们能够在 Microsoft VSTS 中查看 Git 存储库的推送历史记录以及每次推送的相关提交。它甚至显示旧的、过时的提交,由于后来的强制推
我是一名优秀的程序员,十分优秀!