vb提取dll图标

vb提取dll图标,第1张

代码如下。

=====================

Option Explicit

Dim lNumOfIcons As Long

Private Const sFile = "c:\windows\system32\shell32dll"

Private Declare Function ExtractIconEx Lib "shell32dll" Alias "ExtractIconExA" (ByVal lpszFile As String, ByVal nIconIndex As Long, phiconLarge As Long, phiconSmall As Long, ByVal nIcons As Long) As Long

'lpszFile-文件完整路径及文件名

'nIconIndex-开始提取的图标序号,如果设为-1,则函数返回图标总数量

'phiconLarge-装载大图标句柄的数组

'phiconSmall-装载小图标句柄的数组

'nIcons-提取的图标数量

Private Declare Function DrawIcon Lib "user32" (ByVal hdc As Long, ByVal x As Long, ByVal y As Long, ByVal hIcon As Long) As Long

Private Declare Function DestroyIcon Lib "user32" (ByVal hIcon As Long) As Long

Private Sub Form_Click() '单击窗体查看效果

'===========这些是你想要的代码

Dim hIL As OLE_HANDLE, hIS As OLE_HANDLE

ExtractIconEx sFile, 0, hIL, hIS, 1

DrawIcon hdc, 0, 0, hIL

DrawIcon hdc, 0, 60, hIS

'====================

'这些是提取所有图标的代码

'ReDim hIL(lNumOfIcons - 1) As OLE_HANDLE

'ReDim hIS(lNumOfIcons - 1) As OLE_HANDLE

'ExtractIconEx sFile, 0, hIL(0), hIS(0), lNumOfIcons

'Dim i As Byte

'For i = 0 To lNumOfIcons - 1

' CurrentX = i 50

' CurrentY = 0

' Print i

' DrawIcon hdc, i 50, 10, hIL(i)

' DestroyIcon hIL(i)

' CurrentX = i 50

' CurrentY = 50

' Print i

' DrawIcon hdc, i 50, 60, hIS(i)

' DestroyIcon hIS(i)

'Next

End Sub

Private Sub Form_Load()

ScaleMode = vbPixels

lNumOfIcons = ExtractIconEx(sFile, -1, 0, 0, 0)

End Sub

我空间上有很多关于图标的,你可以参考参考。

API从文件中提取图标并绘制>

Private Declare Function ExtractIcon Lib "shell32dll" Alias "ExtractIconA" (ByVal hInst As Long, ByVal lpszExeFileName As String, ByVal nIconIndex As Long) As Long

Private Declare Function DrawIcon Lib "user32" (ByVal hdc As Long, ByVal x As Long, ByVal y As Long, ByVal hIcon As Long) As Long

Private Sub Command1_Click()

Dim a As Long

Picture1AutoRedraw = True

Picture1BackColor = vbWhite

Picture1Width = 540

Picture1Height = 540

a = ExtractIcon(ApphInstance, "G:\Program Files\Tencent\QQ\qqexe", 0)

a = DrawIcon(Picture1hdc, 0, 0, a)

ImageList1ListImagesAdd , , Picture1Image

ListView1Icons = ImageList1

ListView1ListItemsAdd , , "aa", 1

End Sub

放个PICTUREBOX,IMAGELIST,LISTVIEW,COMMAND写入以上代码,OK。

您可以使用 GetWindow API 来列出窗口,其中包括子窗口。但是,调用 GetWindow 来执行此任务的应用程序存在陷入无限循环的风险或引用已销毁窗口的句柄的风险。使用 EnumWindows 枚举顶级窗口,使用 EnumChildWindows 枚举子窗口,或者使用 EnumThreadWindows 枚举与某个线程关联的所有非子窗口是首选方法,本文中将演示这一方法。

回到顶端

更多信息EnumWindows 将枚举所有顶级窗口,但不枚举子窗口。EnumChildWindows 函数既不会枚举由特定窗口拥有的顶级窗口,也不会枚举任何其他拥有的窗口。EnumThreadWindows 函数将枚举与某个线程关联的所有非子窗口。此示例使用上述全部三个函数来列出它找到的窗口的类和标题。请注意,尽管所有窗口都有一个类,但并是所有窗口也都有一个标题。

回到顶端

分步示例

在 Visual Basic 中启动一个新的项目。默认情况下创建 Form1。

添加两个 CommandButtons 和一个 TextBox。

将下面的代码复制到该窗体的模块中:

Option Explicit

Private Sub Command1_Click()

Dim lRet As Long, lParam As Long

Dim lhWnd As Long

lhWnd = Mehwnd ' Find the Form's Child Windows

' Comment the line above and uncomment the line below to

' enumerate Windows for the DeskTop rather than for the Form

'lhWnd = GetDesktopWindow() ' Find the Desktop's Child Windows

' enumerate the list

lRet = EnumChildWindows(lhWnd, AddressOf EnumChildProc, lParam)

End Sub

Private Sub Command2_Click()

Dim lRet As Long

Dim lParam As Long

'enumerate the list

lRet = EnumWindows(AddressOf EnumWinProc, lParam)

' How many Windows did we find

DebugPrint TopCount; " Total Top level Windows"

DebugPrint ChildCount; " Total Child Windows"

DebugPrint ThreadCount; " Total Thread Windows"

DebugPrint "For a grand total of "; TopCount + _

ChildCount + ThreadCount; " Windows!"

End Sub

添加包含以下代码的模块:

Option Explicit

Type RECT

Left As Long

Top As Long

Right As Long

Bottom As Long

End Type

Declare Function GetWindowRect Lib "user32" (ByVal hwnd As Long, _

lpRect As RECT) As Long

Declare Function MoveWindow Lib "user32" (ByVal hwnd As Long, _

ByVal x As Long, ByVal y As Long, ByVal nWidth As Long, _

ByVal nHeight As Long, ByVal bRepaint As Long) As Long

Declare Function GetDesktopWindow Lib "user32" () As Long

Declare Function EnumWindows Lib "user32" _

(ByVal lpEnumFunc As Long, ByVal lParam As Long) As Long

Declare Function EnumChildWindows Lib "user32" (ByVal hWndParent _

As Long, ByVal lpEnumFunc As Long, ByVal lParam As Long) As Long

Declare Function EnumThreadWindows Lib "user32" (ByVal dwThreadId _

As Long, ByVal lpfn As Long, ByVal lParam As Long) As Long

Declare Function GetWindowThreadProcessId Lib "user32" _

(ByVal hwnd As Long, lpdwProcessId As Long) As Long

Declare Function GetClassName Lib "user32" Alias "GetClassNameA" _

(ByVal hwnd As Long, ByVal lpClassName As String, _

ByVal nMaxCount As Long) As Long

Declare Function GetWindowText Lib "user32" Alias "GetWindowTextA" _

(ByVal hwnd As Long, ByVal lpString As String, _

ByVal cch As Long) As Long

Public TopCount As Integer ' Number of Top level Windows

Public ChildCount As Integer ' Number of Child Windows

Public ThreadCount As Integer ' Number of Thread Windows

Function EnumWinProc(ByVal lhWnd As Long, ByVal lParam As Long) _

As Long

Dim RetVal As Long, ProcessID As Long, ThreadID As Long

Dim WinClassBuf As String 255, WinTitleBuf As String 255

Dim WinClass As String, WinTitle As String

RetVal = GetClassName(lhWnd, WinClassBuf, 255)

WinClass = StripNulls(WinClassBuf) ' remove extra Nulls & spaces

RetVal = GetWindowText(lhWnd, WinTitleBuf, 255)

WinTitle = StripNulls(WinTitleBuf)

TopCount = TopCount + 1

' see the Windows Class and Title for each top level Window

DebugPrint "Top level Class = "; WinClass; ", Title = "; WinTitle

' Usually either enumerate Child or Thread Windows, not both

' In this example, EnumThreadWindows may produce a very long list!

RetVal = EnumChildWindows(lhWnd, AddressOf EnumChildProc, lParam)

ThreadID = GetWindowThreadProcessId(lhWnd, ProcessID)

RetVal = EnumThreadWindows(ThreadID, AddressOf EnumThreadProc, _

lParam)

EnumWinProc = True

End Function

Function EnumChildProc(ByVal lhWnd As Long, ByVal lParam As Long) _

As Long

Dim RetVal As Long

Dim WinClassBuf As String 255, WinTitleBuf As String 255

Dim WinClass As String, WinTitle As String

Dim WinRect As RECT

Dim WinWidth As Long, WinHeight As Long

RetVal = GetClassName(lhWnd, WinClassBuf, 255)

WinClass = StripNulls(WinClassBuf) ' remove extra Nulls & spaces

RetVal = GetWindowText(lhWnd, WinTitleBuf, 255)

WinTitle = StripNulls(WinTitleBuf)

ChildCount = ChildCount + 1

' see the Windows Class and Title for each Child Window enumerated

DebugPrint " Child Class = "; WinClass; ", Title = "; WinTitle

' You can find any type of Window by searching for its WinClass

If WinClass = "ThunderTextBox" Then ' TextBox Window

RetVal = GetWindowRect(lhWnd, WinRect) ' get current size

WinWidth = WinRectRight - WinRectLeft ' keep current width

WinHeight = (WinRectBottom - WinRectTop) 2 ' double height

RetVal = MoveWindow(lhWnd, 0, 0, WinWidth, WinHeight, True)

EnumChildProc = False

Else

EnumChildProc = True

End If

End Function

Function EnumThreadProc(ByVal lhWnd As Long, ByVal lParam As Long) _

As Long

Dim RetVal As Long

Dim WinClassBuf As String 255, WinTitleBuf As String 255

Dim WinClass As String, WinTitle As String

RetVal = GetClassName(lhWnd, WinClassBuf, 255)

WinClass = StripNulls(WinClassBuf) ' remove extra Nulls & spaces

RetVal = GetWindowText(lhWnd, WinTitleBuf, 255)

WinTitle = StripNulls(WinTitleBuf)

ThreadCount = ThreadCount + 1

' see the Windows Class and Title for top level Window

DebugPrint "Thread Window Class = "; WinClass; ", Title = "; _

WinTitle

EnumThreadProc = True

End Function

Public Function StripNulls(OriginalStr As String) As String

' This removes the extra Nulls so String comparisons will work

If (InStr(OriginalStr, Chr(0)) > 0) Then

OriginalStr = Left(OriginalStr, InStr(OriginalStr, Chr(0)) - 1)

End If

StripNulls = OriginalStr

End Function

运行项目并单击 Command1。这将枚举出该窗体的子窗口直至找到 TextBox,然后将 TextBox 的高度扩大一倍并将其移动到位置 (0, 0)(该窗体的左上方。)

单击 Command2。这会立即在即时窗口中列出所有顶级窗口及其子窗口以及与其线程关联的任何非子窗口的类和标题(如果存在)。请注意,这可以是一个非常长的列表,可能需要一段时间才能列出所有内容。

从“运行”菜单选择“结束”或单击“结束”按钮以停止程序。根据注释更改 Sub Command1_Click 中的代码以传递来自 GetDesktopWindow 的句柄。运行项目并单击 Command1 以枚举 DeskTop 的所有子窗口。请注意,完成此过程需要花费一些时间。

Process32First和 Process32Next来扫描当前系统的进程列表,假如目标进程存在的话就做你想要的工作

关闭进程的话用NtTerminateProcess 来实现,前提要用OpenProcess来获取进程句柄的最大权限,还不理解的话可以联系我

你可能对文件类型了解不是非常清楚:

1、不同的文件类型显示的图标不同;

2、不同的文件类型打开需要的软件不同,“双击可以直接打开选定的文件”,只要你的计算机有相应的软件,应该可以,但是如果没有相应软件,是打不开的;

3、记事本能够打开的文件只能是文本文档,如txt文件、ini文件等,因此“右键菜单可以打开文件,也可以编辑文件(通过记事本打开文件)”是不可能的。

4、目前计算机根据用途不同,安装的应用软件也不同,如果需要全部关联,恐怕可能性不大,因为现在windows平台的应用软件估计也有几千种吧?

以上就是关于vb提取dll图标全部的内容,包括:vb提取dll图标、用VB怎么列出windows正在运行的所有进程、VB 如何提取.exe文件图标,并加载到ListView中等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!

欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/web/9872474.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2023-05-02
下一篇2023-05-02

发表评论

登录后才能评论

评论列表(0条)

    保存