Introduce a powerful API function shellexecute

xiaoxiao2021-03-06  143

Introduction to a powerful API function shellexecute compiles Zhao Xiangning issues: I use MFC to write an app, ask for the About dialog box to display logo, company name, address, and company URL links. 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. Workaround: If there is such an API function, how good: 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. E.g:

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. E.g:

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, 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. :)

转载请注明原文地址:https://www.9cbs.com/read-127412.html

New Post(0)