EnumWindows 使用的问题

juleson138 2004-08-25 04:03:53
我需要实现这样一个控件,以便可以设定窗口标题为 “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

...全文
228 12 打赏 收藏 转发到动态 举报
写回复
用AI写文章
12 条回复
切换为时间正序
请发表友善的回复…
发表回复
sakurako 2004-08-27
  • 打赏
  • 举报
回复
建议使用FindWindow函数
另外,子类要放在模块中哦
zyl910 2004-08-27
  • 打赏
  • 举报
回复
但是有一个问题啊 就是 调用EnumWindows AddressOf EnumWindowsProc, 0&
好像只执行了一次?没有遍历所有的窗口吗?
-------------------------
EnumWindowsProc的返回值设为True!
EnumWindows只是遍里所有顶层窗口




但是 由于这个属性WindowTitleName需要在 Module中使用,
如何使用啊??
--------------------------
使用全局变量




还是推荐FindWindow、FindWindowEx
它们没有EnumWindow麻烦
juleson138 2004-08-27
  • 打赏
  • 举报
回复
帮我看看阿
高手们
terry6394 2004-08-26
  • 打赏
  • 举报
回复
用findwindowex可以遍历的.可以达到搂住说的目的
juleson138 2004-08-26
  • 打赏
  • 举报
回复
好了 搞定了
juleson138 2004-08-26
  • 打赏
  • 举报
回复
to:BlueBeer(1win) ( )
用GetWindow 也可以,但是你能告诉我如何用getwindow遍历所有的窗口吗?
因为 我只能知道窗口标题可能包含 “test”,因为IE窗口的标题很奇怪
有时候有microsoft internal explorer,有时候没有。
这样的话 我如果用getwindow 也只是找到窗口类为 IEFrame的 然后遍历比较窗口标题
谢谢。

juleson138 2004-08-26
  • 打赏
  • 举报
回复
to:goodname008(卢培培,充电中......)
你说得很对 我放到 模块以后编译不出错了
但是 有个问题啊

但是有一个问题啊 就是 调用EnumWindows AddressOf EnumWindowsProc, 0&
好像只执行了一次?没有遍历所有的窗口吗?
这些代码我也是动拼西凑的。
我上面的代码不能够实现 当窗口名称类似于test1 的时候 设定 这个窗口的位置置顶?
谢谢你的帮助。
juleson138 2004-08-26
  • 打赏
  • 举报
回复
请问如何 在使用一个属性
下面的代码是 在空间中定义了一个属性
但是 由于这个属性WindowTitleName需要在 Module中使用,
如何使用啊??
在模块使用的时候 一直是empty
谢谢。

'WARNING! DO NOT REMOVE OR MODIFY THE FOLLOWING COMMENTED LINES!
'MemberInfo=13,0,0,事务提醒
Public Property Get WindowTitleName() As String
WindowTitleName = m_WindowTitleName
End Property

Public Property Let WindowTitleName(ByVal New_WindowTitleName As String)
m_WindowTitleName = New_WindowTitleName
PropertyChanged (WindowTitleName)
End Property

'Initialize Properties for User Control
Private Sub UserControl_InitProperties()
m_WindowTitleName = m_def_WindowTitleName

End Sub

'Load property values from storage
Private Sub UserControl_ReadProperties(PropBag As PropertyBag)

m_WindowTitleName = PropBag.ReadProperty("WindowTitleName", m_def_WindowTitleName)
End Sub

'Write property values to storage
Private Sub UserControl_WriteProperties(PropBag As PropertyBag)

Call PropBag.WriteProperty("WindowTitleName", m_WindowTitleName, m_def_WindowTitleName)
End Sub
goodname008 2004-08-26
  • 打赏
  • 举报
回复
楼主把retValue = SetWindowPos(hWnd, HWND_TOPMOST, 0, 0, 300, 300, SWP_SHOWWINDOW)注释了。
当然不能置顶了,现在搞定了就好。 :D
BlueBeer 2004-08-25
  • 打赏
  • 举报
回复
窗口标题是固定的干嘛不用FindWindow???
goodname008 2004-08-25
  • 打赏
  • 举报
回复
EnumWindowsProc函数(回调函数)要放在标准模块里。 :D
starsoulxp 2004-08-25
  • 打赏
  • 举报
回复
帮你顶。

1,486

社区成员

发帖
与我相关
我的任务
社区描述
VB API
社区管理员
  • API
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧