Access开发培训
网站公告
·Access专家课堂QQ群号:151711184    ·Access快速开发平台下载地址及教程    ·欢迎加入Access专家课堂微信群!    ·如何快速搜索本站文章|示例|资料    
您的位置: 首页 > 技术文章 > Access数据库-窗体/数据页

如何设置窗体左上角的图标?

时 间:2007-10-21 09:30:16
作 者:cuxun   ID:70  城市:闵行
摘 要:如何设置窗体左上角的图标?
正 文:

如何设置窗体左上角的图标?
方法很多,这里介绍3种:

方法一:
在菜单中设置, 工具 -> 启动 -> 应用程序图标
如果在“用作窗体和报表的图标”前面打勾,那么你的这个access数据库中所有的窗体和报表的图标都会一致

方法二:
用api,代码如下:

There are no direct way to place a custom icon in a form's caption bar. However, by loading an ICO file into memory, we can assign the icon to a form by sending a WM_SETICON message to the window.

'*********** Code Start ********
'Code courtesy of
'Klaus H. Probst
'
'// Place all this in a module
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


Public Const WM_GETICON = &H7F
Public Const WM_SETICON = &H80
Public Const ICON_SMALL = 0
Public Const ICON_BIG = 1

'// LoadImage() image types
Public Const IMAGE_BITMAP = 0
Public Const IMAGE_ICON = 1
Public Const IMAGE_CURSOR = 2
Public Const IMAGE_ENHMETAFILE = 3

'// LoadImage() flags
Public Const LR_DEFAULTCOLOR = &H0
Public Const LR_MONOCHROME = &H1
Public Const LR_COLOR = &H2
Public Const LR_COPYRETURNORG = &H4
Public Const LR_COPYDeleteORG = &H8
Public Const LR_LOADFROMFILE = &H10
Public Const LR_LOADTRANSPARENT = &H20
Public Const LR_DEFAULTSIZE = &H40
Public Const LR_LOADMAP3DCOLORS = &H1000
Public Const LR_CreateDIBHeader = &H2000
Public Const LR_COPYFROMRESOURCE = &H4000
Public Const LR_SHARED = &H8000

Public Function SetFormIcon(hWnd As Long, IconPath As String) As Boolean
Dim hIcon As Long

hIcon = LoadImage(0&, IconPath, IMAGE_ICON, 16, 16, LR_LOADFROMFILE)

'// wParam = 0; Setting small icon. wParam = 1; setting large icon
If hIcon <> 0 Then
Call SendMessage(hWnd, WM_SETICON, 0, ByVal hIcon)
SetFormIcon = True
End If
End Function
'*********** Code Start ********
'翻译成中文如下:
没有一个直接的办法为窗体设置自己的图标,然而, 通过加载图标文件到内存,
然后通过发送WM_SETICON 消息到这个窗体来指定这个窗体的图标

'*********** 代码开始 ********
'Code courtesy of
'Klaus H. Probst
'
'// 引用API 函数loadimage及 sendmessage
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


Public Const WM_GETICON = &H7F
Public Const WM_SETICON = &H80
Public Const ICON_SMALL = 0
Public Const ICON_BIG = 1

'// LoadImage() image types
'指定了欲载入的图象类型:IMAGE_BITMAP, IMAGE_CURSOR, IMAGE_ICON

Public Const IMAGE_BITMAP = 0
Public Const IMAGE_ICON = 1
Public Const IMAGE_CURSOR = 2
Public Const IMAGE_ENHMETAFILE = 3

'// LoadImage() 参数

'LR_DEFAULTCOLOR 以常规方式载入图象
'LR_LOADREALSIZE 不对图象进行缩放处理。忽略n1和n2的设置
'LR_CreateDIBSECTION 如果指定了IMAGE_BITMAP,就返回DIBSection的句柄,而不是位图
的句柄
'LR_DEFAULTSIZE 如果n1和n2为零,就使用由系统定义的图象默认大小,而不是图象本身
定义的大小
'LR_LOADFROMFILE 如hInst为零,lpsz就代表要载入适当类型的一个文件的名字,仅适用
于Win95
'LR_LOADMAP3DCOLORS 将图象中的深灰、灰、以及浅灰像素都替换成COLOR_3DSHADOW,
COLOR_3DFACE以及COLOR_3DLIGHT的当前设置
'LR_LOADTRANSPARENT 与

Access软件网QQ交流群 (群号:54525238)       Access源码网店

常见问答:

技术分类:

相关资源:

专栏作家

关于我们 | 服务条款 | 在线投稿 | 友情链接 | 网站统计 | 网站帮助