You make it!
成功了!
谢谢版主和宇宙青年!我可以继续下一步工作了!
(我写测试代码的时候习惯用VB.NET……)
Private Function FindPhoneHandle() As Integer
Dim lpForeground As Integer = 0
Dim lpNextWindow As Integer = 0
FindPhoneHandle = 0
Dim lpClassName As New StringBuilder("", 50)
lpForeground = GetForegroundWindow
If lpForeground = 0 Then Return 0
lpNextWindow = GetWindow(lpForeground, GW_CHILD)
lpNextWindow = GetWindow(lpNextWindow, GW_HWNDFIRST)
Do Until lpNextWindow = 0
GetClassName(lpNextWindow, lpClassName, lpClassName.Capacity)
If Trim(lpClassName.ToString.Replace(vbNullChar, "")) = "MS_PHONE_BRANDING" Then
Return lpForeground
End If
lpNextWindow = GetWindow(lpNextWindow, GW_HWNDNEXT)
Loop
End Function
测试结果:
[22:59:52] msg.message:275
[22:59:52] Main Handle:2080989168,ClassName:ToolbarWindow32
[22:59:52] Main Handle:2080989168,ClassName:ATL:01F6B6C8
[22:59:52] Main Handle:2080989168,ClassName:static
[22:59:53] msg.message:275
[22:59:53] Main Handle:2080989168,ClassName:ToolbarWindow32
[22:59:53] Main Handle:2080989168,ClassName:ATL:01F6B6C8
[22:59:53] Main Handle:2080989168,ClassName:static
[22:59:54] msg.message:275
[22:59:54] Main Handle:2080855248,ClassName:SysListView32
[22:59:54] Main Handle:2080855248,ClassName:MS_PHONE_LAYOUTHELPER
[22:59:54] Main Handle:2080855248,ClassName:MS_PHONE_INVALIDPHONE [22:59:54] Main Handle:2080855248,ClassName:MS_PHONE_BRANDING
[22:59:54] Main Handle:2080855248,ClassName:MS_PHONE_BRANDING,Found!!!!
[23: 0: 1] msg.message:275
[23: 0: 1] Main Handle:2080894096,ClassName:MS_PHONE_LAYOUTHELPER
[23: 0: 1] Main Handle:2080894096,ClassName:MS_PHONE_INVALIDPHONE
[23: 0: 1] Main Handle:2080894096,ClassName:MS_PHONE_BRANDING
[23: 0: 1] Main Handle:2080894096,ClassName:MS_PHONE_BRANDING,Found!!!!
[23: 0: 2] msg.message:275
[23: 0: 2] Main Handle:2080989168,ClassName:ToolbarWindow32
[23: 0: 2] Main Handle:2080989168,ClassName:ATL:01F6B6C8
[23: 0: 2] Main Handle:2080989168,ClassName:static
[23: 0: 3] msg.message:275
[23: 0: 3] Main Handle:2080989168,ClassName:ToolbarWindow32
[23: 0: 3] Main Handle:2080989168,ClassName:ATL:01F6B6C8
[23: 0: 3] Main Handle:2080989168,ClassName:static
[23:14:43] Main Handle:2080894096,ClassName:MS_PHONE_LAYOUTHELPER
[23:14:43] Main Handle:2080894096,ClassName:MS_PHONE_INVALIDPHONE
[23:14:43] Main Handle:2080894096,ClassName:MS_PHONE_BRANDING
[23:14:43] Main Handle:2080894096,ClassName:MS_PHONE_LAYOUTHELPER
[23:14:43] Main Handle:2080894096,ClassName:MS_PHONE_STATUSICONS
[23:14:43] Main Handle:2080894096,ClassName:MS_PHONE_CALLSTATE
[23:14:43] Main Handle:2080894096,ClassName:MS_PHONE_ELAPSEDTIME
[23:14:43] Main Handle:2080894096,ClassName:MS_PHONE_ELAPSEDTIME,Found!!!!