C # winform getting the browser address code (multiple methods of adding to favorites)

Source: Internet
Author: User

System.Appdomain objapdom =System.Appdomain. currentdomain;
Object OBJ = objapdom. getdata ("app_launch_url ");

 

Value of "name" Attribute
"Appbase" Applicationbase
"App_config_file" Configurationfile
"Dynamic_base" Dynamicbase
"Dev_path" (No attribute)
"App_name" Applicationname
"Cache_base" Privatebinpath
"Binpath_probe_only" Privatebinpathprobe
"Shadow_copy_dirs" Shadowcopydirectories
"Force_cache_install" Shadowcopyfiles
"Cache_base" Cachepath
(ApplicationProgramSpecific) Licensefile

ErrorCode:
// Application domain
System.Appdomain objapdom =System.Appdomain. currentdomain;
Object OBJ = objapdom. getdata ("app_launch_url ");

If (OBJ = NULL)
{
Strurl = "";
}
Else
{
Strurl = obj. tostring ();
}

 

 

First, import c: \ windows \ system32 \Mshtml. TLB,InterOP. shdocvw. dllTwo dynamic library files
 

-Shrink C # Code /// <Summary>
/// Return the ihtmldocument2 object in the IE window of the specified URL.
/// </Summary>
/// <Returns> ihtmldocument2 </returns>
Public Static Ihtmldocument2 getihtmldocument2byurl ( String URL)
{
Shdocvw. shellwindows = New Shdocvw. shellwindowsclass ();
Foreach (Shdocvw. internetexplorer IE In Shellwindows)
{
String Filename = system. Io. Path. getfilenamewithoutextension (ie. fullname). tolower ();
If (Filename. Equals ( "Iexplore" ) & Ie. locationurl = URL)
{
Return Ie. Document As Ihtmldocument2;
}
}
}

You can use the getihtmldocument2byurl method to obtain the ihtmldocument2 object in the window with the address specified in the opened ie window.

With this object, you can perform related operations.

1. Fill in the form

-Shrink C # Code ihtmldocument2 ihtmldocument2 = getihtmldocument2byurl ( Http://www.163.com" );
Ihtmlinputelement input = (ihtmlinputelement) ihtmldocument2.all. Item ( "Username" , 0 ); // Obtain the object with the specified name
Input. Value = "Xiao" ; // Assign a value

2. click the button

-Shrink C # Code ihtmldocument2 ihtmldocument2 = getihtmldocument2byurl ( Http://www.163.com" );
Htmldocumentclass OBJ = (htmldocumentclass) ihtmldocument2;
Ihtmlelement = Null ;
Ihtmlelementcollection c = obj. getelementsbytagname ( "Input" );
Foreach (Ihtmlelement E In C)
{
If (E. outerhtml. indexof ( "Login" )! =-1)
{
Ihtmlelement = E;
Break ;
}
}
If (Ihtmlelement! = Null )
{
Ihtmlelement. Click (); // Click the logon button.
}

 

Winform obtains the current ieurl address
    1. System. Diagnostics. Process [] _ list = system. Diagnostics. process. getprocessesbyname ("Iexplore");
    2. [Dllimport ("User32.dll")]
    3. Public Static Extern IntEnumchildwindows (intptr hwndparent, enumwindowsproc EWP,IntLparam );

 

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.