Introduce a powerful API function shellexecute
statement of problem:
I use MFC to write an app and ask the LOGO, company name, address, and company URL link in the About dialog. After using the user to click the URL link, start the browser to access the web page, the hot link in this dialog box makes a lot of color. The way I pondering is to get the name of the default browser from the system registry to find the .htm or .html file, this seems to have a lot of work to do. Also, if the browser has already opened, always start a new instance instead of an instance of the current existing. I want to find an easy way, but I have checked the relevant information, no gain, please advise.
Solution:
If there is such an API function, how is it: OpenThishereURLFORMENOWPLEASE (), the problem is not solved! ! I tell you, have, but it is not the function you imagined. So far, there is no mention of such a useful function in the documentation, which can open any file on the desktop and open the Internet URL. The only reference I can find is to mention this function in Microsoft? Access KnowledgeBase.
This incredible function is: Shellexecute, replaced Winexec. You can give it the name of any file, it can identify and open it. For example: Shellexecute (NULL, "Open", "Iloveu.bmp", NULL, NULL, SW_SHOWNORMAL);
Open a bitmap file called Iloveu.bmp with a default bitmap editor, which may be Microsoft Paint, Adobe Photoshop, or Corel PhotoPaint.
For detailed usage information about Shellexecute, you should refer to the relevant information, it is important that you know that this function can open any file, or even a desktop and URL shortcut (.ink or .url). SHELLEXECUTE parses all content in the system registry hkey_classes_root, determine the execution program, and start a new instance or use DDE to connect the file name to an open instance. Then, SHELLEXECUTE returns an instance handle of the application that opens the file.
More wonderful is that shellexecute can not only open the file on the machine, but also open the Internet site address. For example: Shellexecute (NULL, "Open", "http://vckbase.yeah.net", null, null, sw_shownormal);
This code allows you to access Microsoft's homepage. When shellexecute encounters "HTTP:" in front of the file name, it is possible to determine that the file to be opened is a web file, start Internet Explorer or Netscape Navigator or any other browser you use to open the file. Shellexecute can also identify other protocols, like FTP, Gopher. Even "Mailto", if the file name points to "Mailto: Zxn@hq.cninfo.net", which launches an email program and opens a new message to be edited. In short, the shellexecute function is so simply open disk files and Internet files. If the second parameter "open" is changed to "Print" or "Explore", Shellexecute will be able to print the file and open the folder. Shellexecute has an extension function shellexecuteEx, a special structure in the parameters, more functional, and its usage is related to the document. Now, you know the secret of Shellexecute, with it easy to add a link to your About dialog. Not. :)
(Author: Zhao Xiangning, 2000 at 18:24 on January 14)