繁体   English   中英

C#Web邮件控件

[英]c# web message control

我正在创建一个社区站点帖子删除器。 在完成几乎所有该程序时,我都遇到了问题,但是每次尝试删除帖子时,我都会在网上打开一条网络消息,并检查我是否真的要删除它。 网络消息框

每当显示网络消息时,请按Enter键或用鼠标按OK键。

                for (int i = 0; i < arr.Length;i++)
            {
                System.Windows.Forms.HtmlDocument Doc = web.Document;
                Delay(1000);//1second
                for (int q = 0; q < Doc.GetElementsByTagName("div").Count; q++)
                    if (Doc.GetElementsByTagName("div")[q].GetAttribute("article-id") == arr[i])//Only delete posts that match the article-id
                    {
                        Doc.GetElementsByTagName("div")[q].InvokeMember("Click");//Click Delete Post
                        web.Focus();
                        SendKeys.Send("{ENTER}");//Send Enter to web message
                    }
            }

我想使这项工作自动化。 因此,我尝试了以下代码,但是它不起作用,并且我没有更多的想法。 那么,有什么方法可以不同地控制Web消息吗?

好的...我终于解决了

首次使用控制使用user32.dll和spy ++的Web消息框

我使用user32.dll来控制Web消息,并使用间谍++提取了Web消息的按钮值。 使用user32.dll的Web消息控件的源代码如下。

    [DllImport("user32.dll")]
    public static extern int FindWindowEx(int hWnd1, int hWnd2, string lpsz1, string lpsz2);

    [DllImport("user32.dll")]
    public static extern int FindWindow(string lpClassName, string lpWindowName);

    [DllImport("user32.dll")]
    public static extern int SendMessage(int hWnd, int Msg, int wParam, int lParam);

    public class messagebox_control
    {
        const int WM_LBUTTONDOWN = 0x2201;
        const int WM_LBUTTONUP = 0x0202;
        const int BM_CLICK = 0x00F5;

        public void Click_message()
        {
            int nhwnd = FindWindow("#32770", "웹 페이지 메시지");
            if(nhwnd>0)
            {
                int hw1 = FindWindowEx(nhwnd, 0, "DirectUIHWND", "");
                if(hw1>0)
                {
                    int hw2 = FindWindowEx(hw1, 0, "CtrlNotifySink", "");
                    if(hw2>0)
                    {
                        while(true)
                        {
                            int hw3 = FindWindowEx(hw2, 0, "Button", "확인");
                            if (hw3>0)
                            {
                                SendMessage(hw3, BM_CLICK, 0, 1);
                                break;
                            }
                            hw2 = FindWindowEx(hw1, hw2, "CtrlNotifySink", "");
                            if (hw2==0)
                            {
                                break;
                            }
                        }
                    }
                }
            }
        }
}

但是该代码不起作用。 这是因为线程在Web消息弹出时被挂起。 因此,一旦我使用多线程启动程序,我就继续运行上面的代码,并且运行良好。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM