[WebBrowser] automatically click website advertisement C #

Source: Internet
Author: User

I. How to Set proxy IP Address

Public struct Struct_INTERNET_PROXY_INFO
{
Public int dwAccessType;
Public IntPtr proxy;
Public IntPtr proxyBypass;
};

[DllImport ("wininet. dll", SetLastError = true)]
Private static extern bool InternetSetOption (IntPtr hInternet, int dwOption, IntPtr lpBuffer, int lpdwBufferLength );

Public static void RefreshIESettings (string strProxy)
{
Const int INTERNET_OPTION_PROXY = 38;
Const int INTERNET_OPEN_TYPE_PROXY = 3;
Struct_INTERNET_PROXY_INFO struct_IPI;
// Filling in structure
Struct_IPI.dwAccessType = INTERNET_OPEN_TYPE_PROXY;
Struct_IPI.proxy = Marshal. StringToHGlobalAnsi (strProxy );
Struct_IPI.proxyBypass = Marshal. StringToHGlobalAnsi ("local ");
// Allocating memory
IntPtr intptrStruct = Marshal. AllocCoTaskMem (Marshal. SizeOf (struct_IPI ));
// Converting structure to IntPtr
Marshal. StructureToPtr (struct_IPI, intptrStruct, true );
Bool iReturn = InternetSetOption (IntPtr. Zero, INTERNET_OPTION_PROXY, intptrStruct, Marshal. SizeOf (struct_IPI ));
}

Ii. Determine whether the web page is loaded by webBrowser

Private int _ IsLoadedCounter = 0;

This. webBrowser1.Navigated + = new

System. Windows. Forms. WebBrowserNavigatedEventHandler (webBrowser1_Navigated );

This. webBrowser1.DocumentCompleted + = new WebBrowserDocumentCompletedEventHandler (webBrowser1_DocumentCompleted );

Private void webbrowserappsdocumentcompleted (object sender, WebBrowserDocumentCompletedEventArgs e)
{
This. _ IsLoadedCounter --;
If (this. _ IsLoadedCounter <= 0)
{
This. Text = "success"; // Loading completed
This. _ IsLoadedCounter = 0;
}

}

Private void webbrowserinclunavigated (object sender, WebBrowserNavigatedEventArgs e)
{
This. _ IsLoadedCounter ++;
}

3. How to set and obtain the position of the webBrowser scroll bar

Set

This. webBrowser1.Document. Window. ScrollTo (scrollx, scrolly );

Obtain

Mshtml. HTMLDocument doc = (mshtml. HTMLDocument) this. webBrowser1.Document. DomDocument;
String content = String. Empty;
Int sx = (int)doc.doc umentElement. getAttribute ("scrollLeft", 0 );
Int sy = (int)doc.doc umentElement. getAttribute ("scrollTop", 0 );

How to reference mshtml, you can go to the Internet GG

4. If you set the mouse position and double-click

Class Library

Public static readonly int MOUSEEVENTF_LEFTDOWN = 0x2;
Public static readonly int MOUSEEVENTF_LEFTUP = 0x4;
Public static readonly int MOUSEEVENTF_MIDDLEDOWN = 0x20;
Public static readonly int MOUSEEVENTF_MIDDLEUP = 0x40;
Public static readonly int MOUSEEVENTF_MOVE = 0x1;
Public static readonly int MOUSEEVENTF_ABSOLUTE = 0x8000;
Public static readonly int MOUSEEVENTF_RIGHTDOWN = 0x8;
Public static readonly int MOUSEEVENTF_RIGHTUP = 0x10;

[DllImport ("user32.dll")]
Public static extern int GetCursorPos (ref PONITAPI p );

[DllImport ("user32.dll")]
Public static extern int SetCursorPos (int x, int y );

[DllImport ("user32.dll")]
Public static extern int mouse_event (int dwFlags, int dx, int dy, int cButtons, int dwExtraInfo );

Set the IE scroll bar position

This. webBrowser1.Document. Window. ScrollTo (scrollx, scrolly );

Set the mouse position

MouseControl. SetCursorPos (pointx, pointy );
Double-click

MouseControl. mouse_event (MouseControl. MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0 );
MouseControl. mouse_event (MouseControl. MOUSEEVENTF_LEFTUP, 0, 0, 0, 0 );

Source to [Hundred trees]: webBrowser Enables automatic website advertisement clicking through proxy IP Address
Http://www.bmpj.net/forum-viewthread-tid-219-fromuid-26.html

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.