荔园在线

荔园之美,在春之萌芽,在夏之绽放,在秋之收获,在冬之沉淀

[回到开始] [上一篇][下一篇]


发信人: Deny (Deny), 信区: Visual
标  题: [转载] 如何在Desktop上创建文件夹和快捷方式    cudo (转寄)
发信站: BBS 荔园晨风站 (Sat Dec 23 22:05:44 2000), 转信

【 以下文字转载自 Deny 的信箱 】
【 原文由 denick.bbs@smth.org 所发表 】
发信人: solarwind (太阳风), 信区: VisualC
标  题: Re:  如何在win95的Desktop上创建文件夹和快捷方式
发信站: BBS 水木清华站 (Thu Jul  2 23:23:50 1998)

【 在 DevStudio (   ) 的大作中提到: 】
: 如提,我指的是用程序实现,就比如做一个安装程序。

使用类似如下程序段


dlg.SetStatus("正在建立程序组和快捷方式...");
char m_strWinDir[512];
long rval;
HKEY hKey;
DWORD dwType;
char szText[80];
DWORD dwSize, dwDisp;
rval = RegOpenKeyEx(HKEY_CURRENT_USER,
        "Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\Shell Folders",
        NULL, KEY_QUERY_VALUE, &hKey);

if(rval == ERROR_SUCCESS)
{
        dwSize = 512;
        rval = RegQueryValueEx(hKey, "Programs", 0,
                &dwType, (LPBYTE)m_strWinDir, &dwSize);
        rval = RegCloseKey(hKey);
        strcat(m_strWinDir, "\\惠普KeyIn系统");
        CreateDirectory(m_strWinDir, NULL);
        strcat(m_strWinDir, "\\惠普KeyIn系统.lnk");
        HRESULT hres;
        IShellLink* psl;
        // Get a pointer to the IShellLink interface.
        CoInitialize(NULL);
        hres = CoCreateInstance(CLSID_ShellLink, NULL,
                CLSCTX_INPROC_SERVER, IID_IShellLink, (LPVOID *)&psl);
        if(SUCCEEDED(hres))
        {
                IPersistFile* ppf;
                // Set the path to the shortcut target, and add the
                // description.
                if(!pSheet->bUseNetwork)
                {
                        psl->SetPath("c:\\keyin\\keyin.exe");
                        psl->SetWorkingDirectory("c:\\keyin");
                }
                else
                {
                        CString temp;
                        temp = pSheet->m_strPath.Left(pSheet->
m_strPath.GetLength()-10);
                        if(temp.GetLength() == 2)temp += "\\";
                        psl->SetPath(pSheet->m_strPath);
                        psl->SetWorkingDirectory(temp);
                }
                psl->SetDescription("惠普KeyIn系统");
           // Query IShellLink for the IPersistFile interface for saving the
           // shortcut in persistent storage.
                hres = psl->QueryInterface(IID_IPersistFile,
                        (LPVOID *)&ppf);
                if(SUCCEEDED(hres))
                {
                        WORD wsz[MAX_PATH];
                        // Ensure that the string is ANSI.
                        MultiByteToWideChar(CP_ACP, 0, m_strWinDir, -1,
                                wsz, MAX_PATH);
                        // Save the link by calling IPersistFile::Save.
                        hres = ppf->Save(wsz, TRUE);
                        ppf->Release();
                }
                psl->Release();
        }
}
else
{
        MessageBox("创建程序组和快捷方式失败,请稍后自行创建。", "错误");
}



--
※ 来源:·BBS 水木清华站 bbs.net.tsinghua.edu.cn·[FROM: 166.111.33.31]
--
※ 转载:·BBS 荔园晨风站 bbs.szu.edu.cn·[FROM: 192.168.1.119]


[回到开始] [上一篇][下一篇]

荔园在线首页 友情链接:深圳大学 深大招生 荔园晨风BBS S-Term软件 网络书店