獲得IHTMLDocument2

2019-05-24 行業動態 haoservcie

  private void button4_Click(object sender, EventArgs e)
        {
              IntPtr ParenthWndldsl = new IntPtr(0);
               IntPtr EdithWnd = new IntPtr(0);
               Thread.Sleep(200);
               ParenthWndldsl = FindWindow(null, "電話服務平臺1.01 - [歡迎使用]");

               if (!ParenthWndldsl.Equals(IntPtr.Zero))
               {
                   //得到User Name這個子窗體,并設置其內容
                   EdithWnd = FindWindowEx(ParenthWndldsl, IntPtr.Zero, "MDIClient", "");
                   IntPtr e1 = FindWindowEx(EdithWnd, IntPtr.Zero, "TForm_welcome", "歡迎使用");
                   IntPtr e2 = FindWindowEx(e1, IntPtr.Zero, "Shell Embedding", "");
                   IntPtr e3 = FindWindowEx(e2, IntPtr.Zero, "Shell DocObject View", "");
                   IntPtr e4 = FindWindowEx(e3, IntPtr.Zero, "Internet Explorer_Server", "");

 

 


                    mshtml.IHTMLDocument2 id = getIEWindowDocument(int.Parse(e4.ToString()));//上邊代碼是獲得句柄的
               IHTMLElementCollection links = id.links;
               foreach (mshtml.IHTMLElement k in links)
               {
                  // mshtml.HTMLAnchorElementClass ks = k.GetType();
                 //  string aa = ((mshtml.HTMLAnchorElementClass)(k)).href;
                   string aaa = k.outerHTML;//這個是指定單擊
                   if (aaa=="<AREA title=電話受理 href="+"\"$dhsl\""+" shape=rect coords=188,137,251,210>")
                   {
                       k.click();
                   }
                   //mshtml.HTMLAnchorElementClass ks = (mshtml.HTMLAnchorElementClass)(k);
                 
               }

                  
               }
              
        }

 

  class Win32API
        {
            [DllImport("User32.dll")] //User32.dll是Windows操作系統的核心動態庫之一
            public static extern int FindWindow(string lpClassName, string lpWindowName);


            [DllImport("user32", EntryPoint = "RegisterWindowMessage")]
            public static extern int RegisterWindowMessage(
                    string lpString
            );

            [DllImport("user32", EntryPoint = "SendMessage")]
            public static extern int SendMessage(
                    int hwnd,
                    int wMsg,
                    int wParam,
                    ref int lParam
            );

            [DllImport("OLEACC.DLL", EntryPoint = "ObjectFromLresult")]
            public static extern int ObjectFromLresult(
            int lResult,
            ref System.Guid riid,
            int wParam,
            [System.Runtime.InteropServices.MarshalAs(UnmanagedType.Interface), System.Runtime.InteropServices.In, System.Runtime.InteropServices.Out]ref System.Object ppvObject
                //注意這個函數ObjectFromLresult的聲明.
            );
        }


      
            public mshtml.IHTMLDocument2 getIEWindowDocument(int jubing)
            {
                System.Object domObject = new System.Object();
                int tempInt = 0;
                System.Guid guidIEDocument2 = new Guid(); //應該是IHTMLDocument2的接口id
                int WM_Html_GETOBJECT = Win32API.RegisterWindowMessage("WM_Html_GETOBJECT");


                //開始查找指定的ie窗體
                int hwnd = jubing;

                int W = Win32API.SendMessage(hwnd, WM_Html_GETOBJECT, 0, ref tempInt);
                int lreturn = Win32API.ObjectFromLresult(W, ref guidIEDocument2, 0, ref domObject);
                mshtml.IHTMLDocument2 doc = (mshtml.IHTMLDocument2)domObject;

                //MessageBox.Show(doc.toString());
                MessageBox.Show("到這里2");
                MessageBox.Show(doc.url);
                MessageBox.Show(doc.title);

                return doc;
            }

聯系客服

010-58436659

天天捕鱼电玩城正版赢话费
快乐12最大遗漏数据 最新版中国体彩app官方下载 快乐3分彩开奖结果 时时彩前三后三一码定胆 体彩开奖时间是星几 sg飞艇计划软件 2019年六合采今晚开奖结 安徽快三走势图遗漏 上海时时查结果查询 24481香港赛马会 澳客网论坛 票内蒙古时时 江西快3走势图360 广东时时玩法说明 云南快乐十分复试金额表 福彩快乐十二开奖走势图