1

Before you call CreateFile, you need the name of a file. You can of course create your own dialog:

  • enumerates drives, folders, or the shell namespace
  • allow the user to navigate
  • show files in selected folder
  • and let the user pick a file and close the dialog

But fortunately Windows already did all the UI heavy lifting, and provided you an IFileOpenDialog common dialog:

enter image description here

Does the same exist for creating a link?

Windows Explorer has a dialog that guides the user through creating a shortcut to a file, folder, item, url, etc:

enter image description here

Is this dialog a "common" dialog - available for use by applications?


Edit: Also a reminder: I'm not looking to invoke the wizard - because the wizard creates the link on the hard drive. And i don't want it saved on the hard drive. I need the ability to get the resulting:

  • IShellLink or
  • IUniformResourceLocator,

or the

  • Location
  • Title

that the user entered.

I need a "location picker" user interface.

Ian Boyd
  • 246,734
  • 253
  • 869
  • 1,219
  • 4
    That dialog is not programmatically exposed, sorry. – Raymond Chen Jul 16 '19 at 17:21
  • But I believe you can invoke it by invoking the context menu and executing the appropriate action. I believe that there are examples of doing this, in fact I think Raymond has shown how to do this. – David Heffernan Jul 16 '19 at 17:23
  • There is an undocumented interface, ICreateNewLink you can find a description here: https://gist.github.com/hfiref0x/e58711820276fe8b1b36dd51faae59cf ... – Simon Mourier Jul 16 '19 at 18:27
  • There are other ways of doing this, I'm not going to put them in an answer because they are more work and still relies on undocumented stuff but: A) SVGIO_BACKGROUND IContextMenu or B) .lnk\ShellNew in the registry (Handler type used in newer Windows versions is undocumented AFAIK). – Anders Jul 16 '19 at 23:11

1 Answers1

1

Does the same exist for creating a link?

Windows Explorer has a dialog that guides the user through creating a shortcut to a file, folder, item, url, etc:

Yes, it is the API NewLinkHereW

A test (VS 2015, Windows 10) =>

(link created in e:\test for the sample)

        typedef void(WINAPI *NLH)(HWND hwnd, HINSTANCE hAppInstance, LPTSTR lpszCmdLine, int nCmdShow);
        NLH NewLinkHereW;
        HMODULE hDll = LoadLibrary(L"appwiz.cpl");
        NewLinkHereW = (NLH)GetProcAddress(hDll, "NewLinkHereW");
        WCHAR wsFolder[MAX_PATH] = L"e:\\test";
        lstrcat(wsFolder, L"\\newlink.lnk");
        if (NewLinkHereW)
        {
            HANDLE hLink = CreateFile(wsFolder, GENERIC_WRITE, FILE_SHARE_READ, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
            if (hLink != INVALID_HANDLE_VALUE)
            {
                CloseHandle(hLink);
                NewLinkHereW(GetDesktopWindow(), NULL, wsFolder, SW_SHOWNORMAL);
            }               
        }
Castorix
  • 1,465
  • 1
  • 9
  • 11
  • 2
    This goes back as far as at least Win2000 but it is undocumented and some versions of Windows don't call this directly (XP does, 8 does not etc). – Anders Jul 16 '19 at 18:21