ReactOS  0.4.14-dev-55-g2da92ac
createlink.c File Reference
#include "appwiz.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)
 
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, LPWSTR 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 144 of file createlink.c.

145 {
146  IUniformResourceLocatorW *pURL = NULL;
147  IPersistFile *pPersistFile = NULL;
148  HRESULT hr;
151 
152  hr = CoCreateInstance(&CLSID_InternetShortcut, NULL, CLSCTX_ALL,
153  &IID_IUniformResourceLocatorW, (void **)&pURL);
154  if (FAILED(hr))
155  return FALSE;
156 
157  hr = IUnknown_QueryInterface(pURL, &IID_IPersistFile, (void **)&pPersistFile);
158  if (FAILED(hr))
159  {
160  IUnknown_Release(pURL);
161  return FALSE;
162  }
163 
164  pURL->lpVtbl->SetURL(pURL, pContext->szTarget, 0);
165 
166  hr = pPersistFile->lpVtbl->Save(pPersistFile, szPath, TRUE);
167 
168  IUnknown_Release(pPersistFile);
169  IUnknown_Release(pURL);
170 
171  return SUCCEEDED(hr);
172 }
#define TRUE
Definition: types.h:120
HRESULT hr
Definition: shlfolder.c:183
#define _countof(array)
Definition: fontsub.cpp:30
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)
smooth NULL
Definition: ftsmooth.c:416
__wchar_t WCHAR
Definition: xmlstorage.h:180
LONG HRESULT
Definition: typedefs.h:77
#define MAX_PATH
Definition: compat.h:26
HRESULT WINAPI DECLSPEC_HOTPATCH CoCreateInstance(REFCLSID rclsid, LPUNKNOWN pUnkOuter, DWORD dwClsContext, REFIID iid, LPVOID *ppv)
Definition: compobj.c:3234
LPCWSTR szPath
Definition: env.c:35
const GUID IID_IPersistFile
#define SUCCEEDED(hr)
Definition: intsafe.h:57

Referenced by FinishDlgProc().

◆ CreateShortcut()

BOOL CreateShortcut ( PCREATE_LINK_CONTEXT  pContext)

Definition at line 73 of file createlink.c.

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

Referenced by FinishDlgProc().

◆ FinishDlgProc()

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

Definition at line 288 of file createlink.c.

292 {
293  LPPROPSHEETPAGEW ppsp;
294  PCREATE_LINK_CONTEXT pContext;
295  LPPSHNOTIFY lppsn;
296 
297  switch(uMsg)
298  {
299  case WM_INITDIALOG:
300  ppsp = (LPPROPSHEETPAGEW)lParam;
301  pContext = (PCREATE_LINK_CONTEXT) ppsp->lParam;
302  SetWindowLongPtr(hwndDlg, DWLP_USER, (LONG_PTR)pContext);
303  SetDlgItemTextW(hwndDlg, IDC_SHORTCUT_NAME, pContext->szDescription);
305  break;
306  case WM_COMMAND:
307  switch(HIWORD(wParam))
308  {
309  case EN_CHANGE:
311  {
313  }
314  else
315  {
317  }
318  break;
319  }
320  break;
321  case WM_NOTIFY:
322  lppsn = (LPPSHNOTIFY) lParam;
323  pContext = (PCREATE_LINK_CONTEXT) GetWindowLongPtr(hwndDlg, DWLP_USER);
324  if (lppsn->hdr.code == PSN_WIZFINISH)
325  {
326  LPWSTR pch;
327  DWORD attrs;
329  StrTrimW(pContext->szDescription, L" \t");
330 
331  /* if old shortcut file exists, then delete it now */
332  attrs = GetFileAttributesW(pContext->szOldFile);
333  if (attrs != INVALID_FILE_ATTRIBUTES && !(attrs & FILE_ATTRIBUTE_DIRECTORY))
334  {
335  DeleteFileW(pContext->szOldFile);
336  }
337 
338  if (IsInternetLocation(pContext->szTarget))
339  {
340  /* internet */
341  StringCchCopyW(pContext->szLinkName, _countof(pContext->szLinkName),
342  pContext->szOrigin);
343  PathAppendW(pContext->szLinkName, pContext->szDescription);
344 
345  /* change extension if any */
346  pch = PathFindExtensionW(pContext->szLinkName);
347  if (pch && *pch)
348  *pch = 0;
349  StringCchCatW(pContext->szLinkName, _countof(pContext->szLinkName), L".url");
350 
351  if (!CreateInternetShortcut(pContext))
352  {
353  WCHAR szMessage[128];
354  LoadStringW(hApplet, IDS_CANTMAKEINETSHORTCUT, szMessage, _countof(szMessage));
355  MessageBoxW(hwndDlg, szMessage, NULL, MB_ICONERROR);
356  }
357  }
358  else
359  {
360  /* file */
361  StringCchCopyW(pContext->szLinkName, _countof(pContext->szLinkName),
362  pContext->szOrigin);
363  PathAppendW(pContext->szLinkName, pContext->szDescription);
364 
365  /* change extension if any */
366  pch = PathFindExtensionW(pContext->szLinkName);
367  if (pch && *pch)
368  *pch = 0;
369  StringCchCatW(pContext->szLinkName, _countof(pContext->szLinkName), L".lnk");
370 
371  if (!CreateShortcut(pContext))
372  {
373  WCHAR szMessage[128];
374  LoadStringW(hApplet, IDS_CANTMAKESHORTCUT, szMessage, _countof(szMessage));
375  MessageBoxW(hwndDlg, szMessage, NULL, MB_ICONERROR);
376  }
377  }
378  }
379  break;
380  }
381  return FALSE;
382 }
#define WM_GETTEXTLENGTH
Definition: winuser.h:1601
UINT WINAPI GetDlgItemTextW(HWND hDlg, int nIDDlgItem, LPWSTR lpString, int nMaxCount)
Definition: dialog.c:2208
struct _PSHNOTIFY * LPPSHNOTIFY
#define _countof(array)
Definition: fontsub.cpp:30
HINSTANCE hApplet
Definition: access.c:17
#define SendDlgItemMessage
Definition: winuser.h:5743
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
BOOL WINAPI PathAppendW(LPWSTR lpszPath, LPCWSTR lpszAppend)
Definition: path.c:121
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:3133
#define IDS_CANTMAKESHORTCUT
Definition: resource.h:27
NMHDR hdr
Definition: prsht.h:312
#define PSN_WIZFINISH
Definition: prsht.h:122
DWORD WINAPI GetFileAttributesW(LPCWSTR lpFileName)
Definition: fileinfo.c:802
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
smooth NULL
Definition: ftsmooth.c:416
struct _PROPSHEETPAGEW * LPPROPSHEETPAGEW
#define PropSheet_SetWizButtons(d, f)
Definition: prsht.h:339
LPWSTR WINAPI PathFindExtensionW(LPCWSTR lpszPath)
Definition: path.c:442
#define IDS_CANTMAKEINETSHORTCUT
Definition: resource.h:26
#define FILE_ATTRIBUTE_DIRECTORY
Definition: nt_native.h:705
#define PSWIZB_FINISH
Definition: prsht.h:155
int WINAPI MessageBoxW(_In_opt_ HWND, _In_opt_ LPCWSTR, _In_opt_ LPCWSTR, _In_ UINT)
__wchar_t WCHAR
Definition: xmlstorage.h:180
#define PSWIZB_BACK
Definition: prsht.h:153
#define MAX_PATH
Definition: compat.h:26
#define IDC_SHORTCUT_NAME
Definition: resource.h:40
unsigned long DWORD
Definition: ntddk_ex.h:95
#define INVALID_FILE_ATTRIBUTES
Definition: vfdcmd.c:23
static const WCHAR L[]
Definition: oid.c:1250
LPARAM lParam
Definition: prsht.h:218
#define DWLP_USER
Definition: winuser.h:866
#define MB_ICONERROR
Definition: winuser.h:781
#define WM_COMMAND
Definition: winuser.h:1722
struct CREATE_LINK_CONTEXT * PCREATE_LINK_CONTEXT
HWND WINAPI GetParent(_In_ HWND)
__int3264 LONG_PTR
Definition: mstsclib_h.h:276
BOOL WINAPI StrTrimW(LPWSTR lpszStr, LPCWSTR lpszTrim)
Definition: string.c:1869
#define HIWORD(l)
Definition: typedefs.h:246
#define GetWindowLongPtr
Definition: treelist.c:73
WCHAR * LPWSTR
Definition: xmlstorage.h:184
#define WM_INITDIALOG
Definition: winuser.h:1721
LPARAM lParam
Definition: combotst.c:139
#define WM_NOTIFY
Definition: richedit.h:61
#define EN_CHANGE
Definition: winuser.h:2004

Referenced by ShowCreateShortcutWizard().

◆ IsExtensionAShortcut()

BOOL IsExtensionAShortcut ( LPWSTR  lpExtension)

Definition at line 34 of file createlink.c.

35 {
36  HKEY hKey;
37  WCHAR Buffer[100];
38  DWORD Size;
39  DWORD Type;
40 
42  return FALSE;
43 
44  if (IsShortcut(hKey))
45  {
46  RegCloseKey(hKey);
47  return TRUE;
48  }
49 
50  Size = sizeof(Buffer);
52  {
53  RegCloseKey(hKey);
54  return FALSE;
55  }
56 
57  RegCloseKey(hKey);
58 
60  return FALSE;
61 
62  if (IsShortcut(hKey))
63  {
64  RegCloseKey(hKey);
65  return TRUE;
66  }
67 
68  RegCloseKey(hKey);
69  return FALSE;
70 }
#define RegQueryValueEx
Definition: winreg.h:524
#define TRUE
Definition: types.h:120
Type
Definition: Type.h:6
#define ERROR_SUCCESS
Definition: deptool.c:10
#define KEY_READ
Definition: nt_native.h:1023
LONG WINAPI RegCloseKey(HKEY hKey)
Definition: reg.c:423
unsigned char * LPBYTE
Definition: typedefs.h:52
smooth NULL
Definition: ftsmooth.c:416
Definition: bufpool.h:45
__wchar_t WCHAR
Definition: xmlstorage.h:180
unsigned long DWORD
Definition: ntddk_ex.h:95
IN PVOID IN PVOID IN USHORT IN USHORT Size
Definition: pci.h:359
_In_ LPCSTR _In_opt_ LPCSTR lpExtension
Definition: winbase.h:3011
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
IN BOOLEAN OUT PSTR Buffer
Definition: progress.h:34
#define REG_SZ
Definition: layer.c:22

Referenced by CreateShortcut().

◆ IsInternetLocation()

BOOL IsInternetLocation ( LPCWSTR  pszLocation)

Definition at line 174 of file createlink.c.

175 {
176  return (PathIsURLW(pszLocation) || wcsstr(pszLocation, L"www.") == pszLocation);
177 }
_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 17 of file createlink.c.

18 {
19  WCHAR Value[10];
20  DWORD Size;
21  DWORD Type;
22 
23  Size = sizeof(Value);
24  if (RegQueryValueExW(hKey, L"IsShortcut", NULL, &Type, (LPBYTE)Value, &Size) != ERROR_SUCCESS)
25  return FALSE;
26 
27  if (Type != REG_SZ)
28  return FALSE;
29 
30  return (wcsicmp(Value, L"yes") == 0);
31 }
_In_opt_ ULONG _Out_ PULONG Value
Definition: rtlfuncs.h:2343
Type
Definition: Type.h:6
#define ERROR_SUCCESS
Definition: deptool.c:10
unsigned char * LPBYTE
Definition: typedefs.h:52
smooth NULL
Definition: ftsmooth.c:416
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
unsigned long DWORD
Definition: ntddk_ex.h:95
static const WCHAR L[]
Definition: oid.c:1250
IN PVOID IN PVOID IN USHORT IN USHORT Size
Definition: pci.h:359
#define wcsicmp
Definition: string.h:1152
#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 506 of file createlink.c.

507 {
508  WCHAR szFile[MAX_PATH];
509 
510  if (MultiByteToWideChar(CP_ACP, 0, (LPSTR) lParam1, -1, szFile, MAX_PATH))
511  {
512  return ShowCreateShortcutWizard(hwndCPl, szFile);
513  }
514  return -1;
515 }
#define CP_ACP
Definition: compat.h:99
char * LPSTR
Definition: xmlstorage.h:182
__wchar_t WCHAR
Definition: xmlstorage.h:180
#define MAX_PATH
Definition: compat.h:26
#define MultiByteToWideChar
Definition: compat.h:100

◆ NewLinkHereW()

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

Definition at line 499 of file createlink.c.

500 {
501  return ShowCreateShortcutWizard(hwndCPl, (LPWSTR) lParam1);
502 }
WCHAR * LPWSTR
Definition: xmlstorage.h:184

◆ PropSheetProc()

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

Definition at line 385 of file createlink.c.

386 {
387  // NOTE: This callback is needed to set large icon correctly.
388  HICON hIcon;
389  switch (uMsg)
390  {
391  case PSCB_INITIALIZED:
392  {
394  SendMessageW(hwndDlg, WM_SETICON, ICON_BIG, (LPARAM)hIcon);
395  break;
396  }
397  }
398  return 0;
399 }
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,
LPWSTR  szPath 
)

Definition at line 402 of file createlink.c.

403 {
404  PROPSHEETHEADERW psh;
405  HPROPSHEETPAGE ahpsp[2];
406  PROPSHEETPAGE psp;
407  UINT nPages = 0;
408  UINT nLength;
409  DWORD attrs;
410  PCREATE_LINK_CONTEXT pContext;
411  WCHAR szMessage[128];
412 
413  pContext = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*pContext));
414  if (!pContext)
415  {
416  /* no memory */
417  LoadStringW(hApplet, IDS_NO_MEMORY, szMessage, _countof(szMessage));
418  MessageBoxW(hwndCPl, szMessage, NULL, MB_ICONERROR);
419  return FALSE;
420  }
421 
422  nLength = wcslen(szPath);
423  if (!nLength)
424  {
425  HeapFree(GetProcessHeap(), 0, pContext);
426 
427  /* no directory given */
428  LoadStringW(hApplet, IDS_NO_DIRECTORY, szMessage, _countof(szMessage));
429  MessageBoxW(hwndCPl, szMessage, NULL, MB_ICONERROR);
430  return FALSE;
431  }
432 
433  attrs = GetFileAttributesW(szPath);
434  if (attrs == INVALID_FILE_ATTRIBUTES)
435  {
436  HeapFree(GetProcessHeap(), 0, pContext);
437 
438  /* invalid path */
439  LoadStringW(hApplet, IDS_INVALID_PATH, szMessage, _countof(szMessage));
440  MessageBoxW(hwndCPl, szMessage, NULL, MB_ICONERROR);
441  return FALSE;
442  }
443 
444  /* build the pContext->szOrigin and pContext->szOldFile */
445  StringCchCopyW(pContext->szOrigin, _countof(pContext->szOrigin), szPath);
446  pContext->szOldFile[0] = 0;
447  if (!(attrs & FILE_ATTRIBUTE_DIRECTORY))
448  {
449  LPWSTR pch;
450  StringCchCopyW(pContext->szOldFile, _countof(pContext->szOldFile), szPath);
451  pch = PathFindFileNameW(pContext->szOrigin);
452  if (pch && *pch)
453  {
454  /* build szDescription */
455  StringCchCopyW(pContext->szDescription, _countof(pContext->szDescription), pch);
456  *pch = 0;
457 
458  pch = PathFindExtensionW(pContext->szDescription);
459  *pch = 0;
460  }
461  }
462  PathAddBackslashW(pContext->szOrigin);
463 
464  /* Create the Welcome page */
465  psp.dwSize = sizeof(PROPSHEETPAGE);
466  psp.dwFlags = PSP_DEFAULT | PSP_HIDEHEADER;
467  psp.hInstance = hApplet;
468  psp.pfnDlgProc = WelcomeDlgProc;
469  psp.pszTemplate = MAKEINTRESOURCEW(IDD_SHORTCUT_LOCATION);
470  psp.lParam = (LPARAM)pContext;
471  ahpsp[nPages++] = CreatePropertySheetPage(&psp);
472 
473  /* Create the Finish page */
474  psp.dwFlags = PSP_DEFAULT | PSP_HIDEHEADER;
475  psp.pfnDlgProc = FinishDlgProc;
476  psp.pszTemplate = MAKEINTRESOURCEW(IDD_SHORTCUT_FINISH);
477  ahpsp[nPages++] = CreatePropertySheetPage(&psp);
478 
479  /* Create the property sheet */
480  psh.dwSize = sizeof(PROPSHEETHEADER);
481  psh.dwFlags = PSH_WIZARD97 | PSH_WATERMARK | PSH_USEICONID | PSH_USECALLBACK;
482  psh.hInstance = hApplet;
484  psh.hwndParent = NULL;
485  psh.nPages = nPages;
486  psh.nStartPage = 0;
487  psh.phpage = ahpsp;
488  psh.pszbmWatermark = MAKEINTRESOURCEW(IDB_SHORTCUT);
490 
491  /* Display the wizard */
492  PropertySheet(&psh);
493  HeapFree(GetProcessHeap(), 0, pContext);
494  return TRUE;
495 }
HWND hwndParent
Definition: prsht.h:277
#define TRUE
Definition: types.h:120
#define IDS_NO_MEMORY
Definition: resource.h:28
#define _countof(array)
Definition: fontsub.cpp:30
_In_ DWORD nLength
Definition: wincon.h:461
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
LPWSTR WINAPI PathAddBackslashW(LPWSTR lpszPath)
Definition: path.c:289
DWORD WINAPI GetFileAttributesW(LPCWSTR lpFileName)
Definition: fileinfo.c:802
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:293
smooth NULL
Definition: ftsmooth.c:416
#define PROPSHEETHEADER
Definition: prsht.h:374
LPWSTR WINAPI PathFindFileNameW(LPCWSTR lpszPath)
Definition: path.c:389
LONG_PTR LPARAM
Definition: windef.h:208
LPWSTR WINAPI PathFindExtensionW(LPCWSTR lpszPath)
Definition: path.c:442
#define CreatePropertySheetPage
Definition: prsht.h:381
#define FILE_ATTRIBUTE_DIRECTORY
Definition: nt_native.h:705
#define PSP_DEFAULT
Definition: prsht.h:22
#define GetProcessHeap()
Definition: compat.h:395
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:278
LPCWSTR pszIcon
Definition: prsht.h:281
unsigned long DWORD
Definition: ntddk_ex.h:95
DWORD dwSize
Definition: prsht.h:275
#define INVALID_FILE_ATTRIBUTES
Definition: vfdcmd.c:23
DWORD dwFlags
Definition: prsht.h:276
#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:291
LPCWSTR szPath
Definition: env.c:35
unsigned int UINT
Definition: ndis.h:50
#define HEAP_ZERO_MEMORY
Definition: compat.h:123
#define IDB_SHORTCUT
Definition: resource.h:18
#define PropertySheet
Definition: prsht.h:382
#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
size_t __cdecl wcslen(_In_z_ const wchar_t *_Str)
#define HeapFree(x, y, z)
Definition: compat.h:394
#define PROPSHEETPAGE
Definition: prsht.h:371
UINT nStartPage
Definition: prsht.h:286

Referenced by NewLinkHereA(), and NewLinkHereW().

◆ WelcomeDlgProc()

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

Definition at line 181 of file createlink.c.

185 {
186  LPPROPSHEETPAGEW ppsp;
187  PCREATE_LINK_CONTEXT pContext;
188  LPPSHNOTIFY lppsn;
190  WCHAR szDesc[100];
191  BROWSEINFOW brws;
192  LPITEMIDLIST pidllist;
193 
194  switch(uMsg)
195  {
196  case WM_INITDIALOG:
197  ppsp = (LPPROPSHEETPAGEW)lParam;
198  pContext = (PCREATE_LINK_CONTEXT) ppsp->lParam;
199  SetWindowLongPtr(hwndDlg, DWLP_USER, (LONG_PTR)pContext);
200  PropSheet_SetWizButtons(GetParent(hwndDlg), 0);
201  break;
202  case WM_COMMAND:
203  switch(HIWORD(wParam))
204  {
205  case EN_CHANGE:
207  {
209  }
210  else
211  {
212  PropSheet_SetWizButtons(GetParent(hwndDlg), 0);
213  }
214  break;
215  }
216  switch(LOWORD(wParam))
217  {
218  case IDC_SHORTCUT_BROWSE:
219  ZeroMemory(&brws, sizeof(brws));
220  brws.hwndOwner = hwndDlg;
221  brws.pidlRoot = NULL;
222  brws.pszDisplayName = szPath;
224  brws.lpfn = NULL;
225  pidllist = SHBrowseForFolderW(&brws);
226  if (!pidllist)
227  break;
228 
229  if (SHGetPathFromIDListW(pidllist, szPath))
231 
232  /* Free memory, if possible */
233  CoTaskMemFree(pidllist);
234  break;
235  }
236  break;
237  case WM_NOTIFY:
238  lppsn = (LPPSHNOTIFY) lParam;
239  if (lppsn->hdr.code == PSN_WIZNEXT)
240  {
241  LPWSTR pch;
242  pContext = (PCREATE_LINK_CONTEXT) GetWindowLongPtr(hwndDlg, DWLP_USER);
243  GetDlgItemTextW(hwndDlg, IDC_SHORTCUT_LOCATION, pContext->szTarget, _countof(pContext->szTarget));
244  StrTrimW(pContext->szTarget, L" \t");
245 
246  if (IsInternetLocation(pContext->szTarget))
247  {
248  /* internet */
249  WCHAR szName[128];
251  StringCchCopyW(pContext->szDescription, _countof(pContext->szDescription), szName);
252 
253  pContext->szWorkingDirectory[0] = 0;
254  }
255  else if (GetFileAttributesW(pContext->szTarget) != INVALID_FILE_ATTRIBUTES)
256  {
257  /* file */
261 
262  /* set working directory */
264  pContext->szTarget);
267  if (pch && *pch)
268  *pch = 0;
270  }
271  else
272  {
273  /* not found */
274  WCHAR szError[MAX_PATH + 100];
275  LoadStringW(hApplet, IDS_CREATE_SHORTCUT, szDesc, _countof(szDesc));
277  StringCchPrintfW(szError, _countof(szError), szPath, pContext->szTarget);
278  MessageBoxW(hwndDlg, szError, szDesc, MB_ICONERROR);
279  }
280  }
281  break;
282  }
283  return FALSE;
284 }
#define WM_GETTEXTLENGTH
Definition: winuser.h:1601
UINT WINAPI GetDlgItemTextW(HWND hDlg, int nIDDlgItem, LPWSTR lpString, int nMaxCount)
Definition: dialog.c:2208
VOID WINAPI CoTaskMemFree(LPVOID ptr)
Definition: ifs.c:422
struct _PSHNOTIFY * LPPSHNOTIFY
#define _countof(array)
Definition: fontsub.cpp:30
#define BIF_BROWSEINCLUDEFILES
Definition: shlobj.h:1150
BOOL WINAPI SHGetPathFromIDListW(LPCITEMIDLIST pidl, LPWSTR pszPath)
Definition: pidl.c:1280
#define PSWIZB_NEXT
Definition: prsht.h:154
HWND hwndOwner
Definition: shlobj.h:1118
#define ZeroMemory
Definition: winbase.h:1635
HWND WINAPI SetFocus(_In_opt_ HWND)
HINSTANCE hApplet
Definition: access.c:17
#define SendDlgItemMessage
Definition: winuser.h:5743
#define IDC_SHORTCUT_BROWSE
Definition: resource.h:39
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:3133
NMHDR hdr
Definition: prsht.h:312
LPWSTR pszDisplayName
Definition: shlobj.h:1120
DWORD WINAPI GetFileAttributesW(LPCWSTR lpFileName)
Definition: fileinfo.c:802
STRSAFEAPI StringCchCopyW(STRSAFE_LPWSTR pszDest, size_t cchDest, STRSAFE_LPCWSTR pszSrc)
Definition: strsafe.h:149
#define PSNRET_INVALID_NOCHANGEPAGE
Definition: prsht.h:131
smooth NULL
Definition: ftsmooth.c:416
struct _PROPSHEETPAGEW * LPPROPSHEETPAGEW
#define PSN_WIZNEXT
Definition: prsht.h:121
LPWSTR WINAPI PathFindFileNameW(LPCWSTR lpszPath)
Definition: path.c:389
#define PropSheet_SetWizButtons(d, f)
Definition: prsht.h:339
LPCITEMIDLIST pidlRoot
Definition: shlobj.h:1119
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 MAX_PATH
Definition: compat.h:26
#define EM_SETSEL
Definition: winuser.h:2000
#define INVALID_FILE_ATTRIBUTES
Definition: vfdcmd.c:23
#define IDC_SHORTCUT_LOCATION
Definition: resource.h:38
#define IDS_CREATE_SHORTCUT
Definition: resource.h:23
static const WCHAR L[]
Definition: oid.c:1250
LPARAM lParam
Definition: prsht.h:218
#define DWLP_USER
Definition: winuser.h:866
#define MB_ICONERROR
Definition: winuser.h:781
#define WM_COMMAND
Definition: winuser.h:1722
LPWSTR WINAPI PathRemoveBackslashW(LPWSTR lpszPath)
Definition: path.c:862
struct CREATE_LINK_CONTEXT * PCREATE_LINK_CONTEXT
LPITEMIDLIST WINAPI SHBrowseForFolderW(LPBROWSEINFOW lpbi)
Definition: brsfolder.c:1156
HWND WINAPI GetParent(_In_ HWND)
UINT ulFlags
Definition: shlobj.h:1122
LPCWSTR szPath
Definition: env.c:35
STRSAFEAPI StringCchPrintfW(STRSAFE_LPWSTR pszDest, size_t cchDest, STRSAFE_LPCWSTR pszFormat,...)
Definition: strsafe.h:530
BFFCALLBACK lpfn
Definition: shlobj.h:1123
__int3264 LONG_PTR
Definition: mstsclib_h.h:276
#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
#define HIWORD(l)
Definition: typedefs.h:246
#define GetWindowLongPtr
Definition: treelist.c:73
WCHAR * LPWSTR
Definition: xmlstorage.h:184
#define IDS_NEW_INTERNET_SHORTCUT
Definition: resource.h:25
ITEMIDLIST UNALIGNED * LPITEMIDLIST
Definition: shtypes.idl:41
#define WM_INITDIALOG
Definition: winuser.h:1721
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:2004

Referenced by ShowCreateShortcutWizard().