Describes a powerful API function, ShellExecute.

Source: Internet
Author: User

Describes a powerful API function, ShellExecute.

Compile Zhao Xiangning

Question:
I used MFC to write an app and asked the about dialog box to display the logo, company name, address, and company URL link. After the user clicks the URL link, start the browser to access the Web page. The hot link in this dialog box adds a lot of colors to the application. I tried to obtain the name of the default browser from the associated program of the. htm or. html file in the system registration table. It seems that there is a lot of work to do. In addition, if the browser is enabled, a new instance is always started to replace the existing instance. I want to find an easy way, but I have checked the relevant information and have not obtained any results. Please advise.

Solution:
If there is such an API function, how good is it: openthishereurlformenowplease (), the problem will not be solved !! Let me tell you, yes, but it is not the function you think. So far, this useful function has not been mentioned in the relevant documentation. It can open any file on the desktop or Internet URL. The only reference I can find is that I mentioned this function in Microsoft Access KnowledgeBase.
This incredible function is: ShellExecute, replacing winexec. You can give it the name of any file, which can be identified and opened. For example:

ShellExecute(NULL,"open","iloveu.bmp",NULL,NULL,SW_SHOWNORMAL);

Open a bitmap file named iloveu.bmp with your map editor. The default bitmap editor may beMicrosoft Paint, Adobe Photoshop, or Corel photopaint.

RelatedFor details about how to use ShellExecute, refer to relevant information. It is important that you know that this function can open any file, or even desktop and URL shortcuts (. Ink or. URL ).ShellExecute parses all content in the hkey_classes_root system registry, determines the execution program to be started, and starts a new instance or uses DDE to connect the file name to an open instance. Then, ShellExecute returns the instance handle of the application that opened the file.

What's more, ShellExecute can not only open files on the machine, but also open the Internet site address. For example:

ShellExecute (null, "open", "http://www.microsoft.com", null, null, sw_shownormal );

This Code allows you to access Microsoft's homepage. When ShellExecute Encounters "http:" in front of the file name, you can determine that the file to be opened is a Web file, and then start Internet Explorer or Netscape Navigator or any other browser you use to open the file. ShellExecute can also identify other protocols, such as FTP and gopher. Even recognize "mailto", if the file name points to "mailto: zxn@hq.cninfo.net", it starts the e-mail program and opens a new mail to be edited. In short, the ShellExecute Function is so simple to open disk files and Internet files. If you change the second parameter "open" to "print" or "Release E", ShellExecute can print files and open folders. ShellExecute also has an extension function shellexecuteex, which has a special structure and is more powerful. For more information about its usage, see the relevant documentation.

Now that you know the secret of ShellExecute, you can easily add a dialog box that links to your about. No. :)

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.