João serras-pereira
asked on
putting an icon in a form
I had this question after viewing type mismatch calling function.
I have picked a solution from EE to put an icon on a form in ms/access. I have a solution the previously worked which is:
(1) putting the logo in the database folder (e.g. the file "logoFinal32.ico")
(2) put the following code at form load:
strFormIcon = "logoFinal32.ico"
SetFormIcon Me.hwnd, Left(CurrentDb.Name, Len(CurrentDb.Name) - Len(Dir(CurrentDb.Name))) & "\" & strFormIcon
(3) have following functions and definitions in a module:
Option Compare Database
Option Explicit
Declare PtrSafe Function GetSystemMetrics Lib "user32" (ByVal nIndex As Long) As Long
Declare PtrSafe Function LoadImage Lib "user32" Alias "LoadImageA" (ByVal hInst As LongPtr, ByVal lpsz As String, ByVal un1 As Long, ByVal n1 As Long, ByVal n2 As Long, ByVal un2 As Long) As LongPtr
Declare PtrSafe Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As LongPtr, ByVal wMsg As Long, ByVal wParam As LongPtr, lParam As Any) As LongPtr
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
Public Function SetFormIcon(hwnd As Long, strIconPath As String) As Boolean
Dim lResult As LongPtr
Dim X As Long, Y As Long
Dim lIcon As LongPtr
X = GetSystemMetrics(SM_CXSMIC ON)
Y = GetSystemMetrics(SM_CYSMIC ON)
lIcon = LoadImage(0, strIconPath, 1, X, Y, LR_LOADFROMFILE)
lResult = SendMessage(hwnd, WM_SETICON, 0, ByVal lIcon)
End Function
my file has a 32x32 pixel resolution
but the form icon remains
can anyone help?
I have picked a solution from EE to put an icon on a form in ms/access. I have a solution the previously worked which is:
(1) putting the logo in the database folder (e.g. the file "logoFinal32.ico")
(2) put the following code at form load:
strFormIcon = "logoFinal32.ico"
SetFormIcon Me.hwnd, Left(CurrentDb.Name, Len(CurrentDb.Name) - Len(Dir(CurrentDb.Name))) & "\" & strFormIcon
(3) have following functions and definitions in a module:
Option Compare Database
Option Explicit
Declare PtrSafe Function GetSystemMetrics Lib "user32" (ByVal nIndex As Long) As Long
Declare PtrSafe Function LoadImage Lib "user32" Alias "LoadImageA" (ByVal hInst As LongPtr, ByVal lpsz As String, ByVal un1 As Long, ByVal n1 As Long, ByVal n2 As Long, ByVal un2 As Long) As LongPtr
Declare PtrSafe Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As LongPtr, ByVal wMsg As Long, ByVal wParam As LongPtr, lParam As Any) As LongPtr
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
Public Function SetFormIcon(hwnd As Long, strIconPath As String) As Boolean
Dim lResult As LongPtr
Dim X As Long, Y As Long
Dim lIcon As LongPtr
X = GetSystemMetrics(SM_CXSMIC
Y = GetSystemMetrics(SM_CYSMIC
lIcon = LoadImage(0, strIconPath, 1, X, Y, LR_LOADFROMFILE)
lResult = SendMessage(hwnd, WM_SETICON, 0, ByVal lIcon)
End Function
my file has a 32x32 pixel resolution
but the form icon remains
can anyone help?
How/when are you running the code to set the icon?
ASKER
at form load...
Can you post the exact code you are using?
ASKER
yeap. It is just above, on the starting of this question
Can you post the whole code for the form's Load event?
Then we can see if there is a problem there.
Then we can see if there is a problem there.
ASKER
sure!
here it goes:
Private Sub Form_Load()
Dim strFormIcon As String
'DoCmd.ShowToolbar "Ribbon", acToolbarNo
DoCmd.ShowToolbar "Ribbon", acToolbarYes
'DoCmd.NavigateTo "acNavigationCategoryObjec tType"
'DoCmd.RunCommand acCmdWindowHide
'DoCmd.RunCommand acCmdWindowShow
DoCmd.OpenForm "_commonVariables", , , , , acHidden
Forms![_commonVariables]![ latGPS] = 12.29027777777
Forms![_commonVariables]![ lgtGPS] = -15.3863888888
Forms![_commonVariables]![ raioLimite ] = 1000
Forms![_commonVariables]![ userID] = ""
Call logMe("load form [00 base]", "")
On Error Resume Next
strFormIcon = "logoFinal32.ico"
SetFormIcon Me.hwnd, Left(CurrentDb.Name, Len(CurrentDb.Name) - Len(Dir(CurrentDb.Name))) & "\" & strFormIcon
End Sub
and the full module code is:
ption Compare Database
Option Explicit
Declare PtrSafe Function GetSystemMetrics Lib "user32" (ByVal nIndex As Long) As Long
Declare PtrSafe Function LoadImage Lib "user32" Alias "LoadImageA" (ByVal hInst As LongPtr, ByVal lpsz As String, ByVal un1 As Long, ByVal n1 As Long, ByVal n2 As Long, ByVal un2 As Long) As LongPtr
Declare PtrSafe Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As LongPtr, ByVal wMsg As Long, ByVal wParam As LongPtr, lParam As Any) As LongPtr
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
Public Function SetFormIcon(hwnd As Long, strIconPath As String) As Boolean
Dim lResult As LongPtr
Dim X As Long, Y As Long
Dim lIcon As LongPtr
X = GetSystemMetrics(SM_CXSMIC ON)
Y = GetSystemMetrics(SM_CYSMIC ON)
lIcon = LoadImage(0, strIconPath, 1, X, Y, LR_LOADFROMFILE)
lResult = SendMessage(hwnd, WM_SETICON, 0, ByVal lIcon)
End Function
and the ico file is uploaded on the message (I have changed the extension to png as EE does dot accept to upload ICO files. I am using ICO and not png because, as long as I know, the ms/access forms does not accept PNG....
logofinal32.png
here it goes:
Private Sub Form_Load()
Dim strFormIcon As String
'DoCmd.ShowToolbar "Ribbon", acToolbarNo
DoCmd.ShowToolbar "Ribbon", acToolbarYes
'DoCmd.NavigateTo "acNavigationCategoryObjec
'DoCmd.RunCommand acCmdWindowHide
'DoCmd.RunCommand acCmdWindowShow
DoCmd.OpenForm "_commonVariables", , , , , acHidden
Forms![_commonVariables]![
Forms![_commonVariables]![
Forms![_commonVariables]![
Forms![_commonVariables]![
Call logMe("load form [00 base]", "")
On Error Resume Next
strFormIcon = "logoFinal32.ico"
SetFormIcon Me.hwnd, Left(CurrentDb.Name, Len(CurrentDb.Name) - Len(Dir(CurrentDb.Name))) & "\" & strFormIcon
End Sub
and the full module code is:
ption Compare Database
Option Explicit
Declare PtrSafe Function GetSystemMetrics Lib "user32" (ByVal nIndex As Long) As Long
Declare PtrSafe Function LoadImage Lib "user32" Alias "LoadImageA" (ByVal hInst As LongPtr, ByVal lpsz As String, ByVal un1 As Long, ByVal n1 As Long, ByVal n2 As Long, ByVal un2 As Long) As LongPtr
Declare PtrSafe Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As LongPtr, ByVal wMsg As Long, ByVal wParam As LongPtr, lParam As Any) As LongPtr
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
Public Function SetFormIcon(hwnd As Long, strIconPath As String) As Boolean
Dim lResult As LongPtr
Dim X As Long, Y As Long
Dim lIcon As LongPtr
X = GetSystemMetrics(SM_CXSMIC
Y = GetSystemMetrics(SM_CYSMIC
lIcon = LoadImage(0, strIconPath, 1, X, Y, LR_LOADFROMFILE)
lResult = SendMessage(hwnd, WM_SETICON, 0, ByVal lIcon)
End Function
and the ico file is uploaded on the message (I have changed the extension to png as EE does dot accept to upload ICO files. I am using ICO and not png because, as long as I know, the ms/access forms does not accept PNG....
logofinal32.png
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Well - I should be okay but I am going to try with a smaller (16x16) version.. as well as with other bitmaps
did you try with my bitmap?
did you try with my bitmap?
I tried with the image you uploaded as it was, ie a png file, and after saving as bitmap but neither worked I'm afraid.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Hi -
My image is NOT a PNG. It is a .ICO had to change the extension "the ico file is uploaded on the message (I have changed the extension to png as EE does dot accept to upload ICO files. I am using ICO and not png because, as long as I know, the ms/access forms does not accept PNG...."
But Ok I accept the solution and close the question...
thanks for the help!
My image is NOT a PNG. It is a .ICO had to change the extension "the ico file is uploaded on the message (I have changed the extension to png as EE does dot accept to upload ICO files. I am using ICO and not png because, as long as I know, the ms/access forms does not accept PNG...."
But Ok I accept the solution and close the question...
thanks for the help!
My image is NOT a PNG. It is a .ICO had to change the extensionThat's not the point ... as Norie and I have mentioned, Access simply does not accept certain image files, regardless of their format. In other words, MyImage.png may work perfectly fine, but MyOtherImage.png will not.
Try changing the format of the image file, or use a different image file. The one you're trying to use simply won't work.
ASKER
OK!!!