-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathFixIcon.bas
42 lines (39 loc) · 1.64 KB
/
FixIcon.bas
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
Attribute VB_Name = "FixWindowIcon"
Option Explicit
Private Const WM_SETICON = &H80
Private Const ICON_SMALL = 0
Private Const IMAGE_ICON = 1
Private Const LR_DEFAULTSIZE = &H40
Private Declare Function GetModuleHandle Lib "Kernel32.dll" _
Alias "GetModuleHandleA" _
(ByRef lpModuleName As Any) As Long
Private Declare Function LoadImage Lib "User32.dll" _
Alias "LoadImageA" ( _
ByVal hinst As Long, _
ByRef lpszName As Any, _
ByVal uType As Long, _
ByVal cxDesired As Long, _
ByVal cyDesired As Long, _
ByVal fuLoad As Long) As Long
Private Declare Function SendMessageA Lib _
"User32.dll" _
(ByVal hWnd As Long, _
ByVal Msg As Long, _
ByVal Wp As Long, _
Lp As Any) As Long
Sub FixIcon(hWnd As Long, lpszName)
Dim hModule As Long, hIcon As Long, szName As String, nName As Long, Width As Long, Height As Long
hModule = GetModuleHandle(ByVal 0&)
If hModule = 0 Then Exit Sub
Width = Abs(GetReg("HKEY_USERS\.Default\Control Panel\Desktop\WindowMetrics\CaptionWidth", -270)) / Screen.TwipsPerPixelX - 2
Height = Abs(GetReg("HKEY_USERS\.Default\Control Panel\Desktop\WindowMetrics\CaptionHeight", -270)) / Screen.TwipsPerPixelY - 2
If VarType(lpszName) = vbString Then
szName = lpszName
hIcon = LoadImage(hModule, szName, IMAGE_ICON, Width, Height, LR_DEFAULTSIZE)
ElseIf VarType(lpszName) = vbByte Or VarType(lpszName) = vbInteger Or VarType(lpszName) = vbLong Then
nName = lpszName
hIcon = LoadImage(hModule, ByVal nName, IMAGE_ICON, Width, Height, LR_DEFAULTSIZE)
End If
If hIcon = 0 Then Exit Sub
SendMessageA hWnd, WM_SETICON, ICON_SMALL, ByVal hIcon
End Sub