Before you call CreateFile
, you need the name of a file. You can of course create your own dialog:
But fortunately Windows already did all the UI heavy lifting, and provided you an IFileOpenDialog
common dialog:
Windows Explorer has a dialog that guides the user through creating a shortcut to a file, folder, item, url, etc:
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
that the user entered.
I need a "location picker" user interface.
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);
}
}