EnumWindows 使用的问题
我需要实现这样一个控件,以便可以设定窗口标题为 “test1"的IE窗口的置顶
,以下是我的actciveX控件 的全部代码。
但是我编译的时候 在 EnumWindows AddressOf EnumWindowsProc, 0& 总是出错。
我过去没有写过activeX 这个程序也很简单。
请高手帮我看看。
问题出在哪儿了?
谢谢
'引用相关的api
Private Declare Function SetWindowPos Lib "user32" (ByVal hWnd As Long,
ByVal hWndInsertAfter As Long, ByVal X As Long, ByVal Y As Long, ByVal cx As
Long, ByVal cy As Long, ByVal wFlags As Long) As Long
Private Declare Function GetWindowText Lib "user32" Alias "GetWindowTextA"
(ByVal hWnd As Long, ByVal lpString As String, ByVal cch As Long) As Long
Private Declare Function EnumWindows Lib "user32" (ByVal lpEnumFunc As Long,
ByVal LParam As Long) As Long
Private Const SWP_NOSIZE = &H1
Private Const SWP_NOMOVE = &H2
Private Const SWP_NOZORDER = &H4
Private Const SWP_NOREDRAW = &H8
Private Const SWP_NOACTIVATE = &H10
Private Const SWP_FRAMECHANGED = &H20
Private Const SWP_SHOWWINDOW = &H40
Private Const SWP_NOCOPYBITS = &H80
Private Const SWP_NOOWNERZORDER = &H200
Private Const SWP_DRAWFRAME = SWP_FRAMECHANGED
Private Const SWP_NOREPOSITION = SWP_NOOWNERZORDER
Private Const HWND_TOP = 0
Private Const HWND_BOTTOM = 1
Private Const HWND_TOPMOST = -1
Private Const HWND_NOTOPMOST = -2
Private Sub UserControl_Initialize()
EnumWindows AddressOf EnumWindowsProc, 0&
End Sub
'自定义函数 获取句柄的窗体名称
Private Function GetWindowTextBa(ByVal hWnd As Long) As String
Dim lngReturn As Long
Dim strReturn As String
strReturn = Space(255)
lngReturn = GetWindowText(hWnd, strReturn, Len(strReturn))
GetWindowTextBa = Left(strReturn, lngReturn)
End Function
Public Function EnumWindowsProc(ByVal hWnd As Long, ByVal LParam As Long) As
Boolean
Dim sTitle As String
sTitle = GetWindowTextBa(hWnd)
If InStr(sTitle, "test1") > 0 Then
Dim retValue As Long
'retValue = SetWindowPos(hWnd, HWND_TOPMOST, 0, 0, 300, 300,
SWP_SHOWWINDOW)
EnumWindowsProc = True
End If
EnumWindowsProc = False
End Function