|
楼主 |
发表于 2009-3-21 08:49
|
显示全部楼层
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件 ★ 免费下载 ★ ★ 使用帮助★
第7部分 菜单和工具栏
技巧91 自定义工作簿图标
Excel标题栏的图标是默认的,而借助API函数可以自定义工作簿标题栏图标,如下面的代码所示。- #001 Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
- #002 Private Declare Function DrawMenuBar Lib "user32" (ByVal hWnd As Long) As Long
- #003 Private Declare Function SetFocus Lib "user32" (ByVal hWnd As Long) As Long
- #004 Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hWnd As Long, ByVal wMsg As Long, ByVal wParam As Integer, ByVal lParam As Long) As Long
- #005 Private Declare Function ExtractIcon Lib "shell32.dll" Alias "ExtractIconA" (ByVal hInst As Long, ByVal lpszExeFileName As String, ByVal nIconIndex As Long) As Long
- #006 Private Const WM_SETICON = &H80
- #007 Private Sub Workbook_Open()
- #008 Dim IStyle As Long
- #009 Dim hIcon As Long
- #010 Dim hWndForm As Long
- #011 hWndForm = FindWindow(vbNullString, Application.Caption)
- #012 hIcon = ExtractIcon(0, ActiveWorkbook.Path & "\p.bmp", 0)
- #013 SendMessage hWndForm, WM_SETICON, True, hIcon
- #014 SendMessage hWndForm, WM_SETICON, False, hIcon
- #015 End Sub
复制代码 代码解析:
工作簿打开后使用API函数自定义工作簿标题栏的图标。
第1行到第6行代码,API函数声明。
第7行到第15行代码,工作簿的Open事件过程,把工作簿标题栏默认的图标更改为同一文件夹下的p.bmp图片。
工作簿打开后标题栏如图所示。
任务栏图标如图所示。
|
|