c# web 消息控件
c# web message control
我正在创建一个社区站点 post 移除程序。
我在完成几乎所有这个程序时遇到了一个问题,但每次我尝试删除一个 post 时,我都会在网络上打开一个网络消息并检查我是否真的要删除它。
web messagebox
每当显示网络消息时,按回车键或用鼠标按确定按钮。
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
}
}
我想让这项工作自动进行。
所以我尝试了下面的代码,但它没有用,我没有更多的想法。
那么,有什么不同的方法来控制网络消息吗?
好的...我终于解决了
first-to 使用控制网页消息框
使用 user32.dll 和 spy++
我用user32.dll控制网页消息,用spy++提取网页消息的按钮值。
使用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;
}
}
}
}
}
}
}
但该代码不起作用。这是因为线程在网页消息弹出的那一刻被挂起。
所以,一旦我用多线程启动程序,我就保留了 运行 上面的代码并且它运行良好。
我正在创建一个社区站点 post 移除程序。 我在完成几乎所有这个程序时遇到了一个问题,但每次我尝试删除一个 post 时,我都会在网络上打开一个网络消息并检查我是否真的要删除它。 web messagebox
每当显示网络消息时,按回车键或用鼠标按确定按钮。
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
}
}
我想让这项工作自动进行。 所以我尝试了下面的代码,但它没有用,我没有更多的想法。 那么,有什么不同的方法来控制网络消息吗?
好的...我终于解决了
first-to 使用控制网页消息框 使用 user32.dll 和 spy++
我用user32.dll控制网页消息,用spy++提取网页消息的按钮值。 使用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;
}
}
}
}
}
}
}
但该代码不起作用。这是因为线程在网页消息弹出的那一刻被挂起。 所以,一旦我用多线程启动程序,我就保留了 运行 上面的代码并且它运行良好。