Khi tạo một userform mà muốn có logo nhỏ ở thanh tiêu đề form bên cạnh Caption thì làm thế nào?
Giả sử trên c:\ có tập tin logo.ico
Trong code của userform chèn thêm đoạn code dưới đây vào:
Option Explicit
Private Const WM_SETICON = &H80
#If VBA7 Then
Private Declare PtrSafe Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As LongPtr
Private Declare PtrSafe Function ExtractIcon Lib "shell32.dll" Alias "ExtractIconA" (ByVal hInst As LongPtr, ByVal lpszExeFileName As String, ByVal nIconIndex As Long) As LongPtr
Private Declare PtrSafe Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hWnd As LongPtr, ByVal wMsg As Long, ByVal wParam As LongPtr, ByVal lParam As LongPtr) As LongPtr
#Else
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 Long, ByVal lParam As Long) As Long
#End If
Private Sub UserForm_Initialize()
#If VBA7 Then
Dim lngIcon As LongPtr
Dim lnghWnd As LongPtr
#Else
Dim lngIcon As Long
Dim lnghWnd As Long
#End If
If Val(Application.Version) < 9 Then
lnghWnd = FindWindow("ThunderXFrame", Caption) 'XL97
Else
lnghWnd = FindWindow("ThunderDFrame", Caption) 'XL2000
End If
#If VBA7 Then
lngIcon = ExtractIcon(Application.HinstancePtr, "c:\logo.ico", 0)
#Else
lngIcon = ExtractIcon(Application.Hinstance, "c:\logo.ico", 0)
#End If
SendMessage lnghWnd, WM_SETICON, 0, lngIcon
End Sub
Chúc thành công!
Đăng nhận xét
0
Nhận xét
Bạn muốn đặt quảng cáo của bạn tại đây? Liên hệ Email: quocbinh.ga@gmail.com
0 Nhận xét