[VBA]VBA窗体上图标
很想在VB窗体上搞个图标,但一直找不到方法到底有没有方法能够实现在VBA/VB窗体左上角文字之前显示一个小图标呢? 用下面的代码可以实现,在VB中直接使用窗体的Hwnd,而不需要GetActiveWindow获取当前活动窗口的句柄。
不过有个问题,在VBA中的标题前面部分被遮住了。
Private Declare Function GetActiveWindow Lib "user32" () As Long
Private Declare Function LoadImage Lib "user32" Alias "LoadImageA" (ByVal hInst As Long, ByVal lpsz As String, ByVal un1 As Long, ByVal n1 As Long, ByVal n2 As Long, ByVal un2 As Long) As Long
Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal Hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
Private Const WM_SETICON = &H80
Private Const IMAGE_ICON = 1
Private Const LR_LOADFROMFILE = &H10
Private Sub UserForm_Activate()
Dim Hwnd As Long
Hwnd = GetActiveWindow
Dim hIcon As Long
hIcon = LoadImage(0&, "c:\光缆.ico", IMAGE_ICON, 16, 16, LR_LOADFROMFILE)
If hIcon <> 0 Then
Call SendMessage(Hwnd, WM_SETICON, 0, ByVal hIcon)
End If
End Sub
多谢! 是不是一定要是ico的,而且是16X16的? 图标肯定要使用ICO类型的,但大小一般情况下是16*16,如果一定要与标准的风格相异时,也可以自已设定大小。 先在窗体的标题前空6空格,再重新赋予无空格的标题就可以消除被遮现象.
reply
窗体标题被遮住一部分,只要刷新一下窗体就可以了,可以这样Me.Caption = Me.Caption加到efan2000的代码中 学习一下!
页:
[1]