I'm creating a community site post remover. I have encountered a problem while completing almost all of this program, but every time I try to delete a post, I open a web message on the web and check if I really want to delete it. web messagebox
Whenever the web message is displayed, press the Enter key or press the OK button with the mouse.
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
}
}
I want to make that work automatic. So I tried the following code but it did not work and I do not have any more ideas. So, is there any way to control web messages differently?
Ok...finally i solved it
first-to use control a web message box used user32.dll and spy++
I used the user32.dll to control the web message and extracted the button value of the web message using spy ++. The source code of the web message control using user32.dll is as follows.
[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;
}
}
}
}
}
}
}
But that code does not work. This is because the thread is suspended at the moment the web message pops up. So, as soon as I started the program with multithreading, I kept running the above code and it worked fine.