You can use VC to add a command button on the toolbar of IE browser for reference)

Source: Internet
Author: User
Use VC to add a command button on the toolbar of IE browser
[16:35:00 | By: Ru pengxin]
 
I don't know if the readers have noticed it. After Kingsoft, network ant, and other application software are installed on the computer, they will add their own buttons to the tool bar of IE. After you press the button, IE will start the corresponding software, make corresponding actions. How is the above function implemented? This example describes how to add the buttons of your application to the toolbar of IE.

  I. Implementation Method

Microsoft allows developers to add buttons to their toolbar from IE5.0. The essence of the implementation method is to modify the registry and add the information required to create this button. First, create the GUID (globally unique identifier) of this button. This GUID can be generated by guidgen.exe in Visual studio. For example, a generated GUID is {1fba04ee-3024-11d2-8f1f-440f87abd16} (this GUID is used in the following descriptions ). After the GUID value is available, create a subkey in the Windows registry:

HKEY_LOCAL_MACHINE \ Software \ Microsoft \ Internet Explorer \ Extensions \ {1fba04ee-3024-11d2-8f1f-440f87abd16}

Create the following string values under this subkey:

1) CLSID

This is the CLSID of IE, and its value must be {1fba04ee-3024-11d2-8f1f-440f87abd16}
 
2) Default Visible

Specifies whether this button is visible by default, Yes indicates visible, No indicates invisible

3) ButtonText

Button text

4) Icon

The full path of icons in the default status, such as c: \ VCkbase. ico. It can also be an icon contained in the EXE file, for example, C: \ PROGRA ~ 1 \ NETANTS \ NetAnts.exe, 1000

5) HotIcon

Full path of the icon when you move the cursor over the button

The following sub-keys are the actions to be performed after the button is pressed: COM Object, browser Bar, Script, and executable file. Next we will introduce them one by one:

① COM Object

You need to create a string value named ClsidExtension. Its value should be the GUID of the COM Object. For example, Kingsoft uses ClsidExtension to call its own COM object.

② Browser Bar

The browser bar is similar to the historical record list opened after you press the IE history button. In essence, it is like the CReBar object in MFC. You can also create browsing entries by yourself. This is beyond the scope of this article and will not be explained at the moment. To open a browser bar after pressing the button, you need to create a string value named BandCLSID, whose value is the CLSID of the browser bar.

③ Script

The script executed after pressing the button, for example, "% SystemRoot % \ Web \ related.htm", you can add a script in This HTML file to get a lot of information about IE, note that it is not feasible to open non-Script HTML files through scripts. See the following NetAnts script code for getting all links to the current page.

<Script language = "VBScript">
On Error Resume Next
Set NetAntSAPi = CreateObject ("NetAnts. API ")
If err <> 0 then
Alert ("NetAnts not proPerly installed on this PC! ")
Else
Set links = external.menuArguments.doc ument. links
ReDim params (links. length * 2)
Params(01_1_external.menuarguments.doc ument. Url
For I = 0 to links. length-1
Params (I * 2 + 1) = links (I). href
Params (I * 2 + 2) = links (I). innerText
Next
NetAntsApi. AddUrlList params
End if
</Script>

Let's look at another useful script. This script is used to get the current address and open the homepage of this URL:

<Script>
// What userURL gets is the current address, for example, a http://www.yesky.com
UserURL = external. menuArguments. location. href;
ProtocolIndex = userURL. indexOf (": //", 4 );
ServerIndex = userURL. indexOf ("/", protocolIndex + 3 );
FinalURL = userURL. substring (0, serverIndex );
External. menuArguments. open (finalURL, "_ blank"); // open the URL;
</Script>

④ Executable files

If you want IE to execute an executable file after pressing the button, you can add a string value named Exec whose value is the full path of the executable file, such as c: \ windows \ notepad.exe or a Web http://www.yesky.net
With the above knowledge, you can modify the Registry to add a button to the IE Toolbar.

  Ii. programming steps

1. Start Visual C ++ 6.0, generate a dialog box-based application, and name the program "IEButton ";

2. Modify the buttons in the application dialog box with the titles "add" and "exit" respectively ";

3. Use Class Wizard to add the OnAdd () Message response function clicked with the mouse to the "add" button of the application ();

4. Add code and compile and run the program.

3. program code

Void CIEButtonDlg: OnAdd ()
{
/// This is the GUID generated by GUIDGEN: {06926b30-450e-4f1c-8ee3-543cd96573dc}
CRegKey reg;
Char KeyName [] = "Software \ Microsoft \ Internet
Explorer \ Extensions \ {06926b30-450e-4f1c-8ee3-543cd96573dc }";
TCHAR PathName [MAX_PATH];
Tchar iconpathname [max_path]; // full path of the icon in normal conditions
Tchar hoticonpathname [max_path]; // full path of the icon when the mouse overwrites
Getmodulefilename (0, pathname, max_path); // obtain the path of the Local Executable File
Strcpy (iconpathname, pathname );
Strcpy (hoticonpathname, pathname );
Strcat (hoticonpathname, ", 131"); // 131 is the icon ID. You can open the EXE file as a resource to view all resources and their IDs.
Strcat (iconpathname, ", 129 ");
Reg. Create (HKEY_LOCAL_MACHINE, keyname );
Reg. setvalue ("{1fba04ee-3024-11d2-8f1f-440f87abd16}", "CLSID ");
Reg. setvalue ("yes", "Default visible ");
Reg. setvalue ("Skynet", "buttontext ");
Reg. setvalue (iconpathname, "icon ");
Reg. setvalue (hoticonpathname, "hoticon ");
//// If the script is executed, it can be Reg. setvalue ("C: \ test.html", "script"); // store your script code in test.html <br>
Reg. setvalue ("http://www.yesky.com/", "EXEC"); // open the page
}

Iv. Summary

This example introduces how to add buttons in the IE Toolbar. Readers can add their own applications to IE Based on digestion and absorption, add a method and a way to achieve self-promotion.

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.