在access中没有一个直接的办法为窗体设置自己的图标,但是, 可以通过Wondows API的LoadImage加载图标文件到内存, 通过SendMessage发送WM_SETICON消息到这个窗体,来指定这个窗体的图标。
首先新建一个模块,添加Windows API函数定义如下:
Public 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
Public Declare Function SendMessage Lib "user32" Alias "SendMessageA" _
(ByVal hWnd As Long, _
ByVal wMsg As Long, _
ByVal wParam As Long, _
LParam As Any) _
As Long
定义API要使用的常量如下:
Public Const WM_SETICON = &H80
Public Const IMAGE_ICON = 1
Public Const LR_LOADFROMFILE = &H10
更改窗体图标的函数
Public Function SetFormIcon(hWnd As Long, IconPath As String) As Boolean
' 调用方式
' 例: intX = SetFormIcon(Me.hWnd, strPicPath)
Dim hIcon As Long
' 加载 16X16 图标到内存
hIcon = LoadImage(0&, IconPath, IMAGE_ICON, 16, 16, LR_LOADFROMFILE)
' 返回值 执行成功则返回对象的一个句柄;零表示失败
If hIcon <> 0 Then '如果成功则设置窗体图标
' 发送消息,设置窗体图
Call SendMessage(hWnd, WM_SETICON, 0, ByVal hIcon)标
SetFormIcon = True '返回设置成功
Else
SetFormIcon = False
End If
End Function
在程序中使用
例如:把当前窗体的图标改 C:\my.ico
一般在窗体的加载事件处理程序中书写更改窗体的程序
Private Sub Form_Load()
Dim intX
intX = SetFormIcon(Me.hWnd, "C:\my.ico")
End Sub
信息来源:http://www.office-faq.cn/office/5/office184.htm