我意识到这是一个非常具体的问题,在这种情况之外并没有什么帮助,尽管我确信它适用于其他问题。我有一个递归搜索窗口(及其子窗口)的函数来查找特定的函数,它的工作原理与预期完全相同,但它会导致“函数不会在所有路径上返回值”警告。这是我整个程序中唯一的警告,虽然它可能很愚蠢,但我有兴趣知道是否有办法阻止这种错误发生,但仍然允许该功能正常工作。如何让此函数不会生成“不会返回所有路径上的值”警告?
Public Function FindQWidgetWindows() As Integer
Dim hWndStart As Integer = 0
Dim WindowText As String = "*"
Dim Classname As String = "QWidget"
Dim hwnd As Integer
Dim sWindowText As String
Dim sClassname As String
Dim r As Integer
Static level As Integer
If level = 0 Then
If hWndStart = 0 Then hWndStart = GetDesktopWindow()
End If
level = level + 1
hwnd = GetWindow(hWndStart, GW_CHILD)
Do Until hwnd = 0
Call FindQWidgetWindows()
'Get the window text and class name'
sWindowText = Space$(255)
r = GetWindowText(hwnd, sWindowText, 255)
sWindowText = Microsoft.VisualBasic.Left(sWindowText, r)
sClassname = Space$(255)
r = GetClassName(hwnd, sClassname, 255)
sClassname = Microsoft.VisualBasic.Left(sClassname, r)
If (sWindowText Like WindowText) And (sClassname Like Classname) Then
Dim aRECT As RECT
Dim hwndInt As Int32 = hwnd
GetWindowRect(hwndInt, aRECT)
FindQWidgetWindows = hwnd
'uncommenting the next line causes the routine to'
'only return the first matching window.'
'Exit Do'
End If
hwnd = GetWindow(hwnd, GW_HWNDNEXT)
Loop
level = level - 1
End Function
让我给你的意见作出回应,并澄清。首先,感谢您的回答。但是,我明白为什么会发出警告,我只是无法解决警告。 @paxdiablo - 是的,但如果我把它作为一个子,它不会工作 - 事实上它会返回一行“FindQWidgetWindows = hwnd” @Shoban上的错误,这是我想要的行为,如果它发现一个窗口它返回的值,如果它不应该返回任何东西(或者,我想应该是没有返回) – 2010-10-22 06:28:19