리눅스맨

c# webbrowser stackoverflow message from webpage

Background Image
1,000만원 수익
Overlay Image

웹 페이지 메시지 강제로 클릭하게 만들어서 없애기

c# webbrowser stackoverflow message auto click!!

 

code

 



const int BM_CLICK = 0xF5;
const uint WM_ACTIVATE = 0x6;
const int WA_ACTIVE = 1;


[DllImport("User32.dll")]
public static extern IntPtr FindWindow(String lpClassName, String lpWindowName);

[DllImport("user32.dll", SetLastError = true)]
private static extern IntPtr FindWindowEx(IntPtr hwndParent, IntPtr hwndChildAfter, string className, string lpszWindow);

[DllImport("user32.dll", CharSet = CharSet.Auto)]
static extern IntPtr SendMessage(IntPtr hWnd, UInt32 Msg, int wParam, int lParam);





public void 웹페이지메시지클릭()
{

List<string> MessageName = new List<string>();
List<string> ButtonName = new List<string>();

//Your MessageBox subject titles
MessageName.Add("웹 페이지 메시지");
MessageName.Add("웹 페이지의 메시지");
MessageName.Add("Message from webpage");

//Your MessageBox button titles
ButtonName.Add("확인");
ButtonName.Add("예");
ButtonName.Add("OK");

foreach(string message in MessageName)
{
var hwnd = FindWindow("#32770", message);
if (hwnd != IntPtr.Zero)
{
foreach (string button in ButtonName)
{
var btn = FindWindowEx(hwnd, IntPtr.Zero, "Button", button);
if (btn != IntPtr.Zero)
{
SendMessage(btn, WM_ACTIVATE, WA_ACTIVE, 0);
SendMessage(btn, BM_CLICK, 0, 0);
}
} 
}
}


}

메시지 박스창의 네이밍을 직접 적어넣으면 관련한 메시지 창이 모두 강제로 클릭됩니다.

다른 방법으로 애시당초 창을 뜨지않도록 하고 싶었지만 시스템 메시지창의경우에는 제어하기가 쉽지 않아 띄어진 메시지를 강제로 클릭하여 없애는 방법으로 프로그래밍을 하였습니다.

 

일단 장점이라면 관련 창이 나오더라도 타이머 지정을 해놓게되면 주기적으로 창을 자동으로 클릭하여 창이 닫히게됩니다.

 

Background Image
1,000만원 수익
Overlay Image

게시됨

카테고리

작성자

태그: