ReactOS  0.4.15-dev-3175-g222acf5
createlink.c File Reference
#include "appwiz.h"
#include <commctrl.h>
#include <shellapi.h>
#include <strsafe.h>
Include dependency graph for createlink.c:

Go to the source code of this file.

Functions

BOOL IsShortcut (HKEY hKey)
 
BOOL IsExtensionAShortcut (LPWSTR lpExtension)
 
BOOL CreateShortcut (PCREATE_LINK_CONTEXT pContext)
 
BOOL CreateInternetShortcut (PCREATE_LINK_CONTEXT pContext)
 
BOOL IsInternetLocation (LPCWSTR pszLocation)
 
void DoConvertNameForFileSystem (LPWSTR szName)
 
BOOL DoValidateShortcutName (PCREATE_LINK_CONTEXT pContext)
 
INT_PTR CALLBACK WelcomeDlgProc (HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
 
INT_PTR CALLBACK FinishDlgProc (HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
 
static int CALLBACK PropSheetProc (HWND hwndDlg, UINT uMsg, LPARAM lParam)
 
LONG CALLBACK ShowCreateShortcutWizard (HWND hwndCPl, LPCWSTR szPath)
 
LONG CALLBACK NewLinkHereW (HWND hwndCPl, UINT uMsg, LPARAM lParam1, LPARAM lParam2)
 
LONG CALLBACK NewLinkHereA (HWND hwndCPl, UINT uMsg, LPARAM lParam1, LPARAM lParam2)
 

Function Documentation

◆ CreateInternetShortcut()

BOOL CreateInternetShortcut ( PCREATE_LINK_CONTEXT  pContext)

Definition at line 146 of file createlink.c.

147 {
148  IUniformResourceLocatorW *pURL = NULL;
149  IPersistFile *pPersistFile = NULL;
150  HRESULT hr;
153 
154  hr = CoCreateInstance(&CLSID_InternetShortcut, NULL, CLSCTX_ALL,
155  &IID_IUniformResourceLocatorW, (void **)&pURL);
156  if (FAILED(hr))
157  return FALSE;
158 
159  hr = IUnknown_QueryInterface(pURL, &IID_IPersistFile, (void **)&pPersistFile);
160  if (FAILED(hr))
161  {
162  IUnknown_Release(pURL);
163  return FALSE;
164  }
165 
166  pURL->lpVtbl->SetURL(pURL, pContext->szTarget, 0);
167 
168  hr = pPersistFile->lpVtbl->Save(pPersistFile, szPath, TRUE);
169 
170  IUnknown_Release(pPersistFile);
171  IUnknown_Release(pURL);
172 
173  return SUCCEEDED(hr);
174 }
HRESULT hr
Definition: shlfolder.c:183
#define TRUE
Definition: types.h:120
DWORD WINAPI GetFullPathNameW(IN LPCWSTR lpFileName, IN DWORD nBufferLength, OUT LPWSTR lpBuffer, OUT LPWSTR *lpFilePart)
Definition: path.c:1105
HRESULT Save([in, unique] LPCOLESTR pszFileName, [in] BOOL fRemember)
#define FALSE
Definition: types.h:117
if SUCCEEDED(hr)
__wchar_t WCHAR
Definition: xmlstorage.h:180
LONG HRESULT
Definition: typedefs.h:79
#define _countof(array)
Definition: sndvol32.h:68
#define MAX_PATH
Definition: compat.h:34
HRESULT WINAPI DECLSPEC_HOTPATCH CoCreateInstance(REFCLSID rclsid, LPUNKNOWN pUnkOuter, DWORD dwClsContext, REFIID iid, LPVOID *ppv)
Definition: compobj.c:3325
LPCWSTR szPath
Definition: env.c:37
#define NULL
Definition: types.h:112
const GUID IID_IPersistFile

Referenced by FinishDlgProc().

◆ CreateShortcut()

BOOL CreateShortcut ( PCREATE_LINK_CONTEXT  pContext)

Definition at line 75 of file createlink.c.

76 {
77  IShellLinkW *pShellLink, *pSourceShellLink;
78  IPersistFile *pPersistFile;
79  HRESULT hr;
82 
83  /* get the extension */
85 
87  {
88  hr = CoCreateInstance(&CLSID_ShellLink, NULL, CLSCTX_ALL, &IID_IShellLinkW, (void**)&pSourceShellLink);
89 
90  if (FAILED(hr))
91  return FALSE;
92 
93  hr = IUnknown_QueryInterface(pSourceShellLink, &IID_IPersistFile, (void**)&pPersistFile);
94  if (FAILED(hr))
95  {
96  IUnknown_Release(pSourceShellLink);
97  return FALSE;
98  }
99 
100  hr = pPersistFile->lpVtbl->Load(pPersistFile, (LPCOLESTR)pContext->szTarget, STGM_READ);
101  IUnknown_Release(pPersistFile);
102 
103  if (FAILED(hr))
104  {
105  IUnknown_Release(pSourceShellLink);
106  return FALSE;
107  }
108 
109  hr = IShellLinkW_GetPath(pSourceShellLink, Path, _countof(Path), NULL, 0);
110  IUnknown_Release(pSourceShellLink);
111 
112  if (FAILED(hr))
113  {
114  return FALSE;
115  }
116  }
117  else
118  {
119  StringCchCopyW(Path, _countof(Path), pContext->szTarget);
120  }
121 
122  hr = CoCreateInstance(&CLSID_ShellLink, NULL, CLSCTX_ALL,
123  &IID_IShellLinkW, (void**)&pShellLink);
124 
125  if (hr != S_OK)
126  return FALSE;
127 
128  pShellLink->lpVtbl->SetPath(pShellLink, Path);
129  pShellLink->lpVtbl->SetDescription(pShellLink, pContext->szDescription);
130  pShellLink->lpVtbl->SetWorkingDirectory(pShellLink, pContext->szWorkingDirectory);
131 
132  hr = IUnknown_QueryInterface(pShellLink, &IID_IPersistFile, (void**)&pPersistFile);
133  if (hr != S_OK)
134  {
135  IUnknown_Release(pShellLink);
136  return FALSE;
137  }
138 
139  hr = pPersistFile->lpVtbl->Save(pPersistFile, pContext->szLinkName, TRUE);
140  IUnknown_Release(pPersistFile);
141  IUnknown_Release(pShellLink);
142  return (hr == S_OK);
143 }
HRESULT hr
Definition: shlfolder.c:183
#define TRUE
Definition: types.h:120
HRESULT Save([in, unique] LPCOLESTR pszFileName, [in] BOOL fRemember)
#define FALSE
Definition: types.h:117
STRSAFEAPI StringCchCopyW(STRSAFE_LPWSTR pszDest, size_t cchDest, STRSAFE_LPCWSTR pszSrc)
Definition: strsafe.h:149
LPWSTR WINAPI PathFindExtensionW(LPCWSTR lpszPath)
Definition: path.c:447
#define STGM_READ
Definition: objbase.h:916
HRESULT SetWorkingDirectory([in] LPCWSTR pszDir)
__wchar_t WCHAR
Definition: xmlstorage.h:180
LONG HRESULT
Definition: typedefs.h:79
#define _countof(array)
Definition: sndvol32.h:68
#define MAX_PATH
Definition: compat.h:34
HRESULT SetDescription([in] LPCWSTR pszName)
_In_ LPCSTR _In_opt_ LPCSTR lpExtension
Definition: winbase.h:3050
HRESULT WINAPI DECLSPEC_HOTPATCH CoCreateInstance(REFCLSID rclsid, LPUNKNOWN pUnkOuter, DWORD dwClsContext, REFIID iid, LPVOID *ppv)
Definition: compobj.c:3325
#define S_OK
Definition: intsafe.h:52
PRTL_UNICODE_STRING_BUFFER Path
HRESULT SetPath([in] LPCWSTR pszFile)
#define NULL
Definition: types.h:112
HRESULT Load([in] LPCOLESTR pszFileName, [in] DWORD dwMode)
const GUID IID_IPersistFile
WCHAR * LPWSTR
Definition: xmlstorage.h:184

Referenced by FinishDlgProc().

◆ DoConvertNameForFileSystem()

void DoConvertNameForFileSystem ( LPWSTR  szName)

Definition at line 183 of file createlink.c.

184 {
185  LPWSTR pch1, pch2;
186  for (pch1 = pch2 = szName; *pch1; ++pch1)
187  {
188  if (wcschr(L"\\/:*?\"<>|", *pch1) != NULL)
189  {
190  /* *pch1 is an invalid character */
191  continue;
192  }
193  *pch2 = *pch1;
194  ++pch2;
195  }
196  *pch2 = 0;
197 }
_CONST_RETURN wchar_t *__cdecl wcschr(_In_z_ const wchar_t *_Str, wchar_t _Ch)
static const WCHAR L[]
Definition: oid.c:1250
#define NULL
Definition: types.h:112
static const WCHAR szName[]
Definition: msipriv.h:1194
WCHAR * LPWSTR
Definition: xmlstorage.h:184

Referenced by FinishDlgProc().

◆ DoValidateShortcutName()

BOOL DoValidateShortcutName ( PCREATE_LINK_CONTEXT  pContext)

Definition at line 200 of file createlink.c.

201 {
202  SIZE_T cch;
203  LPCWSTR pch, pszName = pContext->szDescription;
204 
205  if (!pszName || !pszName[0])
206  return FALSE;
207 
208  cch = wcslen(pContext->szOrigin) + wcslen(pszName) + 1;
209  if (cch >= MAX_PATH)
210  return FALSE;
211 
212  pch = pszName;
213  for (pch = pszName; *pch; ++pch)
214  {
215  if (wcschr(L"\\/:*?\"<>|", *pch) != NULL)
216  {
217  /* *pch is an invalid character */
218  return FALSE;
219  }
220  }
221 
222  return TRUE;
223 }
const WCHAR * LPCWSTR
Definition: xmlstorage.h:185
#define TRUE
Definition: types.h:120
#define pch(ap)
Definition: match.c:418
#define FALSE
Definition: types.h:117
_CONST_RETURN wchar_t *__cdecl wcschr(_In_z_ const wchar_t *_Str, wchar_t _Ch)
#define MAX_PATH
Definition: compat.h:34
static const WCHAR L[]
Definition: oid.c:1250
ULONG_PTR SIZE_T
Definition: typedefs.h:80
#define NULL
Definition: types.h:112
_CRTIMP size_t __cdecl wcslen(_In_z_ const wchar_t *_Str)
IN PCTCH IN DWORD cch
Definition: pager.h:36

Referenced by FinishDlgProc().

◆ FinishDlgProc()

INT_PTR CALLBACK FinishDlgProc ( HWND  hwndDlg,
UINT  uMsg,
WPARAM  wParam,
LPARAM  lParam 
)

Definition at line 364 of file createlink.c.

368 {
369  LPPROPSHEETPAGEW ppsp;
370  PCREATE_LINK_CONTEXT pContext;
371  LPPSHNOTIFY lppsn;
372  LPWSTR pch;
374  WCHAR szMessage[128];
375 
376  switch(uMsg)
377  {
378  case WM_INITDIALOG:
379  ppsp = (LPPROPSHEETPAGEW)lParam;
380  pContext = (PCREATE_LINK_CONTEXT) ppsp->lParam;
381  SetWindowLongPtr(hwndDlg, DWLP_USER, (LONG_PTR)pContext);
383  break;
384  case WM_COMMAND:
385  switch(HIWORD(wParam))
386  {
387  case EN_CHANGE:
389  {
391  StrTrimW(szText, L" \t");
392  if (szText[0])
394  else
396  }
397  else
398  {
400  }
401  break;
402  }
403  break;
404  case WM_NOTIFY:
405  lppsn = (LPPSHNOTIFY) lParam;
406  pContext = (PCREATE_LINK_CONTEXT) GetWindowLongPtr(hwndDlg, DWLP_USER);
407  if (lppsn->hdr.code == PSN_SETACTIVE)
408  {
409  /* TODO: Use shell32!PathCleanupSpec instead of DoConvertNameForFileSystem */
411  SetDlgItemTextW(hwndDlg, IDC_SHORTCUT_NAME, pContext->szDescription);
414  }
415  else if (lppsn->hdr.code == PSN_WIZFINISH)
416  {
417  GetDlgItemTextW(hwndDlg, IDC_SHORTCUT_NAME, pContext->szDescription, _countof(pContext->szDescription));
418  StrTrimW(pContext->szDescription, L" \t");
419 
420  if (!DoValidateShortcutName(pContext))
421  {
423 
424  LoadStringW(hApplet, IDS_INVALID_NAME, szMessage, _countof(szMessage));
425  MessageBoxW(hwndDlg, szMessage, NULL, MB_ICONERROR);
426 
427  /* prevent the wizard to go next */
428  SetWindowLongPtr(hwndDlg, DWLP_MSGRESULT, -1);
429  return TRUE;
430  }
431 
432  /* if old shortcut file exists, then delete it now */
433  DeleteFileW(pContext->szOldFile);
435 
436  if (IsInternetLocation(pContext->szTarget))
437  {
438  /* internet */
439  StringCchCopyW(pContext->szLinkName, _countof(pContext->szLinkName),
440  pContext->szOrigin);
441  PathAppendW(pContext->szLinkName, pContext->szDescription);
442 
443  /* change extension if any */
444  pch = PathFindExtensionW(pContext->szLinkName);
445  if (pch && *pch)
446  *pch = 0;
447  StringCchCatW(pContext->szLinkName, _countof(pContext->szLinkName), L".url");
448 
449  if (!CreateInternetShortcut(pContext))
450  {
451  LoadStringW(hApplet, IDS_CANTMAKEINETSHORTCUT, szMessage, _countof(szMessage));
452  MessageBoxW(hwndDlg, szMessage, NULL, MB_ICONERROR);
453  }
454  }
455  else
456  {
457  /* file */
458  StringCchCopyW(pContext->szLinkName, _countof(pContext->szLinkName),
459  pContext->szOrigin);
460  PathAppendW(pContext->szLinkName, pContext->szDescription);
461 
462  /* change extension if any */
463  pch = PathFindExtensionW(pContext->szLinkName);
464  if (pch && *pch)
465  *pch = 0;
466  StringCchCatW(pContext->szLinkName, _countof(pContext->szLinkName), L".lnk");
467 
468  if (!CreateShortcut(pContext))
469  {
470  WCHAR szMessage[128];
471  LoadStringW(hApplet, IDS_CANTMAKESHORTCUT, szMessage, _countof(szMessage));
472  MessageBoxW(hwndDlg, szMessage, NULL, MB_ICONERROR);
473  }
474  }
475  }
476  else if (lppsn->hdr.code == PSN_RESET && !lppsn->lParam)
477  {
478  /* The user has clicked [Cancel] */
479  DeleteFileW(pContext->szOldFile);
481  }
482  break;
483  }
484  return FALSE;
485 }
#define WM_GETTEXTLENGTH
Definition: winuser.h:1602
UINT WINAPI GetDlgItemTextW(HWND hDlg, int nIDDlgItem, LPWSTR lpString, int nMaxCount)
Definition: dialog.c:2263
struct _PSHNOTIFY * LPPSHNOTIFY
#define TRUE
Definition: types.h:120
HWND WINAPI SetFocus(_In_opt_ HWND)
HINSTANCE hApplet
Definition: access.c:17
#define SendDlgItemMessage
Definition: winuser.h:5818
#define PSN_SETACTIVE
Definition: prsht.h:115
int WINAPI LoadStringW(_In_opt_ HINSTANCE hInstance, _In_ UINT uID, _Out_writes_to_(cchBufferMax, return+1) LPWSTR lpBuffer, _In_ int cchBufferMax)
#define SetWindowLongPtr
Definition: treelist.c:70
WPARAM wParam
Definition: combotst.c:138
#define pch(ap)
Definition: match.c:418
#define DWLP_MSGRESULT
Definition: winuser.h:864
BOOL WINAPI PathAppendW(LPWSTR lpszPath, LPCWSTR lpszAppend)
Definition: path.c:126
STRSAFEAPI StringCchCatW(STRSAFE_LPWSTR pszDest, size_t cchDest, STRSAFE_LPCWSTR pszSrc)
Definition: strsafe.h:325
BOOL WINAPI SetDlgItemTextW(_In_ HWND, _In_ int, _In_ LPCWSTR)
UINT code
Definition: winuser.h:3135
#define IDS_CANTMAKESHORTCUT
Definition: resource.h:27
NMHDR hdr
Definition: prsht.h:330
#define FALSE
Definition: types.h:117
#define PSN_WIZFINISH
Definition: prsht.h:122
static const WCHAR szText[]
Definition: dialog.c:139
STRSAFEAPI StringCchCopyW(STRSAFE_LPWSTR pszDest, size_t cchDest, STRSAFE_LPCWSTR pszSrc)
Definition: strsafe.h:149
BOOL WINAPI DeleteFileW(IN LPCWSTR lpFileName)
Definition: delete.c:39
struct _PROPSHEETPAGEW * LPPROPSHEETPAGEW
#define PropSheet_SetWizButtons(d, f)
Definition: prsht.h:357
LPWSTR WINAPI PathFindExtensionW(LPCWSTR lpszPath)
Definition: path.c:447
#define IDS_CANTMAKEINETSHORTCUT
Definition: resource.h:26
#define PSWIZB_FINISH
Definition: prsht.h:155
int WINAPI MessageBoxW(_In_opt_ HWND, _In_opt_ LPCWSTR, _In_opt_ LPCWSTR, _In_ UINT)
HWND WINAPI GetDlgItem(_In_opt_ HWND, _In_ int)
__wchar_t WCHAR
Definition: xmlstorage.h:180
#define PSWIZB_BACK
Definition: prsht.h:153
#define _countof(array)
Definition: sndvol32.h:68
#define MAX_PATH
Definition: compat.h:34
#define IDC_SHORTCUT_NAME
Definition: resource.h:41
#define EM_SETSEL
Definition: winuser.h:2001
LRESULT WINAPI SendDlgItemMessageW(_In_ HWND, _In_ int, _In_ UINT, _In_ WPARAM, _In_ LPARAM)
#define IDS_INVALID_NAME
Definition: resource.h:31
EXTERN_C void WINAPI SHChangeNotify(LONG wEventId, UINT uFlags, LPCVOID dwItem1, LPCVOID dwItem2)
static const WCHAR L[]
Definition: oid.c:1250
LPARAM lParam
Definition: prsht.h:227
#define DWLP_USER
Definition: winuser.h:866
#define MB_ICONERROR
Definition: winuser.h:781
#define WM_COMMAND
Definition: winuser.h:1723
#define SHCNF_PATHW
Definition: shlobj.h:1764
struct CREATE_LINK_CONTEXT * PCREATE_LINK_CONTEXT
HWND WINAPI GetParent(_In_ HWND)
#define PSN_RESET
Definition: prsht.h:118
#define SHCNE_DELETE
Definition: shlobj.h:1731
__int3264 LONG_PTR
Definition: mstsclib_h.h:276
#define NULL
Definition: types.h:112
BOOL WINAPI StrTrimW(LPWSTR lpszStr, LPCWSTR lpszTrim)
Definition: string.c:1869
#define HIWORD(l)
Definition: typedefs.h:247
#define GetWindowLongPtr
Definition: treelist.c:73
WCHAR * LPWSTR
Definition: xmlstorage.h:184
LPARAM lParam
Definition: prsht.h:331
#define WM_INITDIALOG
Definition: winuser.h:1722
LPARAM lParam
Definition: combotst.c:139
#define WM_NOTIFY
Definition: richedit.h:61
#define EN_CHANGE
Definition: winuser.h:2005

Referenced by ShowCreateShortcutWizard().

◆ IsExtensionAShortcut()

BOOL IsExtensionAShortcut ( LPWSTR  lpExtension)

Definition at line 36 of file createlink.c.

37 {
38  HKEY hKey;
39  WCHAR Buffer[100];
40  DWORD Size;
41  DWORD Type;
42 
44  return FALSE;
45 
46  if (IsShortcut(hKey))
47  {
49  return TRUE;
50  }
51 
52  Size = sizeof(Buffer);
54  {
56  return FALSE;
57  }
58 
60 
62  return FALSE;
63 
64  if (IsShortcut(hKey))
65  {
67  return TRUE;
68  }
69 
71  return FALSE;
72 }
#define RegQueryValueEx
Definition: winreg.h:524
#define ERROR_SUCCESS
Definition: deptool.c:10
IN BOOLEAN OUT PSTR Buffer
Definition: progress.h:34
#define KEY_READ
Definition: nt_native.h:1023
#define TRUE
Definition: types.h:120
IN PVOID IN PVOID IN USHORT IN USHORT Size
Definition: pci.h:361
LONG WINAPI RegCloseKey(HKEY hKey)
Definition: reg.c:423
unsigned char * LPBYTE
Definition: typedefs.h:53
#define FALSE
Definition: types.h:117
Definition: bufpool.h:45
__wchar_t WCHAR
Definition: xmlstorage.h:180
Type
Definition: Type.h:6
unsigned long DWORD
Definition: ntddk_ex.h:95
_In_ LPCSTR _In_opt_ LPCSTR lpExtension
Definition: winbase.h:3050
FxAutoRegKey hKey
#define NULL
Definition: types.h:112
LONG WINAPI RegOpenKeyExW(HKEY hKey, LPCWSTR lpSubKey, DWORD ulOptions, REGSAM samDesired, PHKEY phkResult)
Definition: reg.c:3366
#define HKEY_CLASSES_ROOT
Definition: winreg.h:10
#define REG_SZ
Definition: layer.c:22

Referenced by CreateShortcut().

◆ IsInternetLocation()

BOOL IsInternetLocation ( LPCWSTR  pszLocation)

Definition at line 176 of file createlink.c.

177 {
178  return (PathIsURLW(pszLocation) || wcsstr(pszLocation, L"www.") == pszLocation);
179 }
_CONST_RETURN wchar_t *__cdecl wcsstr(_In_z_ const wchar_t *_Str, _In_z_ const wchar_t *_SubStr)
BOOL WINAPI PathIsURLW(LPCWSTR lpstrPath)
Definition: url.c:2432
static const WCHAR L[]
Definition: oid.c:1250

Referenced by FinishDlgProc(), and WelcomeDlgProc().

◆ IsShortcut()

BOOL IsShortcut ( HKEY  hKey)

Definition at line 19 of file createlink.c.

20 {
21  WCHAR Value[10];
22  DWORD Size;
23  DWORD Type;
24 
25  Size = sizeof(Value);
26  if (RegQueryValueExW(hKey, L"IsShortcut", NULL, &Type, (LPBYTE)Value, &Size) != ERROR_SUCCESS)
27  return FALSE;
28 
29  if (Type != REG_SZ)
30  return FALSE;
31 
32  return (wcsicmp(Value, L"yes") == 0);
33 }
#define ERROR_SUCCESS
Definition: deptool.c:10
IN PVOID IN PVOID IN USHORT IN USHORT Size
Definition: pci.h:361
unsigned char * LPBYTE
Definition: typedefs.h:53
#define FALSE
Definition: types.h:117
_Must_inspect_result_ _In_ WDFKEY _In_ PCUNICODE_STRING _Out_opt_ PUSHORT _Inout_opt_ PUNICODE_STRING Value
Definition: wdfregistry.h:406
LONG WINAPI RegQueryValueExW(_In_ HKEY hkeyorg, _In_ LPCWSTR name, _In_ LPDWORD reserved, _In_ LPDWORD type, _In_ LPBYTE data, _In_ LPDWORD count)
Definition: reg.c:4116
__wchar_t WCHAR
Definition: xmlstorage.h:180
Type
Definition: Type.h:6
unsigned long DWORD
Definition: ntddk_ex.h:95
#define wcsicmp
Definition: compat.h:15
static const WCHAR L[]
Definition: oid.c:1250
FxAutoRegKey hKey
#define NULL
Definition: types.h:112
#define REG_SZ
Definition: layer.c:22

Referenced by IsExtensionAShortcut().

◆ NewLinkHereA()

LONG CALLBACK NewLinkHereA ( HWND  hwndCPl,
UINT  uMsg,
LPARAM  lParam1,
LPARAM  lParam2 
)

Definition at line 617 of file createlink.c.

618 {
619  WCHAR szFile[MAX_PATH];
620 
621  if (MultiByteToWideChar(CP_ACP, 0, (LPSTR)lParam1, -1, szFile, _countof(szFile)))
622  {
624  return ShowCreateShortcutWizard(hwndCPl, szFile);
625  }
626  return -1;
627 }
#define CP_ACP
Definition: compat.h:109
char * LPSTR
Definition: xmlstorage.h:182
__wchar_t WCHAR
Definition: xmlstorage.h:180
#define _countof(array)
Definition: sndvol32.h:68
#define MAX_PATH
Definition: compat.h:34
#define MultiByteToWideChar
Definition: compat.h:110
VOID WINAPI InitCommonControls(void)
Definition: commctrl.c:863

◆ NewLinkHereW()

LONG CALLBACK NewLinkHereW ( HWND  hwndCPl,
UINT  uMsg,
LPARAM  lParam1,
LPARAM  lParam2 
)

Definition at line 609 of file createlink.c.

610 {
612  return ShowCreateShortcutWizard(hwndCPl, (LPWSTR)lParam1);
613 }
VOID WINAPI InitCommonControls(void)
Definition: commctrl.c:863
WCHAR * LPWSTR
Definition: xmlstorage.h:184

◆ PropSheetProc()

static int CALLBACK PropSheetProc ( HWND  hwndDlg,
UINT  uMsg,
LPARAM  lParam 
)
static

Definition at line 488 of file createlink.c.

489 {
490  // NOTE: This callback is needed to set large icon correctly.
491  HICON hIcon;
492  switch (uMsg)
493  {
494  case PSCB_INITIALIZED:
495  {
497  SendMessageW(hwndDlg, WM_SETICON, ICON_BIG, (LPARAM)hIcon);
498  break;
499  }
500  }
501  return 0;
502 }
static HICON
Definition: imagelist.c:84
HINSTANCE hApplet
Definition: access.c:17
LONG_PTR LPARAM
Definition: windef.h:208
#define PSCB_INITIALIZED
Definition: prsht.h:75
HICON hIcon
Definition: msconfig.c:44
LRESULT WINAPI SendMessageW(_In_ HWND, _In_ UINT, _In_ WPARAM, _In_ LPARAM)
HICON WINAPI LoadIconW(_In_opt_ HINSTANCE, _In_ LPCWSTR)
Definition: cursoricon.c:2044
#define MAKEINTRESOURCEW(i)
Definition: winuser.h:582
#define IDI_APPINETICO
Definition: resource.h:9
#define ICON_BIG
Definition: tnclass.cpp:51

Referenced by ShowCreateShortcutWizard().

◆ ShowCreateShortcutWizard()

LONG CALLBACK ShowCreateShortcutWizard ( HWND  hwndCPl,
LPCWSTR  szPath 
)

Definition at line 505 of file createlink.c.

506 {
507  PROPSHEETHEADERW psh;
508  HPROPSHEETPAGE ahpsp[2];
509  PROPSHEETPAGE psp;
510  UINT nPages = 0;
511  UINT nLength;
512  PCREATE_LINK_CONTEXT pContext;
513  WCHAR szMessage[128];
514  LPWSTR pch;
515 
516  pContext = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*pContext));
517  if (!pContext)
518  {
519  /* no memory */
520  LoadStringW(hApplet, IDS_NO_MEMORY, szMessage, _countof(szMessage));
521  MessageBoxW(hwndCPl, szMessage, NULL, MB_ICONERROR);
522  return FALSE;
523  }
524 
525  nLength = wcslen(szPath);
526  if (!nLength)
527  {
528  HeapFree(GetProcessHeap(), 0, pContext);
529 
530  /* no directory given */
531  LoadStringW(hApplet, IDS_NO_DIRECTORY, szMessage, _countof(szMessage));
532  MessageBoxW(hwndCPl, szMessage, NULL, MB_ICONERROR);
533  return FALSE;
534  }
535 
536  if (!PathFileExistsW(szPath))
537  {
538  HeapFree(GetProcessHeap(), 0, pContext);
539 
540  /* invalid path */
541  LoadStringW(hApplet, IDS_INVALID_PATH, szMessage, _countof(szMessage));
542  MessageBoxW(hwndCPl, szMessage, NULL, MB_ICONERROR);
543  return FALSE;
544  }
545 
546  /* build the pContext->szOrigin and pContext->szOldFile */
548  {
549  StringCchCopyW(pContext->szOrigin, _countof(pContext->szOrigin), szPath);
550  pContext->szOldFile[0] = 0;
551  }
552  else
553  {
554  StringCchCopyW(pContext->szOrigin, _countof(pContext->szOrigin), szPath);
555  pch = PathFindFileNameW(pContext->szOrigin);
556  if (pch && *pch)
557  *pch = 0;
558 
559  StringCchCopyW(pContext->szOldFile, _countof(pContext->szOldFile), szPath);
560 
562  if (pch && *pch)
563  {
564  /* build szDescription */
565  StringCchCopyW(pContext->szDescription, _countof(pContext->szDescription), pch);
566  *pch = 0;
567 
568  pch = PathFindExtensionW(pContext->szDescription);
569  *pch = 0;
570  }
571  }
572  PathAddBackslashW(pContext->szOrigin);
573 
574  /* Create the Welcome page */
575  psp.dwSize = sizeof(PROPSHEETPAGE);
576  psp.dwFlags = PSP_DEFAULT | PSP_HIDEHEADER;
577  psp.hInstance = hApplet;
578  psp.pfnDlgProc = WelcomeDlgProc;
579  psp.pszTemplate = MAKEINTRESOURCEW(IDD_SHORTCUT_LOCATION);
580  psp.lParam = (LPARAM)pContext;
581  ahpsp[nPages++] = CreatePropertySheetPage(&psp);
582 
583  /* Create the Finish page */
584  psp.dwFlags = PSP_DEFAULT | PSP_HIDEHEADER;
585  psp.pfnDlgProc = FinishDlgProc;
586  psp.pszTemplate = MAKEINTRESOURCEW(IDD_SHORTCUT_FINISH);
587  ahpsp[nPages++] = CreatePropertySheetPage(&psp);
588 
589  /* Create the property sheet */
590  psh.dwSize = sizeof(PROPSHEETHEADER);
591  psh.dwFlags = PSH_WIZARD97 | PSH_WATERMARK | PSH_USEICONID | PSH_USECALLBACK;
592  psh.hInstance = hApplet;
594  psh.hwndParent = NULL;
595  psh.nPages = nPages;
596  psh.nStartPage = 0;
597  psh.phpage = ahpsp;
598  psh.pszbmWatermark = MAKEINTRESOURCEW(IDB_SHORTCUT);
600 
601  /* Display the wizard */
602  PropertySheet(&psh);
603  HeapFree(GetProcessHeap(), 0, pContext);
604  return TRUE;
605 }
BOOL WINAPI PathIsDirectoryW(LPCWSTR lpszPath)
Definition: path.c:1722
HWND hwndParent
Definition: prsht.h:295
#define IDS_NO_MEMORY
Definition: resource.h:28
#define TRUE
Definition: types.h:120
_In_ DWORD nLength
Definition: wincon.h:473
HINSTANCE hApplet
Definition: access.c:17
#define PSH_USECALLBACK
Definition: prsht.h:48
int WINAPI LoadStringW(_In_opt_ HINSTANCE hInstance, _In_ UINT uID, _Out_writes_to_(cchBufferMax, return+1) LPWSTR lpBuffer, _In_ int cchBufferMax)
#define pch(ap)
Definition: match.c:418
#define PSH_USEICONID
Definition: prsht.h:42
#define FALSE
Definition: types.h:117
LPWSTR WINAPI PathAddBackslashW(LPWSTR lpszPath)
Definition: path.c:294
STRSAFEAPI StringCchCopyW(STRSAFE_LPWSTR pszDest, size_t cchDest, STRSAFE_LPCWSTR pszSrc)
Definition: strsafe.h:149
struct _PSP * HPROPSHEETPAGE
Definition: mstask.idl:90
PFNPROPSHEETCALLBACK pfnCallback
Definition: prsht.h:311
#define PROPSHEETHEADER
Definition: prsht.h:392
LPWSTR WINAPI PathFindFileNameW(LPCWSTR lpszPath)
Definition: path.c:394
LONG_PTR LPARAM
Definition: windef.h:208
BOOL WINAPI PathFileExistsW(LPCWSTR lpszPath)
Definition: path.c:1776
LPWSTR WINAPI PathFindExtensionW(LPCWSTR lpszPath)
Definition: path.c:447
#define CreatePropertySheetPage
Definition: prsht.h:399
#define PSP_DEFAULT
Definition: prsht.h:22
#define GetProcessHeap()
Definition: compat.h:595
PVOID WINAPI HeapAlloc(HANDLE, DWORD, SIZE_T)
int WINAPI MessageBoxW(_In_opt_ HWND, _In_opt_ LPCWSTR, _In_opt_ LPCWSTR, _In_ UINT)
__wchar_t WCHAR
Definition: xmlstorage.h:180
#define IDS_NO_DIRECTORY
Definition: resource.h:29
HINSTANCE hInstance
Definition: prsht.h:296
#define _countof(array)
Definition: sndvol32.h:68
LPCWSTR pszIcon
Definition: prsht.h:299
DWORD dwSize
Definition: prsht.h:293
DWORD dwFlags
Definition: prsht.h:294
#define IDD_SHORTCUT_LOCATION
Definition: resource.h:12
#define MB_ICONERROR
Definition: winuser.h:781
#define IDS_INVALID_PATH
Definition: resource.h:30
HPROPSHEETPAGE * phpage
Definition: prsht.h:309
LPCWSTR szPath
Definition: env.c:37
unsigned int UINT
Definition: ndis.h:50
#define NULL
Definition: types.h:112
#define HEAP_ZERO_MEMORY
Definition: compat.h:134
_CRTIMP size_t __cdecl wcslen(_In_z_ const wchar_t *_Str)
#define IDB_SHORTCUT
Definition: resource.h:18
#define PropertySheet
Definition: prsht.h:400
#define MAKEINTRESOURCEW(i)
Definition: winuser.h:582
#define IDI_APPINETICO
Definition: resource.h:9
WCHAR * LPWSTR
Definition: xmlstorage.h:184
#define IDD_SHORTCUT_FINISH
Definition: resource.h:13
#define HeapFree(x, y, z)
Definition: compat.h:594
#define PROPSHEETPAGE
Definition: prsht.h:389
UINT nStartPage
Definition: prsht.h:304

Referenced by NewLinkHereA(), and NewLinkHereW().

◆ WelcomeDlgProc()

INT_PTR CALLBACK WelcomeDlgProc ( HWND  hwndDlg,
UINT  uMsg,
WPARAM  wParam,
LPARAM  lParam 
)

Definition at line 227 of file createlink.c.

231 {
232  LPPROPSHEETPAGEW ppsp;
233  PCREATE_LINK_CONTEXT pContext;
234  LPPSHNOTIFY lppsn;
235  WCHAR szPath[MAX_PATH * 2];
236  WCHAR szDesc[100];
237  BROWSEINFOW brws;
238  LPITEMIDLIST pidllist;
239  LPWSTR pch;
241 
242  switch(uMsg)
243  {
244  case WM_INITDIALOG:
245  ppsp = (LPPROPSHEETPAGEW)lParam;
246  pContext = (PCREATE_LINK_CONTEXT) ppsp->lParam;
247  SetWindowLongPtr(hwndDlg, DWLP_USER, (LONG_PTR)pContext);
248  PropSheet_SetWizButtons(GetParent(hwndDlg), 0);
250  break;
251  case WM_COMMAND:
252  switch(HIWORD(wParam))
253  {
254  case EN_CHANGE:
256  {
258  }
259  else
260  {
261  PropSheet_SetWizButtons(GetParent(hwndDlg), 0);
262  }
263  break;
264  }
265  switch(LOWORD(wParam))
266  {
267  case IDC_SHORTCUT_BROWSE:
268  ZeroMemory(&brws, sizeof(brws));
269  brws.hwndOwner = hwndDlg;
270  brws.pidlRoot = NULL;
271  brws.pszDisplayName = szPath;
273  brws.lpfn = NULL;
274  pidllist = SHBrowseForFolderW(&brws);
275  if (!pidllist)
276  break;
277 
278  if (SHGetPathFromIDListW(pidllist, szPath))
279  {
283  }
284  /* Free memory, if possible */
285  CoTaskMemFree(pidllist);
286  break;
287  }
288  break;
289  case WM_NOTIFY:
290  lppsn = (LPPSHNOTIFY) lParam;
291  pContext = (PCREATE_LINK_CONTEXT)GetWindowLongPtr(hwndDlg, DWLP_USER);
292  if (lppsn->hdr.code == PSN_SETACTIVE)
293  {
294  SetDlgItemTextW(hwndDlg, IDC_SHORTCUT_LOCATION, pContext->szTarget);
295  }
296  else if (lppsn->hdr.code == PSN_WIZNEXT)
297  {
298  GetDlgItemTextW(hwndDlg, IDC_SHORTCUT_LOCATION, pContext->szTarget, _countof(pContext->szTarget));
299  StrTrimW(pContext->szTarget, L" \t");
300 
302  StringCchCopyW(pContext->szTarget, _countof(pContext->szTarget), szPath);
303 
304  if (IsInternetLocation(pContext->szTarget))
305  {
306  /* internet */
307  WCHAR szName[128];
309  StringCchCopyW(pContext->szDescription, _countof(pContext->szDescription), szName);
310 
311  pContext->szWorkingDirectory[0] = 0;
312  }
313  else if (GetFileAttributesW(pContext->szTarget) != INVALID_FILE_ATTRIBUTES)
314  {
315  /* file */
319 
320  /* get display name */
321  FileInfo.szDisplayName[0] = 0;
322  if (SHGetFileInfoW(pContext->szTarget, 0, &FileInfo, sizeof(FileInfo), SHGFI_DISPLAYNAME))
323  StringCchCopyW(pContext->szDescription, _countof(pContext->szDescription), FileInfo.szDisplayName);
324 
325  /* set working directory */
327  pContext->szTarget);
330  if (pch && *pch)
331  *pch = 0;
333  }
334  else
335  {
336  /* not found */
337  WCHAR szError[MAX_PATH + 100];
338 
340 
341  LoadStringW(hApplet, IDS_CREATE_SHORTCUT, szDesc, _countof(szDesc));
343  StringCchPrintfW(szError, _countof(szError), szPath, pContext->szTarget);
344  MessageBoxW(hwndDlg, szError, szDesc, MB_ICONERROR);
345 
346  /* prevent the wizard to go next */
347  SetWindowLongPtr(hwndDlg, DWLP_MSGRESULT, -1);
348  return TRUE;
349  }
350  }
351  else if (lppsn->hdr.code == PSN_RESET && !lppsn->lParam)
352  {
353  /* The user has clicked [Cancel] */
354  DeleteFileW(pContext->szOldFile);
356  }
357  break;
358  }
359  return FALSE;
360 }
#define WM_GETTEXTLENGTH
Definition: winuser.h:1602
UINT WINAPI GetDlgItemTextW(HWND hDlg, int nIDDlgItem, LPWSTR lpString, int nMaxCount)
Definition: dialog.c:2263
VOID WINAPI CoTaskMemFree(LPVOID ptr)
Definition: ifs.c:442
struct _PSHNOTIFY * LPPSHNOTIFY
#define TRUE
Definition: types.h:120
#define BIF_BROWSEINCLUDEFILES
Definition: shlobj.h:1159
BOOL WINAPI SHGetPathFromIDListW(LPCITEMIDLIST pidl, LPWSTR pszPath)
Definition: pidl.c:1294
#define PSWIZB_NEXT
Definition: prsht.h:154
HWND hwndOwner
Definition: shlobj.h:1127
#define ZeroMemory
Definition: winbase.h:1664
HWND WINAPI SetFocus(_In_opt_ HWND)
HINSTANCE hApplet
Definition: access.c:17
#define SendDlgItemMessage
Definition: winuser.h:5818
#define IDC_SHORTCUT_BROWSE
Definition: resource.h:40
#define PSN_SETACTIVE
Definition: prsht.h:115
int WINAPI LoadStringW(_In_opt_ HINSTANCE hInstance, _In_ UINT uID, _Out_writes_to_(cchBufferMax, return+1) LPWSTR lpBuffer, _In_ int cchBufferMax)
#define SetWindowLongPtr
Definition: treelist.c:70
WPARAM wParam
Definition: combotst.c:138
#define pch(ap)
Definition: match.c:418
#define DWLP_MSGRESULT
Definition: winuser.h:864
BOOL WINAPI SetDlgItemTextW(_In_ HWND, _In_ int, _In_ LPCWSTR)
UINT code
Definition: winuser.h:3135
NMHDR hdr
Definition: prsht.h:330
#define FALSE
Definition: types.h:117
LPWSTR pszDisplayName
Definition: shlobj.h:1129
DWORD WINAPI GetFileAttributesW(LPCWSTR lpFileName)
Definition: fileinfo.c:652
STRSAFEAPI StringCchCopyW(STRSAFE_LPWSTR pszDest, size_t cchDest, STRSAFE_LPCWSTR pszSrc)
Definition: strsafe.h:149
BOOL WINAPI DeleteFileW(IN LPCWSTR lpFileName)
Definition: delete.c:39
#define PSNRET_INVALID_NOCHANGEPAGE
Definition: prsht.h:131
struct _PROPSHEETPAGEW * LPPROPSHEETPAGEW
#define PSN_WIZNEXT
Definition: prsht.h:121
LPWSTR WINAPI PathFindFileNameW(LPCWSTR lpszPath)
Definition: path.c:394
#define SHGFI_DISPLAYNAME
Definition: shellapi.h:164
#define PropSheet_SetWizButtons(d, f)
Definition: prsht.h:357
HRESULT WINAPI SHAutoComplete(HWND hwndEdit, DWORD dwFlags)
Definition: autocomp.cpp:191
int WINAPI MessageBoxW(_In_opt_ HWND, _In_opt_ LPCWSTR, _In_opt_ LPCWSTR, _In_ UINT)
HWND WINAPI GetDlgItem(_In_opt_ HWND, _In_ int)
__wchar_t WCHAR
Definition: xmlstorage.h:180
DWORD_PTR WINAPI SHGetFileInfoW(LPCWSTR path, DWORD dwFileAttributes, SHFILEINFOW *psfi, UINT sizeofpsfi, UINT flags)
Definition: shell32_main.c:414
#define _countof(array)
Definition: sndvol32.h:68
#define MAX_PATH
Definition: compat.h:34
#define EM_SETSEL
Definition: winuser.h:2001
LRESULT WINAPI SendDlgItemMessageW(_In_ HWND, _In_ int, _In_ UINT, _In_ WPARAM, _In_ LPARAM)
#define INVALID_FILE_ATTRIBUTES
Definition: vfdcmd.c:23
EXTERN_C void WINAPI SHChangeNotify(LONG wEventId, UINT uFlags, LPCVOID dwItem1, LPCVOID dwItem2)
#define IDC_SHORTCUT_LOCATION
Definition: resource.h:39
#define IDS_CREATE_SHORTCUT
Definition: resource.h:23
static const WCHAR L[]
Definition: oid.c:1250
LPARAM lParam
Definition: prsht.h:227
#define DWLP_USER
Definition: winuser.h:866
#define MB_ICONERROR
Definition: winuser.h:781
#define WM_COMMAND
Definition: winuser.h:1723
PCIDLIST_ABSOLUTE pidlRoot
Definition: shlobj.h:1128
LPWSTR WINAPI PathRemoveBackslashW(LPWSTR lpszPath)
Definition: path.c:867
#define SHCNF_PATHW
Definition: shlobj.h:1764
struct CREATE_LINK_CONTEXT * PCREATE_LINK_CONTEXT
LPITEMIDLIST WINAPI SHBrowseForFolderW(LPBROWSEINFOW lpbi)
Definition: brsfolder.c:1411
HWND WINAPI GetParent(_In_ HWND)
UINT ulFlags
Definition: shlobj.h:1131
LPCWSTR szPath
Definition: env.c:37
#define PSN_RESET
Definition: prsht.h:118
#define SHCNE_DELETE
Definition: shlobj.h:1731
STRSAFEAPI StringCchPrintfW(STRSAFE_LPWSTR pszDest, size_t cchDest, STRSAFE_LPCWSTR pszFormat,...)
Definition: strsafe.h:530
BFFCALLBACK lpfn
Definition: shlobj.h:1132
__int3264 LONG_PTR
Definition: mstsclib_h.h:276
#define NULL
Definition: types.h:112
DWORD WINAPI ExpandEnvironmentStringsW(IN LPCWSTR lpSrc, IN LPWSTR lpDst, IN DWORD nSize)
Definition: environ.c:519
#define IDS_ERROR_NOT_FOUND
Definition: resource.h:24
BOOL WINAPI StrTrimW(LPWSTR lpszStr, LPCWSTR lpszTrim)
Definition: string.c:1869
static const WCHAR szName[]
Definition: msipriv.h:1194
struct FileInfo FileInfo
#define SHACF_DEFAULT
Definition: shlwapi.h:1911
#define HIWORD(l)
Definition: typedefs.h:247
#define GetWindowLongPtr
Definition: treelist.c:73
#define WM_SETFOCUS
Definition: winuser.h:1596
WCHAR * LPWSTR
Definition: xmlstorage.h:184
#define IDS_NEW_INTERNET_SHORTCUT
Definition: resource.h:25
LPARAM lParam
Definition: prsht.h:331
ITEMIDLIST UNALIGNED * LPITEMIDLIST
Definition: shtypes.idl:41
#define WM_INITDIALOG
Definition: winuser.h:1722
LPARAM lParam
Definition: combotst.c:139
#define LOWORD(l)
Definition: pedump.c:82
#define WM_NOTIFY
Definition: richedit.h:61
#define EN_CHANGE
Definition: winuser.h:2005

Referenced by ShowCreateShortcutWizard().