<small id='fWei1'></small><noframes id='fWei1'>

      <legend id='fWei1'><style id='fWei1'><dir id='fWei1'><q id='fWei1'></q></dir></style></legend>
      • <bdo id='fWei1'></bdo><ul id='fWei1'></ul>
    1. <i id='fWei1'><tr id='fWei1'><dt id='fWei1'><q id='fWei1'><span id='fWei1'><b id='fWei1'><form id='fWei1'><ins id='fWei1'></ins><ul id='fWei1'></ul><sub id='fWei1'></sub></form><legend id='fWei1'></legend><bdo id='fWei1'><pre id='fWei1'><center id='fWei1'></center></pre></bdo></b><th id='fWei1'></th></span></q></dt></tr></i><div id='fWei1'><tfoot id='fWei1'></tfoot><dl id='fWei1'><fieldset id='fWei1'></fieldset></dl></div>

      <tfoot id='fWei1'></tfoot>

      如何使用 Win32 以编程方式创建快捷方式

      时间:2023-08-01
          <tbody id='AljoY'></tbody>
            <bdo id='AljoY'></bdo><ul id='AljoY'></ul>

            1. <i id='AljoY'><tr id='AljoY'><dt id='AljoY'><q id='AljoY'><span id='AljoY'><b id='AljoY'><form id='AljoY'><ins id='AljoY'></ins><ul id='AljoY'></ul><sub id='AljoY'></sub></form><legend id='AljoY'></legend><bdo id='AljoY'><pre id='AljoY'><center id='AljoY'></center></pre></bdo></b><th id='AljoY'></th></span></q></dt></tr></i><div id='AljoY'><tfoot id='AljoY'></tfoot><dl id='AljoY'><fieldset id='AljoY'></fieldset></dl></div>
              <tfoot id='AljoY'></tfoot>
              1. <legend id='AljoY'><style id='AljoY'><dir id='AljoY'><q id='AljoY'></q></dir></style></legend>

                <small id='AljoY'></small><noframes id='AljoY'>

                本文介绍了如何使用 Win32 以编程方式创建快捷方式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                问题描述

                我需要使用 C++ 以编程方式创建快捷方式.

                I need to programmatically create a shortcut using C++.

                如何使用 Win32 SDK 执行此操作?

                How can I do this using Win32 SDK?

                哪些 API 函数可用于此目的?

                What API function can be used for this purpose?

                推荐答案

                尝试 Windows Shell 链接. 此页面还包含一个 C++ 示例.描述性代码段:

                Try Windows Shell Links. This page also contains a C++ example. Descriptive Snippet:

                使用外壳链接

                本节包含的示例演示如何创建和解决来自基于 Win32 的快捷方式应用.本节假设您熟悉Win32、C++和OLECOM 编程.

                This section contains examples that demonstrate how to create and resolve shortcuts from within a Win32-based application. This section assumes you are familiar with Win32, C++, and OLE COM programming.

                添加代码示例以防链接失效(并且 MSDN 链接经常失效.)

                Adding the code sample in case the link dies (and MSDN links do die often.)

                // CreateLink - Uses the Shell's IShellLink and IPersistFile interfaces 
                //              to create and store a shortcut to the specified object. 
                //
                // Returns the result of calling the member functions of the interfaces. 
                //
                // Parameters:
                // lpszPathObj  - Address of a buffer that contains the path of the object,
                //                including the file name.
                // lpszPathLink - Address of a buffer that contains the path where the 
                //                Shell link is to be stored, including the file name.
                // lpszDesc     - Address of a buffer that contains a description of the 
                //                Shell link, stored in the Comment field of the link
                //                properties.
                
                #include "stdafx.h"
                #include "windows.h"
                #include "winnls.h"
                #include "shobjidl.h"
                #include "objbase.h"
                #include "objidl.h"
                #include "shlguid.h"
                
                HRESULT CreateLink(LPCWSTR lpszPathObj, LPCSTR lpszPathLink, LPCWSTR lpszDesc) 
                { 
                    HRESULT hres; 
                    IShellLink* psl; 
                
                    // Get a pointer to the IShellLink interface. It is assumed that CoInitialize
                    // has already been called.
                    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. 
                        psl->SetPath(lpszPathObj); 
                        psl->SetDescription(lpszDesc); 
                
                        // Query IShellLink for the IPersistFile interface, used for saving the 
                        // shortcut in persistent storage. 
                        hres = psl->QueryInterface(IID_IPersistFile, (LPVOID*)&ppf); 
                
                        if (SUCCEEDED(hres)) 
                        { 
                            WCHAR wsz[MAX_PATH]; 
                
                            // Ensure that the string is Unicode. 
                            MultiByteToWideChar(CP_ACP, 0, lpszPathLink, -1, wsz, MAX_PATH); 
                
                            // Save the link by calling IPersistFile::Save. 
                            hres = ppf->Save(wsz, TRUE); 
                            ppf->Release(); 
                        } 
                        psl->Release(); 
                    } 
                    return hres; 
                

                这篇关于如何使用 Win32 以编程方式创建快捷方式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                上一篇:如何调用带有参数的外部程序? 下一篇:从 dll 返回 std::string/std::list

                相关文章

                最新文章

                  <bdo id='VIZeY'></bdo><ul id='VIZeY'></ul>

                  <legend id='VIZeY'><style id='VIZeY'><dir id='VIZeY'><q id='VIZeY'></q></dir></style></legend>

                  <small id='VIZeY'></small><noframes id='VIZeY'>

                1. <tfoot id='VIZeY'></tfoot>
                  <i id='VIZeY'><tr id='VIZeY'><dt id='VIZeY'><q id='VIZeY'><span id='VIZeY'><b id='VIZeY'><form id='VIZeY'><ins id='VIZeY'></ins><ul id='VIZeY'></ul><sub id='VIZeY'></sub></form><legend id='VIZeY'></legend><bdo id='VIZeY'><pre id='VIZeY'><center id='VIZeY'></center></pre></bdo></b><th id='VIZeY'></th></span></q></dt></tr></i><div id='VIZeY'><tfoot id='VIZeY'></tfoot><dl id='VIZeY'><fieldset id='VIZeY'></fieldset></dl></div>