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

 我来答
龙氏风采
2016-12-14 · 知道合伙人互联网行家
龙氏风采
知道合伙人互联网行家
采纳数:5849 获赞数:12817
从事互联网运营推广,5年以上互联网运营推广经验,丰富的实战经

向TA提问 私信TA
展开全部
方法一:
在菜单中设置, 工具 -> 启动 -> 应用程序图标
如果在“用作窗体和报表的图标”前面打勾,那么你的这个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 与
本回答被网友采纳
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式