The below code works great, but it relies on a string (in red)holding the absolute path to the icon file.
I want to pass a public variable (I've already defined it, and it works elsewhere) that returns the relative application path. This is where the icon file will be.
If I have my global public variable "varFilePath", how do I pass it so that it will work the same as hard-coding the path inside quotes?
The Global Module
Option Compare Database
Private Const WM_SETICON = &H80
Private Const IMAGE_ICON = 1
Private Const LR_LOADFROMFILE = &H10
Private Const SM_CXSMICON As Long = 49
Private Const SM_CYSMICON As Long = 50
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 GetSystemMetrics Lib "user32" (ByVal nIndex 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
Public Function SetFormIcon(hwnd As Long, strIconPath As String) As Boolean
Dim lIcon As Long
Dim lResult As Long
Dim x As Long, y As Long
x = GetSystemMetrics(SM_CXSMICON)
y = GetSystemMetrics(SM_CYSMICON)
lIcon = LoadImage(0, strIconPath, 1, x, y, LR_LOADFROMFILE)
lResult = SendMessage(hwnd, WM_SETICON, 0, ByVal lIcon)
End Function
The call
Private Sub Form_Load()
SetFormIcon Me.hwnd, "C:\MyFolder\MyIcon.ico"
End Sub
This does NOT work because I get "ByRef Argument Type Mismatch":
Private Sub Form_Load()
SetFormIcon Me.hwnd, varIconPathandFileName
End Sub
----
By the way, varIconPathandFileName is declared as String
----
Thanks for any help.
Jay
I want to pass a public variable (I've already defined it, and it works elsewhere) that returns the relative application path. This is where the icon file will be.
If I have my global public variable "varFilePath", how do I pass it so that it will work the same as hard-coding the path inside quotes?
The Global Module
Option Compare Database
Private Const WM_SETICON = &H80
Private Const IMAGE_ICON = 1
Private Const LR_LOADFROMFILE = &H10
Private Const SM_CXSMICON As Long = 49
Private Const SM_CYSMICON As Long = 50
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 GetSystemMetrics Lib "user32" (ByVal nIndex 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
Public Function SetFormIcon(hwnd As Long, strIconPath As String) As Boolean
Dim lIcon As Long
Dim lResult As Long
Dim x As Long, y As Long
x = GetSystemMetrics(SM_CXSMICON)
y = GetSystemMetrics(SM_CYSMICON)
lIcon = LoadImage(0, strIconPath, 1, x, y, LR_LOADFROMFILE)
lResult = SendMessage(hwnd, WM_SETICON, 0, ByVal lIcon)
End Function
The call
Private Sub Form_Load()
SetFormIcon Me.hwnd, "C:\MyFolder\MyIcon.ico"
End Sub
This does NOT work because I get "ByRef Argument Type Mismatch":
Private Sub Form_Load()
SetFormIcon Me.hwnd, varIconPathandFileName
End Sub
----
By the way, varIconPathandFileName is declared as String
----
Thanks for any help.
Jay