1 Process[] procs = Process.GetProcessesByName("Maxthon"); 2 if (procs.Length == 0) 3 { 4 return null; 5 } 6 List<string> titles = new List<string>(); 7 IntPtr hWnd = IntPtr.Zero; 8 foreach (Process p in procs) 9 { 10 if (p.MainWindowTitle.Length > 0) 11 { 12 hWnd = p.MainWindowHandle; 13 break; 14 } 15 } 16 17 IntPtr parentPtr = IntPtr.Zero; 18 IntPtr childPtr = IntPtr.Zero; 19 StringBuilder sb = new StringBuilder(256); 20 21 while (true) 22 { 23 parentPtr = FindWindowEx(IntPtr.Zero, parentPtr, "Maxthon3Cls_MainFrm", null); 24 if (parentPtr == IntPtr.Zero) break; 25 while (true) 26 { 27 childPtr = FindWindowEx(parentPtr, childPtr, "Maxthon3Cls_BrowserView", null); 28 if (childPtr == IntPtr.Zero) break; 29 sb.Length = 0; 30 if (IsWindowVisible(childPtr)) 31 { 32 GetWindowText(childPtr, sb, 256); 33 titles.Add(sb.ToString()); 34 } 35 } 36 } 37 var s = ""; 38 for (int i = 0; i < titles.Count; i++) 39 { 40 s = string.Format("{0}. {1}\n", i + 1, titles[i]); 41 }
[DllImport("user32.dll", SetLastError = true)] static extern IntPtr FindWindowEx(IntPtr hwndParent, IntPtr hwndChildAfter, string lpszClass, string lpszWindow);
我需要获得maxthon、360等浏览器子窗口title。
用UI Spy查看, maxthon云浏览器竟然变化无常……新开的选项卡, 有时能在节点树看到title, 有时却跑到了几级下面,多出很多空节点, 要切换下内核才能正确获得子窗口句柄。
我一层一层找, 竟然死活不返回title。 求高手赐教!
自己解决了, 没人回答, 高手们是不是都很忙? 博客园, 还我的豆豆……囧