Changeing the forms titlebar icon

atisz

Registered User.
Local time
Today, 07:26
Joined
Apr 5, 2005
Messages
96
Hi,

I created an icon for my database application and I would like to display it in each form's title bar. Is this possible? And if it is, how? A few years ago I learned a little Delphi programming, and there this is possible to do.
Thanx!

Attila
 
The below code will allow you to assign an icon file to your forms...

Code:
'place this code in the OnLoad event for each form...
Private Sub Form_Load()
SetFormIcon Me.hWnd, "C:\Data\Icons\Icon1.ico"
'use this instead if the db might be moved and the icon file will be in the same folder as the db
'SetFormIcon Me.hWnd, Left(CurrentDb.Name, Len(CurrentDb.Name) - Len(Dir(CurrentDb.Name))) & "\Icon1.ico"
End Sub

'copy below code in a new public module...
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

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

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

HTH
 
Working, not working

ghudson said:
The below code will allow you to assign an icon file to your forms...

Code:
'place this code in the OnLoad event for each form...
Private Sub Form_Load()
SetFormIcon Me.hWnd, "C:\Data\Icons\Icon1.ico"
'use this instead if the db might be moved and the icon file will be in the same folder as the db
'SetFormIcon Me.hWnd, [I][B]Left[/B][/I](CurrentDb.Name, Len(CurrentDb.Name) - Len(Dir(CurrentDb.Name))) & "\Icon1.ico"
End Sub
[/QUOTE]

Thanx for your help, ghudson!
If I use the first option (the path specified one), it's working fine.
If I use the second one, wich I preffer, it's gaving me for [B][I]Left[/I][/B] the following error:  [I]Can't find project or library.[/I] What could be wrong?

Attila
 
Sounds like a reference error if a simple function like Left() will not work. Check your references for any that are tagged as MISSING and fix it.

What version of Access are you using?

Below are different ways to determine the location of the current db...

Code:
[b]Getting the path to the current database[/b]

[b]For Access 2000/2002/2003...[/b]

'returns the database file name
[b]CurrentProject.Name[/b]

'returns the database path
[b]CurrentProject.Path[/b] 

'returns the database path and the file name
[b]CurrentProject.FullName[/b] 

[b]For Access 97...[/b]

'returns the database file name
[b]Dir(CurrentDb.Name)[/b] 

'returns the database path
[b]Left(CurrentDb.Name,Len(CurrentDb.Name)-Len(Dir(CurrentDb.Name)))[/b] 

'returns the database path and the file name
[b]CurrentDb.Name[/b]

'returns the directory that Access [msaccess.exe] is installed in
[b](SysCmd(acSysCmdAccessDir))[/b]
 
Access 2000

I'm using Access 2000, and I tried to implement the code you sent to me, but I'm such a bigginer in VBA, that I can make it by myself. :(
Can you send me the exact code, explain me everything like someone very beginer in this stuf.

Thank you!

Attila
 

Users who are viewing this thread

Back
Top Bottom