我正在处理一个用户窗体,我试图在用户窗体的标题属性中使用 IE/Chrome 等徽标,以便该徽标显示在窗口框架中,后跟一些文本。
我进行了一些浏览,并在网上找到了以下代码,但在涉及 ExtractIcon 的行上出现子/函数未定义错误。
用户表单代码
Private Sub UserForm_Initialize
Dim strIconPath As String
Dim lngIcon As Long
Dim lnghWnd As Long
' Change to the path and filename of an icon file
strIconPath = "C:\Users\suttond\Desktop\Picture2.gif"
' Get the icon from the source
lngIcon = ExtractIcon(0, strIconPath, 0)
' Get the window handle of the userform
lnghWnd = FindWindow("ThunderDFrame", UserForm1.Caption)
'Set the big (32x32) and small (16x16) icons
SendMessage lnghWnd, WM_SETICON, True, lngIcon
SendMessage lnghWnd, WM_SETICON, False, lngIcon
End Sub
模块代码
Private Declare Function FindWindow _
Lib "user32" Alias "FindWindowA" _
(ByVal lpClassName As String, _
ByVal lpWindowName As String) As Long
Private Declare Function ExtractIcon _
Lib "shell32.dll" Alias "ExtractIconA" _
(ByVal hInst As Long, _
ByVal lpszExeFileName As String, _
ByVal nIconIndex As Long) As Long
Private Declare Function SendMessage _
Lib "user32" Alias "SendMessageA" _
(ByVal hWnd As Long, _
ByVal wMsg As Long, _
ByVal wParam As Integer, _
ByVal lParam As Long) As Long
Private Const WM_SETICON = &H80
本质上,一个小的 IE Explorer 徽标将显示在标题中已有文本的左侧。
编辑
模块代码函数更新为 public 以允许从初始化代码调用它们。不再出现提取错误,但图像未出现在用户窗体标题中。
正如 Mistella 和 Rory 在您的问题的评论中提到的,函数和常量需要声明为Public
. 如果您将它们声明为Private
,则它们仅在模块中已知,而在表单中不存在。
第二件事是您需要从 ICO 文件中读取图标,而不是从 gif 文件中读取图标,因此您需要对其进行转换。我将IrfanView用于此类任务,但有大量工具(甚至在线)可用。我做了一个快速测试,它奏效了:
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句