ReactOS 0.4.15-dev-6662-g1b3eed5
createlink.c File Reference
#include "appwiz.h"
#include <commctrl.h>
#include <shellapi.h>
#include <strsafe.h>
#include <shlwapi_undoc.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 149 of file createlink.c.

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

Referenced by FinishDlgProc().

◆ CreateShortcut()

BOOL CreateShortcut ( PCREATE_LINK_CONTEXT  pContext)

Definition at line 76 of file createlink.c.

77{
78 IShellLinkW *pShellLink, *pSourceShellLink;
79 IPersistFile *pPersistFile;
80 HRESULT hr;
83
84 /* get the extension */
86
88 {
89 hr = CoCreateInstance(&CLSID_ShellLink, NULL, CLSCTX_ALL, &IID_IShellLinkW, (void**)&pSourceShellLink);
90
91 if (FAILED(hr))
92 return FALSE;
93
94 hr = IUnknown_QueryInterface(pSourceShellLink, &IID_IPersistFile, (void**)&pPersistFile);
95 if (FAILED(hr))
96 {
97 IUnknown_Release(pSourceShellLink);
98 return FALSE;
99 }
100
101 hr = pPersistFile->lpVtbl->Load(pPersistFile, (LPCOLESTR)pContext->szTarget, STGM_READ);
102 IUnknown_Release(pPersistFile);
103
104 if (FAILED(hr))
105 {
106 IUnknown_Release(pSourceShellLink);
107 return FALSE;
108 }
109
110 hr = IShellLinkW_GetPath(pSourceShellLink, Path, _countof(Path), NULL, 0);
111 IUnknown_Release(pSourceShellLink);
112
113 if (FAILED(hr))
114 {
115 return FALSE;
116 }
117 }
118 else
119 {
121 }
122
123 hr = CoCreateInstance(&CLSID_ShellLink, NULL, CLSCTX_ALL,
124 &IID_IShellLinkW, (void**)&pShellLink);
125
126 if (hr != S_OK)
127 return FALSE;
128
129 pShellLink->lpVtbl->SetPath(pShellLink, Path);
130 if (pContext->szArguments[0])
131 pShellLink->lpVtbl->SetArguments(pShellLink, pContext->szArguments);
132 pShellLink->lpVtbl->SetDescription(pShellLink, pContext->szDescription);
133 pShellLink->lpVtbl->SetWorkingDirectory(pShellLink, pContext->szWorkingDirectory);
134
135 hr = IUnknown_QueryInterface(pShellLink, &IID_IPersistFile, (void**)&pPersistFile);
136 if (hr != S_OK)
137 {
138 IUnknown_Release(pShellLink);
139 return FALSE;
140 }
141
142 hr = pPersistFile->lpVtbl->Save(pPersistFile, pContext->szLinkName, TRUE);
143 IUnknown_Release(pPersistFile);
144 IUnknown_Release(pShellLink);
145 return (hr == S_OK);
146}
PRTL_UNICODE_STRING_BUFFER Path
LPWSTR WINAPI PathFindExtensionW(LPCWSTR lpszPath)
Definition: path.c:447
HRESULT Load([in] LPCOLESTR pszFileName, [in] DWORD dwMode)
HRESULT SetArguments([in] LPCWSTR pszArgs)
HRESULT SetPath([in] LPCWSTR pszFile)
HRESULT SetDescription([in] LPCWSTR pszName)
HRESULT SetWorkingDirectory([in] LPCWSTR pszDir)
#define S_OK
Definition: intsafe.h:52
#define STGM_READ
Definition: objbase.h:917
STRSAFEAPI StringCchCopyW(STRSAFE_LPWSTR pszDest, size_t cchDest, STRSAFE_LPCWSTR pszSrc)
Definition: strsafe.h:149
_In_ LPCSTR _In_opt_ LPCSTR lpExtension
Definition: winbase.h:3062
WCHAR * LPWSTR
Definition: xmlstorage.h:184

Referenced by FinishDlgProc().

◆ DoConvertNameForFileSystem()

void DoConvertNameForFileSystem ( LPWSTR  szName)

Definition at line 186 of file createlink.c.

187{
188 LPWSTR pch1, pch2;
189 for (pch1 = pch2 = szName; *pch1; ++pch1)
190 {
191 if (wcschr(L"\\/:*?\"<>|", *pch1) != NULL)
192 {
193 /* *pch1 is an invalid character */
194 continue;
195 }
196 *pch2 = *pch1;
197 ++pch2;
198 }
199 *pch2 = 0;
200}
#define wcschr
Definition: compat.h:17
#define L(x)
Definition: ntvdm.h:50
static const WCHAR szName[]
Definition: powrprof.c:45

Referenced by FinishDlgProc().

◆ DoValidateShortcutName()

BOOL DoValidateShortcutName ( PCREATE_LINK_CONTEXT  pContext)

Definition at line 203 of file createlink.c.

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

Referenced by FinishDlgProc().

◆ FinishDlgProc()

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

Definition at line 387 of file createlink.c.

391{
392 LPPROPSHEETPAGEW ppsp;
393 PCREATE_LINK_CONTEXT pContext;
394 LPPSHNOTIFY lppsn;
395 WCHAR szText[MAX_PATH];
396 WCHAR szMessage[128];
397
398 switch(uMsg)
399 {
400 case WM_INITDIALOG:
401 ppsp = (LPPROPSHEETPAGEW)lParam;
402 pContext = (PCREATE_LINK_CONTEXT) ppsp->lParam;
403 SetWindowLongPtr(hwndDlg, DWLP_USER, (LONG_PTR)pContext);
405 break;
406 case WM_COMMAND:
407 switch(HIWORD(wParam))
408 {
409 case EN_CHANGE:
411 {
412 GetDlgItemTextW(hwndDlg, IDC_SHORTCUT_NAME, szText, _countof(szText));
413 StrTrimW(szText, L" \t");
414 if (szText[0])
416 else
418 }
419 else
420 {
422 }
423 break;
424 }
425 break;
426 case WM_NOTIFY:
427 lppsn = (LPPSHNOTIFY) lParam;
428 pContext = (PCREATE_LINK_CONTEXT) GetWindowLongPtr(hwndDlg, DWLP_USER);
429 if (lppsn->hdr.code == PSN_SETACTIVE)
430 {
431 /* TODO: Use shell32!PathCleanupSpec instead of DoConvertNameForFileSystem */
436 }
437 else if (lppsn->hdr.code == PSN_WIZFINISH)
438 {
440 StrTrimW(pContext->szDescription, L" \t");
441
442 if (!DoValidateShortcutName(pContext))
443 {
445
446 LoadStringW(hApplet, IDS_INVALID_NAME, szMessage, _countof(szMessage));
447 MessageBoxW(hwndDlg, szMessage, NULL, MB_ICONERROR);
448
449 /* prevent the wizard to go next */
450 SetWindowLongPtr(hwndDlg, DWLP_MSGRESULT, -1);
451 return TRUE;
452 }
453
454 /* if old shortcut file exists, then delete it now */
455 DeleteFileW(pContext->szOldFile);
457
458 if (IsInternetLocation(pContext->szTarget))
459 {
460 /* internet */
461 StringCchCopyW(pContext->szLinkName, _countof(pContext->szLinkName),
462 pContext->szOrigin);
463 PathAppendW(pContext->szLinkName, pContext->szDescription);
464
465 /* change extension if any */
467 StringCchCatW(pContext->szLinkName, _countof(pContext->szLinkName), L".url");
468
469 if (!CreateInternetShortcut(pContext))
470 {
471 LoadStringW(hApplet, IDS_CANTMAKEINETSHORTCUT, szMessage, _countof(szMessage));
472 MessageBoxW(hwndDlg, szMessage, NULL, MB_ICONERROR);
473 }
474 }
475 else
476 {
477 /* file */
478 StringCchCopyW(pContext->szLinkName, _countof(pContext->szLinkName),
479 pContext->szOrigin);
480 PathAppendW(pContext->szLinkName, pContext->szDescription);
481
482 /* change extension if any */
484 StringCchCatW(pContext->szLinkName, _countof(pContext->szLinkName), L".lnk");
485
486 if (!CreateShortcut(pContext))
487 {
488 WCHAR szMessage[128];
489 LoadStringW(hApplet, IDS_CANTMAKESHORTCUT, szMessage, _countof(szMessage));
490 MessageBoxW(hwndDlg, szMessage, NULL, MB_ICONERROR);
491 }
492 }
493 }
494 else if (lppsn->hdr.code == PSN_RESET && !lppsn->lParam)
495 {
496 /* The user has clicked [Cancel] */
497 DeleteFileW(pContext->szOldFile);
499 }
500 break;
501 }
502 return FALSE;
503}
struct CREATE_LINK_CONTEXT * PCREATE_LINK_CONTEXT
EXTERN_C void WINAPI SHChangeNotify(LONG wEventId, UINT uFlags, LPCVOID dwItem1, LPCVOID dwItem2)
WPARAM wParam
Definition: combotst.c:138
LPARAM lParam
Definition: combotst.c:139
HINSTANCE hApplet
Definition: access.c:17
#define IDC_SHORTCUT_NAME
Definition: resource.h:42
#define IDS_CANTMAKESHORTCUT
Definition: resource.h:27
#define IDS_CANTMAKEINETSHORTCUT
Definition: resource.h:26
#define IDS_INVALID_NAME
Definition: resource.h:31
BOOL WINAPI DeleteFileW(IN LPCWSTR lpFileName)
Definition: delete.c:39
void WINAPI PathRemoveExtensionW(LPWSTR lpszPath)
Definition: path.c:823
BOOL WINAPI PathAppendW(LPWSTR lpszPath, LPCWSTR lpszAppend)
Definition: path.c:126
BOOL WINAPI StrTrimW(LPWSTR lpszStr, LPCWSTR lpszTrim)
Definition: string.c:1869
__int3264 LONG_PTR
Definition: mstsclib_h.h:276
#define PSWIZB_FINISH
Definition: prsht.h:155
#define PSWIZB_BACK
Definition: prsht.h:153
#define PropSheet_SetWizButtons(d, f)
Definition: prsht.h:357
#define PSN_WIZFINISH
Definition: prsht.h:122
struct _PROPSHEETPAGEW * LPPROPSHEETPAGEW
#define PSN_RESET
Definition: prsht.h:118
struct _PSHNOTIFY * LPPSHNOTIFY
#define PSN_SETACTIVE
Definition: prsht.h:115
#define WM_NOTIFY
Definition: richedit.h:61
#define SHCNE_DELETE
Definition: shlobj.h:1748
#define SHCNF_PATHW
Definition: shlobj.h:1781
STRSAFEAPI StringCchCatW(STRSAFE_LPWSTR pszDest, size_t cchDest, STRSAFE_LPCWSTR pszSrc)
Definition: strsafe.h:325
LPARAM lParam
Definition: prsht.h:227
LPARAM lParam
Definition: prsht.h:331
NMHDR hdr
Definition: prsht.h:330
UINT code
Definition: winuser.h:3149
#define GetWindowLongPtr
Definition: treelist.c:73
#define SetWindowLongPtr
Definition: treelist.c:70
#define HIWORD(l)
Definition: typedefs.h:247
UINT WINAPI GetDlgItemTextW(HWND hDlg, int nIDDlgItem, LPWSTR lpString, int nMaxCount)
Definition: dialog.c:2263
#define WM_GETTEXTLENGTH
Definition: winuser.h:1609
#define DWLP_USER
Definition: winuser.h:866
int WINAPI LoadStringW(_In_opt_ HINSTANCE hInstance, _In_ UINT uID, _Out_writes_to_(cchBufferMax, return+1) LPWSTR lpBuffer, _In_ int cchBufferMax)
#define WM_COMMAND
Definition: winuser.h:1730
BOOL WINAPI SetDlgItemTextW(_In_ HWND, _In_ int, _In_ LPCWSTR)
#define WM_INITDIALOG
Definition: winuser.h:1729
int WINAPI MessageBoxW(_In_opt_ HWND hWnd, _In_opt_ LPCWSTR lpText, _In_opt_ LPCWSTR lpCaption, _In_ UINT uType)
HWND WINAPI GetDlgItem(_In_opt_ HWND, _In_ int)
LRESULT WINAPI SendDlgItemMessageW(_In_ HWND, _In_ int, _In_ UINT, _In_ WPARAM, _In_ LPARAM)
#define MB_ICONERROR
Definition: winuser.h:781
HWND WINAPI SetFocus(_In_opt_ HWND)
#define EM_SETSEL
Definition: winuser.h:2008
HWND WINAPI GetParent(_In_ HWND)
#define DWLP_MSGRESULT
Definition: winuser.h:864
#define SendDlgItemMessage
Definition: winuser.h:5832
#define EN_CHANGE
Definition: winuser.h:2012

Referenced by ShowCreateShortcutWizard().

◆ IsExtensionAShortcut()

BOOL IsExtensionAShortcut ( LPWSTR  lpExtension)

Definition at line 37 of file createlink.c.

38{
39 HKEY hKey;
40 WCHAR Buffer[100];
41 DWORD Size;
42 DWORD Type;
43
45 return FALSE;
46
47 if (IsShortcut(hKey))
48 {
50 return TRUE;
51 }
52
53 Size = sizeof(Buffer);
55 {
57 return FALSE;
58 }
59
61
63 return FALSE;
64
65 if (IsShortcut(hKey))
66 {
68 return TRUE;
69 }
70
72 return FALSE;
73}
Type
Definition: Type.h:7
#define RegCloseKey(hKey)
Definition: registry.h:47
Definition: bufpool.h:45
#define ERROR_SUCCESS
Definition: deptool.c:10
LONG WINAPI RegOpenKeyExW(HKEY hKey, LPCWSTR lpSubKey, DWORD ulOptions, REGSAM samDesired, PHKEY phkResult)
Definition: reg.c:3353
unsigned long DWORD
Definition: ntddk_ex.h:95
FxAutoRegKey hKey
#define REG_SZ
Definition: layer.c:22
#define KEY_READ
Definition: nt_native.h:1023
unsigned char * LPBYTE
Definition: typedefs.h:53
_Must_inspect_result_ _In_ WDFDEVICE _In_ PWDF_DEVICE_PROPERTY_DATA _In_ DEVPROPTYPE _In_ ULONG Size
Definition: wdfdevice.h:4533
#define RegQueryValueEx
Definition: winreg.h:524
#define HKEY_CLASSES_ROOT
Definition: winreg.h:10

Referenced by CreateShortcut().

◆ IsInternetLocation()

BOOL IsInternetLocation ( LPCWSTR  pszLocation)

Definition at line 179 of file createlink.c.

180{
181 return (PathIsURLW(pszLocation) || wcsstr(pszLocation, L"www.") == pszLocation);
182}
BOOL WINAPI PathIsURLW(LPCWSTR lpstrPath)
Definition: url.c:2432
_CONST_RETURN wchar_t *__cdecl wcsstr(_In_z_ const wchar_t *_Str, _In_z_ const wchar_t *_SubStr)

Referenced by FinishDlgProc(), and WelcomeDlgProc().

◆ IsShortcut()

BOOL IsShortcut ( HKEY  hKey)

Definition at line 20 of file createlink.c.

21{
22 WCHAR Value[10];
23 DWORD Size;
24 DWORD Type;
25
26 Size = sizeof(Value);
27 if (RegQueryValueExW(hKey, L"IsShortcut", NULL, &Type, (LPBYTE)Value, &Size) != ERROR_SUCCESS)
28 return FALSE;
29
30 if (Type != REG_SZ)
31 return FALSE;
32
33 return (wcsicmp(Value, L"yes") == 0);
34}
LONG WINAPI RegQueryValueExW(_In_ HKEY hkeyorg, _In_ LPCWSTR name, _In_ LPDWORD reserved, _In_ LPDWORD type, _In_ LPBYTE data, _In_ LPDWORD count)
Definition: reg.c:4118
#define wcsicmp
Definition: compat.h:15
_Must_inspect_result_ _In_ WDFKEY _In_ PCUNICODE_STRING _Out_opt_ PUSHORT _Inout_opt_ PUNICODE_STRING Value
Definition: wdfregistry.h:413

Referenced by IsExtensionAShortcut().

◆ NewLinkHereA()

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

Definition at line 635 of file createlink.c.

636{
637 WCHAR szFile[MAX_PATH];
638
639 if (MultiByteToWideChar(CP_ACP, 0, (LPSTR)lParam1, -1, szFile, _countof(szFile)))
640 {
642 return ShowCreateShortcutWizard(hwndCPl, szFile);
643 }
644 return -1;
645}
VOID WINAPI InitCommonControls(void)
Definition: commctrl.c:863
#define CP_ACP
Definition: compat.h:109
#define MultiByteToWideChar
Definition: compat.h:110
char * LPSTR
Definition: xmlstorage.h:182

◆ NewLinkHereW()

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

Definition at line 627 of file createlink.c.

628{
630 return ShowCreateShortcutWizard(hwndCPl, (LPWSTR)lParam1);
631}

◆ PropSheetProc()

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

Definition at line 506 of file createlink.c.

507{
508 // NOTE: This callback is needed to set large icon correctly.
509 HICON hIcon;
510 switch (uMsg)
511 {
512 case PSCB_INITIALIZED:
513 {
515 SendMessageW(hwndDlg, WM_SETICON, ICON_BIG, (LPARAM)hIcon);
516 break;
517 }
518 }
519 return 0;
520}
#define IDI_APPINETICO
Definition: resource.h:9
static HICON
Definition: imagelist.c:84
HICON hIcon
Definition: msconfig.c:44
#define PSCB_INITIALIZED
Definition: prsht.h:75
#define ICON_BIG
Definition: tnclass.cpp:51
LONG_PTR LPARAM
Definition: windef.h:208
#define MAKEINTRESOURCEW(i)
Definition: winuser.h:582
HICON WINAPI LoadIconW(_In_opt_ HINSTANCE hInstance, _In_ LPCWSTR lpIconName)
Definition: cursoricon.c:2044
LRESULT WINAPI SendMessageW(_In_ HWND, _In_ UINT, _In_ WPARAM, _In_ LPARAM)

Referenced by ShowCreateShortcutWizard().

◆ ShowCreateShortcutWizard()

LONG CALLBACK ShowCreateShortcutWizard ( HWND  hwndCPl,
LPCWSTR  szPath 
)

Definition at line 523 of file createlink.c.

524{
526 HPROPSHEETPAGE ahpsp[2];
527 PROPSHEETPAGE psp;
528 UINT nPages = 0;
530 PCREATE_LINK_CONTEXT pContext;
531 WCHAR szMessage[128];
532 LPWSTR pch;
533
534 pContext = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*pContext));
535 if (!pContext)
536 {
537 /* no memory */
538 LoadStringW(hApplet, IDS_NO_MEMORY, szMessage, _countof(szMessage));
539 MessageBoxW(hwndCPl, szMessage, NULL, MB_ICONERROR);
540 return FALSE;
541 }
542
544 if (!nLength)
545 {
546 HeapFree(GetProcessHeap(), 0, pContext);
547
548 /* no directory given */
549 LoadStringW(hApplet, IDS_NO_DIRECTORY, szMessage, _countof(szMessage));
550 MessageBoxW(hwndCPl, szMessage, NULL, MB_ICONERROR);
551 return FALSE;
552 }
553
555 {
556 HeapFree(GetProcessHeap(), 0, pContext);
557
558 /* invalid path */
559 LoadStringW(hApplet, IDS_INVALID_PATH, szMessage, _countof(szMessage));
560 MessageBoxW(hwndCPl, szMessage, NULL, MB_ICONERROR);
561 return FALSE;
562 }
563
564 /* build the pContext->szOrigin and pContext->szOldFile */
566 {
567 StringCchCopyW(pContext->szOrigin, _countof(pContext->szOrigin), szPath);
568 pContext->szOldFile[0] = 0;
569 }
570 else
571 {
572 StringCchCopyW(pContext->szOrigin, _countof(pContext->szOrigin), szPath);
573 pch = PathFindFileNameW(pContext->szOrigin);
574 if (pch && *pch)
575 *pch = 0;
576
577 StringCchCopyW(pContext->szOldFile, _countof(pContext->szOldFile), szPath);
578
580 if (pch && *pch)
581 {
582 /* build szDescription */
583 StringCchCopyW(pContext->szDescription, _countof(pContext->szDescription), pch);
584 *pch = 0;
585
587 *pch = 0;
588 }
589 }
590 PathAddBackslashW(pContext->szOrigin);
591
592 /* Create the Welcome page */
593 psp.dwSize = sizeof(PROPSHEETPAGE);
594 psp.dwFlags = PSP_DEFAULT | PSP_HIDEHEADER;
595 psp.hInstance = hApplet;
596 psp.pfnDlgProc = WelcomeDlgProc;
597 psp.pszTemplate = MAKEINTRESOURCEW(IDD_SHORTCUT_LOCATION);
598 psp.lParam = (LPARAM)pContext;
599 ahpsp[nPages++] = CreatePropertySheetPage(&psp);
600
601 /* Create the Finish page */
602 psp.dwFlags = PSP_DEFAULT | PSP_HIDEHEADER;
603 psp.pfnDlgProc = FinishDlgProc;
604 psp.pszTemplate = MAKEINTRESOURCEW(IDD_SHORTCUT_FINISH);
605 ahpsp[nPages++] = CreatePropertySheetPage(&psp);
606
607 /* Create the property sheet */
608 psh.dwSize = sizeof(PROPSHEETHEADER);
609 psh.dwFlags = PSH_WIZARD97 | PSH_WATERMARK | PSH_USEICONID | PSH_USECALLBACK;
610 psh.hInstance = hApplet;
612 psh.hwndParent = NULL;
613 psh.nPages = nPages;
614 psh.nStartPage = 0;
615 psh.phpage = ahpsp;
616 psh.pszbmWatermark = MAKEINTRESOURCEW(IDB_SHORTCUT);
618
619 /* Display the wizard */
620 PropertySheet(&psh);
621 HeapFree(GetProcessHeap(), 0, pContext);
622 return TRUE;
623}
#define IDS_INVALID_PATH
Definition: resource.h:30
#define IDS_NO_DIRECTORY
Definition: resource.h:29
#define IDB_SHORTCUT
Definition: resource.h:18
#define IDD_SHORTCUT_LOCATION
Definition: resource.h:12
#define IDD_SHORTCUT_FINISH
Definition: resource.h:13
#define IDS_NO_MEMORY
Definition: resource.h:28
#define GetProcessHeap()
Definition: compat.h:736
#define HeapAlloc
Definition: compat.h:733
#define HeapFree(x, y, z)
Definition: compat.h:735
#define HEAP_ZERO_MEMORY
Definition: compat.h:134
LPWSTR WINAPI PathAddBackslashW(LPWSTR lpszPath)
Definition: path.c:294
LPWSTR WINAPI PathFindFileNameW(LPCWSTR lpszPath)
Definition: path.c:394
BOOL WINAPI PathFileExistsW(LPCWSTR lpszPath)
Definition: path.c:1777
BOOL WINAPI PathIsDirectoryW(LPCWSTR lpszPath)
Definition: path.c:1723
struct _PSP * HPROPSHEETPAGE
Definition: mstask.idl:90
unsigned int UINT
Definition: ndis.h:50
#define PROPSHEETHEADER
Definition: prsht.h:392
#define CreatePropertySheetPage
Definition: prsht.h:399
#define PSH_USECALLBACK
Definition: prsht.h:48
#define PSP_DEFAULT
Definition: prsht.h:22
#define PropertySheet
Definition: prsht.h:400
#define PSH_USEICONID
Definition: prsht.h:42
#define PROPSHEETPAGE
Definition: prsht.h:389
HINSTANCE hInstance
Definition: prsht.h:296
DWORD dwSize
Definition: prsht.h:293
DWORD dwFlags
Definition: prsht.h:294
LPCWSTR pszIcon
Definition: prsht.h:299
HWND hwndParent
Definition: prsht.h:295
PFNPROPSHEETCALLBACK pfnCallback
Definition: prsht.h:311
HPROPSHEETPAGE * phpage
Definition: prsht.h:309
UINT nStartPage
Definition: prsht.h:304
_In_ DWORD nLength
Definition: wincon.h:473

Referenced by NewLinkHereA(), and NewLinkHereW().

◆ WelcomeDlgProc()

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

Definition at line 230 of file createlink.c.

234{
235 LPPROPSHEETPAGEW ppsp;
236 PCREATE_LINK_CONTEXT pContext;
237 LPPSHNOTIFY lppsn;
238 WCHAR szPath[MAX_PATH * 2];
239 WCHAR szDesc[100];
240 WCHAR szTitle[100];
241 BROWSEINFOW brws;
242 LPITEMIDLIST pidllist;
244
245 switch(uMsg)
246 {
247 case WM_INITDIALOG:
248 ppsp = (LPPROPSHEETPAGEW)lParam;
249 pContext = (PCREATE_LINK_CONTEXT) ppsp->lParam;
250 SetWindowLongPtr(hwndDlg, DWLP_USER, (LONG_PTR)pContext);
253 break;
254 case WM_COMMAND:
255 {
256 switch(HIWORD(wParam))
257 {
258 case EN_CHANGE:
260 {
262 }
263 else
264 {
266 }
267 break;
268 }
269 switch(LOWORD(wParam))
270 {
273 ZeroMemory(&brws, sizeof(brws));
274 brws.hwndOwner = hwndDlg;
275 brws.pidlRoot = NULL;
276 brws.pszDisplayName = szPath;
277 brws.lpszTitle = szTitle;
280 brws.lpfn = NULL;
281 pidllist = SHBrowseForFolderW(&brws);
282 if (!pidllist)
283 break;
284
285 if (SHGetPathFromIDListW(pidllist, szPath))
286 {
290 }
291 else
292 {
294 }
295
296 /* Free memory, if possible */
297 CoTaskMemFree(pidllist);
298 break;
299 }
300 break;
301 case WM_NOTIFY:
302 lppsn = (LPPSHNOTIFY) lParam;
303 pContext = (PCREATE_LINK_CONTEXT)GetWindowLongPtr(hwndDlg, DWLP_USER);
304 if (lppsn->hdr.code == PSN_SETACTIVE)
305 {
307 }
308 else if (lppsn->hdr.code == PSN_WIZNEXT)
309 {
310 GetDlgItemTextW(hwndDlg, IDC_SHORTCUT_LOCATION, pContext->szTarget, _countof(pContext->szTarget));
311 StrTrimW(pContext->szTarget, L" \t");
313
314 if (IsInternetLocation(szPath)) /* The internet location */
315 {
316 WCHAR szName[128];
319 pContext->szWorkingDirectory[0] = 0;
320 pContext->szArguments[0] = 0;
321 return FALSE;
322 }
323
324 /* Split and build args */
325 LPWSTR pszArgs = PathGetArgsW(szPath);
326 if (pszArgs && pszArgs > szPath)
327 {
329 StringCchCopyW(pContext->szArguments, _countof(pContext->szArguments), pszArgs);
330 }
331 else
332 {
333 pContext->szArguments[0] = 0;
334 }
335
336 /* Find the file */
337 WCHAR szFound[MAX_PATH];
338 StringCchCopyW(szFound, _countof(szFound), szPath);
339 if (!PathFindOnPathExW(szFound, NULL, WHICH_DEFAULT) &&
340 FindExecutableW(szPath, NULL, szFound) <= (HINSTANCE)(INT_PTR)32)
341 {
342 /* Not found */
344
347
348 WCHAR szError[MAX_PATH + 100];
349 StringCchPrintfW(szError, _countof(szError), szPath, pContext->szTarget);
350 MessageBoxW(hwndDlg, szError, szDesc, MB_ICONERROR);
351
352 /* Prevent the wizard to go next */
353 SetWindowLongPtr(hwndDlg, DWLP_MSGRESULT, -1);
354 return TRUE;
355 }
356
357 /* Rebuild target */
358 StringCchCopyW(pContext->szTarget, _countof(pContext->szTarget), szFound);
359
360 /* Get display name */
361 FileInfo.szDisplayName[0] = 0;
362 if (SHGetFileInfoW(szFound, 0, &FileInfo, sizeof(FileInfo), SHGFI_DISPLAYNAME))
363 StringCchCopyW(pContext->szDescription, _countof(pContext->szDescription), FileInfo.szDisplayName);
364
365 /* Set working directory */
366 StringCchCopyW(pContext->szWorkingDirectory, _countof(pContext->szWorkingDirectory), szFound);
370
372 }
373 else if (lppsn->hdr.code == PSN_RESET && !lppsn->lParam)
374 {
375 /* The user has clicked [Cancel] */
376 DeleteFileW(pContext->szOldFile);
378 }
379 break;
380 }
381 }
382 return FALSE;
383}
#define IDS_NEW_INTERNET_SHORTCUT
Definition: resource.h:25
#define IDS_CREATE_SHORTCUT
Definition: resource.h:23
#define IDS_ERROR_NOT_FOUND
Definition: resource.h:24
#define IDC_SHORTCUT_LOCATION
Definition: resource.h:40
#define IDC_SHORTCUT_BROWSE
Definition: resource.h:41
#define IDS_BROWSE_FOR_TARGET
Definition: resource.h:32
DWORD WINAPI ExpandEnvironmentStringsW(IN LPCWSTR lpSrc, IN LPWSTR lpDst, IN DWORD nSize)
Definition: environ.c:519
LPITEMIDLIST WINAPI SHBrowseForFolderW(LPBROWSEINFOW lpbi)
Definition: brsfolder.c:1406
void WINAPI PathRemoveArgsW(LPWSTR lpszPath)
Definition: path.c:779
BOOL WINAPI PathRemoveFileSpecW(LPWSTR lpszPath)
Definition: path.c:629
BOOL WINAPI PathFindOnPathExW(LPWSTR lpszFile, LPCWSTR *lppszOtherDirs, DWORD dwWhich)
Definition: path.c:1351
LPWSTR WINAPI PathRemoveBackslashW(LPWSTR lpszPath)
Definition: path.c:867
LPWSTR WINAPI PathGetArgsW(LPCWSTR lpszPath)
Definition: path.c:506
VOID WINAPI CoTaskMemFree(LPVOID ptr)
Definition: ifs.c:442
TCHAR szTitle[MAX_LOADSTRING]
Definition: magnifier.c:35
#define LOWORD(l)
Definition: pedump.c:82
BOOL WINAPI SHGetPathFromIDListW(LPCITEMIDLIST pidl, LPWSTR pszPath)
Definition: pidl.c:1298
#define PSNRET_INVALID_NOCHANGEPAGE
Definition: prsht.h:131
#define PSN_WIZNEXT
Definition: prsht.h:121
#define PSWIZB_NEXT
Definition: prsht.h:154
DWORD_PTR WINAPI SHGetFileInfoW(LPCWSTR path, DWORD dwFileAttributes, SHFILEINFOW *psfi, UINT sizeofpsfi, UINT flags)
Definition: shell32_main.c:415
#define SHGFI_DISPLAYNAME
Definition: shellapi.h:163
HINSTANCE WINAPI FindExecutableW(LPCWSTR lpFile, LPCWSTR lpDirectory, LPWSTR lpResult)
Definition: shlexec.cpp:1257
#define BIF_RETURNONLYFSDIRS
Definition: shlobj.h:1148
#define BIF_BROWSEINCLUDEFILES
Definition: shlobj.h:1163
#define BIF_NEWDIALOGSTYLE
Definition: shlobj.h:1154
#define BIF_SHAREABLE
Definition: shlobj.h:1164
HRESULT WINAPI SHAutoComplete(HWND hwndEdit, DWORD dwFlags)
Definition: autocomp.cpp:191
#define SHACF_DEFAULT
Definition: shlwapi.h:1911
#define WHICH_DEFAULT
ITEMIDLIST UNALIGNED * LPITEMIDLIST
Definition: shtypes.idl:41
STRSAFEAPI StringCchPrintfW(STRSAFE_LPWSTR pszDest, size_t cchDest, STRSAFE_LPCWSTR pszFormat,...)
Definition: strsafe.h:530
BFFCALLBACK lpfn
Definition: shlobj.h:1136
PCIDLIST_ABSOLUTE pidlRoot
Definition: shlobj.h:1132
UINT ulFlags
Definition: shlobj.h:1135
LPWSTR pszDisplayName
Definition: shlobj.h:1133
HWND hwndOwner
Definition: shlobj.h:1131
LPCWSTR lpszTitle
Definition: shlobj.h:1134
int32_t INT_PTR
Definition: typedefs.h:64
#define ZeroMemory
Definition: winbase.h:1700
#define WM_SETFOCUS
Definition: winuser.h:1603

Referenced by ShowCreateShortcutWizard().