C# 源代碼,通過API實現跨進程得到浏覽器對象,然後就可以進行下一步操作。
1 using System;
2 using System.Runtime.InteropServices;
3 using mshtml;
4
5 class Win32API {
6 [DllImport("user32.dll", EntryPoint = "FindWindow")]
7 public static extern IntPtr FindWindow(string lpClassName, string lpWindowName);
8 [DllImport("user32.dll", EntryPoint = "FindWindowEx")]
9 public static extern IntPtr FindWindowEx(IntPtr hwndParent, IntPtr hwndChildAfter, string lpszClass, string lpszWindow);
10 [DllImport("user32.dll", SetLastError = true, CharSet = CharSet.Auto)]
11 public static extern uint RegisterWindowMessage(string lpString);
12 [DllImport("oleacc.dll", PreserveSig = false)]
13 [return: MarshalAs(UnmanagedType.Interface)]
14 public static extern object ObjectFromLresult(UIntPtr lResult, [MarshalAs(UnmanagedType.LPStruct)] Guid refiid, IntPtr wParam);
15 [DllImport("user32.dll", SetLastError = true, CharSet = CharSet.Auto)]
16 public static extern IntPtr SendMessageTimeout(IntPtr hWnd, uint Msg, UIntPtr wParam, IntPtr lParam, SendMessageTimeoutFlags fuFlags, uint uTimeout, out UIntPtr lpdwResult);
17
18 public enum SendMessageTimeoutFlags : uint {
19 SMTO_NORMAL =