| 在桌面建立快捷方式 |
|
| 作者:未知 文章来源:网络收集 点击数: 更新时间:2006-3-29 15:22:23
|
Harold Howe(翻译:抱雪)
API提供了一个COM接口:调用 IShellLink 将允许你建立一个快捷方式,要在桌面建立一个快捷方式,只要把这个快捷方式保存到桌面目录就可以了。
下面的示例代码演示怎样建立一个快捷方式,在这个例子里,快捷方式将保存在C:\ drive。
//---------------------------------------------------------------------- #include
void __fastcall TForm1::Button1Click(TObject *Sender) { // Allow the user to find a file with a common dialog box, // then create a shortcut to that file. if(OpenDialog1->Execute()) CreateShortCut(OpenDialog1->FileName); } //---------------------------------------------------------------------- void TForm1::CreateShortCut(const AnsiString &file) { // IShellLink allows us to create the shortcut. // IPersistFile saves the link to the hard drive. IShellLink* pLink; IPersistFile* pPersistFile;
// First, we have to initialize the COM library if(SUCCEEDED(CoInitialize(NULL))) { // If CoInitialize doesn't fail, then instantiate an // IShellLink object by calling CoCreateInstance. if(SUCCEEDED(CoCreateInstance(CLSID_ShellLink, NULL, CLSCTX_INPROC_SERVER, IID_IShellLink, (void **) &pLink))) { // if that succeeds, then fill in the shortcut attributes pLink->SetPath(file.c_str()); pLink->SetDescription("Woo hoo, look at Homer's shortcut"); pLink->SetShowCmd(SW_SHOW);
// Now we need to save the shortcut to the hard drive. The // IShellLink object also implements the IPersistFile interface. // Get the IPersistFile part of the object using QueryInterface. if(SUCCEEDED(pLink->QueryInterface(IID_IPersistFile, (void **)&pPersistFile))) { // If that succeeds, then call the Save method of the // IPersistFile object to write the shortcut to the desktop. WideString strShortCutLocation("C:\\bcbshortcut.lnk"); pPersistFile->Save(strShortCutLocation.c_bstr(), TRUE); pPersistFile->Release(); } pLink->Release(); }
// Calls to CoInitialize ne[1] [2] [3] 下一页
|
|
[ 收藏此页到: 天天|和讯|博采|ViVi|狐摘|我摘|天极 ] 文章录入:kinda 责任编辑:kinda |
|
上一篇文章: security of programer - 5 下一篇文章: 一个操作本地或者远程主机服务的小程序 |
| 【字体:小 大】【发表评论】【加入收藏】【告诉好友】【打印此文】【关闭窗口】 |