Custom icon with a Form

A

Amateur

Dear Sirs,
I would like to see a custom icon with a Form.
I did the following:
I created a module with the name "favicon" in the DB "Mainswitchboard -
Option Compare Database

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 Declare Function GetSystemMetrics Lib "user32" (ByVal nIndex As
Long) As Long

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 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


I created in the "On open" property of the form:

Private Sub Form_Open(Cancel As Integer)
DoCmd.Maximize
SetFormIcon Me.hWnd, "C:\cps208\photos\fav.ico"
End Sub

My own Favicon is not shown. Can someone tell me why not?
Thanks
Klaus
 
J

Jon Lewis

Have you got the Form's Control Box property set to No by any chance? It
should be Yes to display the icon.

HTH

Jon
 
A

Amateur

I did now and the icon is showing - but I believe I explained it wrong.
What I wanted:
I have a form called "MainForm" in a database called Mainswitchboard".
I created a shortcut from the "MainForm" to my desktop.
There is a shortcut icon (as all Forms have in MS Access) on the desktop for
this Form.
I would like to change this shortcut icon.
Any idea how to do that?
Thanks
Klaus
 
J

Jon Lewis

I don't think you can aside from altering registry settings.

Why don't you create a shortcut to the database itself (you can then right
click the shortcut and choose whatever icon you like) and have this form as
the starup form?

HTH
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top