獲得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

天天捕鱼电玩城正版赢话费
金彩 百人炸金花规则 国外苹果id有什么好处 压单双技巧 时时彩历史开奖结果查询 聚星娱乐入口 重庆老是彩开奖号码 重庆欢乐生肖开奖号码 排列三4码组六遗漏 斗牛看牌抢庄计算器 时时彩包胆什么意思 mg游戏 米兰有什么 时时彩历史开奖结果查询 吉林时时开奖查询 3d胆拖投注怎么算中奖