Create shortcuts on the desktop

Source: Internet
Author: User

From: http://www.vckbase.com

 

ReadingCodeBefore that, let's take a look at the structure of the "shortcut" component.

 
Figure 2 interface structure of the shortcut component

From the structure diagram, we can see that the "shortcut" component (clsid_shelllink) has three (in fact, more than one) interfaces, each of which completes a set of functions. The ishelllink interface (iid_ishelllink) provides a shortcut for parameter read/write (see figure 3). The ipersistfile interface (iid_ipersistfile) provides a shortcut for persistent file read/write. Object persistence (note 5) is a very common and powerful interface family. But today, we only need to know two of these functions: ipersistfile: Save () and ipersistfile: load (). (Note 6)

 
Figure 3. Attributes of shortcuts

# Include <atlconv. h> void createshortcut (lpctstr lpszexe, lpctstr lpszlnk) {// create a blockchain method // parameter lpszexe: full path name of the EXE file // parameter lpszlnk: full path name of the shortcut file :: coinitialize (null); ishelllink * PSL = NULL; ipersistfile * PPF = NULL; hresult hR =: cocreateinstance (// start component clsid_shelllink, // shortcut clsidnull, // for aggregation (note 4) clsctx_inproc_server, // The iid_ishelllink and the iid (lpvoid *) of the shell32.dll service in the process. & PSL ); // obtain the interface pointer if (succeeded (HR) {PSL-> setpath (lpszexe); // full path Program Name // PSL-> setarguments (); // command line parameter // PSL-> setdescription (); // remarks // PSL-> sethotkey (); // shortcut // PSL-> seticonlocation (); // icon // PSL-> setshowcmd (); // window size // according to the EXE file name, obtain the directory name tchar szworkpath [max_path];: lstrcpy (szworkpath, lpszexe); lptstr Lp = szworkpath; while (* LP) LP ++; while (''//''! = * LP) LP --; * Lp = 0; // set the default working directory of the EXE program, PSL-> setworkingdirectory (szworkpath ); hR = PSL-> QueryInterface (// persistence file query interface pointer iid_ipersistfile, // persistence interface IID (lpvoid *) & PPF ); // obtain the interface pointer if (succeeded (HR) {uses_conversion; // convert it to the Unicode string PPF-> Save (t2cole (lpszlnk), true ); // save} If (PPF) PPF-> release (); If (PSL) PSL-> release ();: couninitialize ();} void onxxx () {createshortcut (_ T ("C: // winnt // notepad.exe "), // Notepad program. Note: Is your system also in this directory? _ T ("C: // Documents and Settings // administrator // desktop // my notepad. lnk "); // create the full path name of the shortcut (lnk) file on the desktop. Note: Is your system also in this directory? // If you use a program to find the desktop path, you can check the registry // HKEY_CURRENT_USER/software/Microsoft/Windows/CurrentVersion/Explorer/Shell Folders}

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.