• 怎样创建一个快捷方式


    void __fastcall TMainForm::Shortcut_Log( AnsiString LinkName, AnsiString LinkFile )
    {
    IShellLinkA* pLink;
    IPersistFile* pPersistFile;

    if(SUCCEEDED(CoInitialize(NULL)))
    {
    if(SUCCEEDED(CoCreateInstance(CLSID_ShellLink, NULL,
    CLSCTX_INPROC_SERVER,
    IID_IShellLink, (void **) &pLink)))
    {
    pLink->SetPath( LinkFile.c_str() );
    //pLink->SetDescription( SoftExplain.SubString(2, SoftExplain.Length() - 1 ).c_str() );
    pLink->SetWorkingDirectory( ExtractFileDir( LinkFile ).c_str() );
    pLink->SetShowCmd(SW_SHOW);

    if(SUCCEEDED(pLink->QueryInterface(IID_IPersistFile,
    (void **)&pPersistFile)))
    {

    WideString strShortCutLocation;
    strShortCutLocation = WideString( LinkName ) + ".lnk";
    pPersistFile->Save(strShortCutLocation.c_bstr(), TRUE);
    pPersistFile->Release();
    }
    pLink->Release();
    }
    CoUninitialize();
    }
    }
    专访张慧华:厨师、程序员到J-UI联合创始人对我有用[0] 丢个板砖[0] 引用 | 举报 | 管理

    Libran
    Libran
    等级:
    2
    #3 得分:10 回复于: 2002-10-25 11:35:20
    转载:
    下面的例子代码演示了怎样创建一个快捷方式。在这个例子里,这个快捷方式保存在C:Drive目录下。

    //------------------------------------------------------------------include <shlobj.h>

    void __fastcall TForm1::Button1Click(TObject *Sender)
    {
    if(OpenDialog1->Execute())
    CreateShortCut(OpenDialog1->FileName);
    }
    //------------------------------------------------------------------void TForm1::CreateShortCut(const AnsiString &file)
    {
    IShellLink* pLink;
    IPersistFile* pPersistFile;
    if(SUCCEEDED(CoInitialize(NULL)))
    {
    if(SUCCEEDED(CoCreateInstance(CLSID_ShellLink, NULL,
    CLSCTX_INPROC_SERVER,
    IID_IShellLink, (void **) &pLink)))
    {
    pLink->SetPath(file.c_str());
    pLink->SetDescription("Woo hoo, look at Homer's shortcut");
    pLink->SetShowCmd(SW_SHOW);
    if(SUCCEEDED(pLink->QueryInterface(IID_IPersistFile,
    (void **)&pPersistFile)))
    {
    WideString strShortCutLocation("C:\bcbshortcut.lnk");
    pPersistFile->Save(strShortCutLocation.c_bstr(), TRUE);
    pPersistFile->Release();
    }
    pLink->Release();
    }

    CoUninitialize();
    }
    }
    //------------------------------------------------------------------
    与她合影留念,致终将逝去的青春对我有用[0] 丢个板砖[0] 引用 | 举报 | 管理

    mynameis007
    mynameis007
    等级:
    #4 得分:40 回复于: 2002-10-25 12:32:53
    如果你不懂COM,可以用一下的代码:
    TShellLind *Link;
    TPersistFile *PersistFile;

    Link=new TShellLink;
    Link->SetPath(file.c_str());

    PersistFile=dynamic_cast<TPersistFile*>(Link);
    PersistFile->Save("d:\ff\");

    delete PersistFile;
    delete Link;
    当然如果你要保存的桌面,要知道桌面的目录:
    用一下的代码可以实现(因为NT的桌面目录不再C:desktop下)
    void TForm1::CreateShortCut(const AnsiString &file)
    {
    IShellLink* pLink;
    IPersistFile* pPersistFile;
    LPMALLOC ShellMalloc;
    LPITEMIDLIST DesktopPidl;
    char DesktopDir[MAX_PATH];

    if(FAILED(SHGetMalloc(&ShellMalloc)))
    return;

    if(FAILED(SHGetSpecialFolderLocation(NULL,
    CSIDL_DESKTOPDIRECTORY,
    &DesktopPidl)))
    return;

    if(!SHGetPathFromIDList(DesktopPidl, DesktopDir))
    {
    ShellMalloc->Free(DesktopPidl);
    ShellMalloc->Release();
    return;
    }

    ShellMalloc->Free(DesktopPidl);
    ShellMalloc->Release();

    if(SUCCEEDED(CoInitialize(NULL)))
    {
    if(SUCCEEDED(CoCreateInstance(CLSID_ShellLink, NULL,
    CLSCTX_INPROC_SERVER,
    IID_IShellLink, (void **) &pLink)))
    {
    pLink->SetPath(file.c_str());
    pLink->SetDescription("Woo hoo, look at Homer's shortcut");
    pLink->SetShowCmd(SW_SHOW);

    if(SUCCEEDED(pLink->QueryInterface(IID_IPersistFile,
    (void **)&pPersistFile)))
    {

    WideString strShortCutLocation(DesktopDir);
    strShortCutLocation += "\bcbshortcut.lnk";
    pPersistFile->Save(strShortCutLocation.c_bstr(), TRUE);
    pPersistFile->Release();
    }
    pLink->Release();
    }
    CoUninitialize();
    }
    }

  • 相关阅读:
    java之获取变量的类型
    java中的++和--
    java(三)基础类型之间的转换
    golang数据结构之总结
    golang数据结构之树的三种遍历方式
    golang数据结构之散哈希表(Hash)
    golang数据结构之递归解决迷宫问题
    golang数据结构之利用栈求计算表达式(加减乘除)
    golang数据结构之栈
    golang数据结构之快速排序
  • 原文地址:https://www.cnblogs.com/blogpro/p/11446058.html
Copyright © 2020-2023  润新知