- 积分
- 10513
- 明经币
- 个
- 注册时间
- 2002-6-3
- 在线时间
- 小时
- 威望
-
- 金钱
- 个
- 贡献
-
- 激情
-
|
发表于 2003-10-23 11:42:00
|
显示全部楼层
用下面的代码可以实现,在VB中直接使用窗体的Hwnd,而不需要GetActiveWindow获取当前活动窗口的句柄。
不过有个问题,在VBA中的标题前面部分被遮住了。
- Private Declare Function GetActiveWindow Lib "user32" () As Long
- 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
- Private Const WM_SETICON = &H80
- Private Const IMAGE_ICON = 1
- Private Const LR_LOADFROMFILE = &H10
- Private Sub UserForm_Activate()
- Dim Hwnd As Long
- Hwnd = GetActiveWindow
- Dim hIcon As Long
- hIcon = LoadImage(0&, "c:\光缆.ico", IMAGE_ICON, 16, 16, LR_LOADFROMFILE)
- If hIcon <> 0 Then
- Call SendMessage(Hwnd, WM_SETICON, 0, ByVal hIcon)
- End If
- End Sub
|
|