【发布时间】:2016-01-16 21:50:57
【问题描述】:
在一个 VB6 应用程序中,我正在检查某个 VB.NET WinForms 窗口是否存在:
Public Declare Function IsWindow Lib "user32" (ByVal hwnd As Long) As Long
If Not IsWindow(102937) Then
MessageBox("Window not found!")
End If
消息框已显示,但窗口确实存在。
我检查它通过
Debug.Print(Me.Handle.ToInt32)'it prints 102937
这里出了什么问题? 我是否可能错误地处理了“IsWindow”的返回值?
谢谢。
【问题讨论】:
-
A thread should not use IsWindow for a window that it did not create because the window could be destroyed after this function was called. Further, because window handles are recycled the handle could even point to a different window. -
你的窗口句柄很奇怪?真的吗?
-
正如 Bob77 在评论中指出的,这段代码显然是 VB6(不是 VB.NET)。在这种情况下,Long data type 实际上是 32 位,函数签名应该没问题。
-
我没有检查 VB.NET。我正在检查 VB6。而且我确实使用该功能来查看窗口是否仍然存在。我经常做这个检查,所以窗口句柄被回收的机会不是很大。
标签: vb.net winapi vb6 window-handles