VC windows shortcut

Source: Internet
Author: User
Two operations: Create and parse the COM component. Header functions to be added for ishelllink and ipersistfile
Shobjidl. hipersistfile mainly uses two member functions:
1. Save. Save the content to the file
2. Load. Read
Load function prototype
Hresult load (
Lpcolstr pszfilename, // name of the shortcut file, which should be an ANSI character
DWORD dwmode // read mode
);
Dwmode can be set to the following values:
Stgm_read: Read-Only
Stgm_write: Write-only
Stgm_readwrite: Primary member of ishelllink:
1. getarguments: Get the parameter information
2. getdescription: obtains the description (remarks)
3. gethotkey: Get the shortcut key
4. geticonlocation: Get the icon
5. getidlist: Obtain the item identifier list of the target object in the shortcut mode (each object in the Windows Shell, such as a file, directory, or printer, has a unique item identifiler List)
6. getpath: obtain the full path of the target file or directory of the shortcut.
7. getshowcmd: Get the shortcut running mode, such as regular window, to maximize
8. getworkingdirectory: Get the working directory
9. Resolve: attempts to obtain the target object according to certain search rules, even if the target object has been deleted or moved, rename
The following is how to set the corresponding information:
10. setarguments
11. setdescription
12. sethotkey
13. seticonlocation
14. setidlist
15. setpath
16. setrelativepat
17. setshowcmd
18. setworkingdirectory: 1. initialize the COM interface
Ii. Create an ishelllink object
3. Get ipersistfile object interface from the ishelllink object
4. Operate the ishelllink object
5. Release the ipersistfile object interface
6. Release the ishelllink object
VII. Example code for releasing the COM interface:
/*
Note: Create a shortcut on the desktop. The shortcut name is "VC created shortcut". The shortcut points to the application "C:/aa.exe"
Shortcut: None
Shortcut working directory: C :/
Remarks on shortcuts: VC writing and writing
Shortcut running mode: regular window
*/Hresult HRET;
Ishelllink * plink; // ishelllink object pointer
Ipersistfile * PPF; // ipersisfil object pointer
Wchar wsz [max_path]; // defines the Unicode string // initializes the com Library
HRET =: coinitialize (null );
If (HRET! = S_ OK) // An error occurred while initializing the com library.
{
Afxmessagebox ("failed to initialize com library ");
Return;
}
// Create an ishelllink instance
HRET =: cocreateinstance (clsid_shelllink, null, clsctx_inproc_server, iid_ishelllink, (void **) & plink );
If (HRET! = S_ OK)
{
Afxmessagebox ("An error occurred while creating the ishelllink instance ");
}
Else
{
// The ishelllink instance is successfully created. Continue.
 
// Obtain the ipersistfile interface from the ishelllink object
HRET = plink-> QueryInterface (iid_ipersistfile, (void **) & PPF );
If (HRET! = S_ OK)
{
Afxmessagebox ("failed to get ipersistfile interface ");
}
Else
{
// The interface is obtained successfully. Continue the operation.
// Set the program path in the shortcut
Plink-> setpath ("C: // aa.exe ");
// Set the shortcut working directory
Plink-> setworkingdirectory ("C ://");
// Make sure that the shortcut path consists of an ANSI string
Multibytetowidechar (
Cp_acp,
0,
"C: // Documents and Settings // hjs // shortcuts created by desktop // VC. lnk ",
-1,
Wsz,
Max_path
);
// Save the shortcut
PPF-> Save (wsz, true );
}
} // Release the ipersistfile Interface
PPF-> release ();
// Release the ishelllink object
Plink-> release ();
// Release the COM interface
: Couninitialize ();

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.