ReactOS 0.4.15-dev-7934-g1dc8d80
createlink.c File Reference
#include "appwiz.h"
#include <commctrl.h>
#include <shellapi.h>
#include <strsafe.h>
#include <shlwapi_undoc.h>
#include "../../win32/shell32/shresdef.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 121 of file createlink.c.

122{
123 IUniformResourceLocatorW *pURL = NULL;
124 IPersistFile *pPersistFile = NULL;
125 HRESULT hr;
128
129 hr = CoCreateInstance(&CLSID_InternetShortcut, NULL, CLSCTX_ALL,
130 &IID_IUniformResourceLocatorW, (void **)&pURL);
131 if (FAILED(hr))
132 return FALSE;
133
134 hr = IUnknown_QueryInterface(pURL, &IID_IPersistFile, (void **)&pPersistFile);
135 if (FAILED(hr))
136 {
137 IUnknown_Release(pURL);
138 return FALSE;
139 }
140
141 pURL->lpVtbl->SetURL(pURL, pContext->szTarget, 0);
142
143 hr = pPersistFile->lpVtbl->Save(pPersistFile, szPath, TRUE);
144
145 IUnknown_Release(pPersistFile);
146 IUnknown_Release(pURL);
147
148 return SUCCEEDED(hr);
149}
#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 77 of file createlink.c.

78{
79 IShellLinkW *pShellLink;
80 IPersistFile *pPersistFile;
81 HRESULT hr;
82
83 hr = CoCreateInstance(&CLSID_ShellLink, NULL, CLSCTX_ALL, &IID_IShellLinkW, (void**)&pShellLink);
84 if (FAILED(hr))
85 return FALSE;
86
87 hr = IUnknown_QueryInterface(pShellLink, &IID_IPersistFile, (void**)&pPersistFile);
88 if (FAILED(hr))
89 {
90 IUnknown_Release(pShellLink);
91 return FALSE;
92 }
93
95 {
96 hr = pPersistFile->lpVtbl->Load(pPersistFile, (LPCOLESTR)pContext->szTarget, STGM_READ);
97 }
98 else
99 {
100 if (pContext->pidlTarget)
101 pShellLink->lpVtbl->SetIDList(pShellLink, pContext->pidlTarget);
102 else
103 pShellLink->lpVtbl->SetPath(pShellLink, pContext->szTarget);
104
105 if (pContext->szArguments[0])
106 pShellLink->lpVtbl->SetArguments(pShellLink, pContext->szArguments);
107
108 if (pContext->szDescription[0])
109 pShellLink->lpVtbl->SetDescription(pShellLink, pContext->szDescription);
110 }
111
112 if (SUCCEEDED(hr))
113 hr = pPersistFile->lpVtbl->Save(pPersistFile, pContext->szLinkName, TRUE);
114
115 IUnknown_Release(pPersistFile);
116 IUnknown_Release(pShellLink);
117 return SUCCEEDED(hr);
118}
LPWSTR WINAPI PathFindExtensionW(LPCWSTR lpszPath)
Definition: path.c:447
HRESULT Load([in] LPCOLESTR pszFileName, [in] DWORD dwMode)
HRESULT SetArguments([in] LPCWSTR pszArgs)
HRESULT SetIDList([in] PCIDLIST_ABSOLUTE pidl)
HRESULT SetPath([in] LPCWSTR pszFile)
HRESULT SetDescription([in] LPCWSTR pszName)
#define STGM_READ
Definition: objbase.h:917

Referenced by FinishDlgProc().

◆ DoConvertNameForFileSystem()

void DoConvertNameForFileSystem ( LPWSTR  szName)

Definition at line 158 of file createlink.c.

159{
160 LPWSTR pch1, pch2;
161 for (pch1 = pch2 = szName; *pch1; ++pch1)
162 {
163 if (wcschr(L"\\/:*?\"<>|", *pch1) != NULL)
164 {
165 /* *pch1 is an invalid character */
166 continue;
167 }
168 *pch2 = *pch1;
169 ++pch2;
170 }
171 *pch2 = 0;
172}
#define wcschr
Definition: compat.h:17
#define L(x)
Definition: ntvdm.h:50
static const WCHAR szName[]
Definition: powrprof.c:45
WCHAR * LPWSTR
Definition: xmlstorage.h:184

Referenced by FinishDlgProc().

◆ DoValidateShortcutName()

BOOL DoValidateShortcutName ( PCREATE_LINK_CONTEXT  pContext)

Definition at line 175 of file createlink.c.

176{
177 SIZE_T cch;
178 LPCWSTR pch, pszName = pContext->szDescription;
179
180 if (!pszName || !pszName[0])
181 return FALSE;
182
183 cch = wcslen(pContext->szOrigin) + wcslen(pszName) + 1;
184 if (cch >= MAX_PATH)
185 return FALSE;
186
187 pch = pszName;
188 for (pch = pszName; *pch; ++pch)
189 {
190 if (wcschr(L"\\/:*?\"<>|", *pch) != NULL)
191 {
192 /* *pch is an invalid character */
193 return FALSE;
194 }
195 }
196
197 return TRUE;
198}
_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 369 of file createlink.c.

373{
374 LPPROPSHEETPAGEW ppsp;
375 PCREATE_LINK_CONTEXT pContext;
376 LPPSHNOTIFY lppsn;
377 WCHAR szText[MAX_PATH], szPath[MAX_PATH];
378 WCHAR szMessage[128];
379
380 switch(uMsg)
381 {
382 case WM_INITDIALOG:
383 ppsp = (LPPROPSHEETPAGEW)lParam;
384 pContext = (PCREATE_LINK_CONTEXT) ppsp->lParam;
385 SetWindowLongPtr(hwndDlg, DWLP_USER, (LONG_PTR)pContext);
387 break;
388 case WM_COMMAND:
389 switch(HIWORD(wParam))
390 {
391 case EN_CHANGE:
393 {
394 GetDlgItemTextW(hwndDlg, IDC_SHORTCUT_NAME, szText, _countof(szText));
395 StrTrimW(szText, L" \t");
396 if (szText[0])
398 else
400 }
401 else
402 {
404 }
405 break;
406 }
407 break;
408 case WM_NOTIFY:
409 lppsn = (LPPSHNOTIFY) lParam;
410 pContext = (PCREATE_LINK_CONTEXT) GetWindowLongPtr(hwndDlg, DWLP_USER);
411 if (lppsn->hdr.code == PSN_SETACTIVE)
412 {
413 /* Remove invalid characters */
416
417 /* Is it empty? (rare case) */
418 if (!pContext->szDescription[0])
419 {
420 HMODULE hShell32 = GetModuleHandleW(L"shell32.dll");
422 LoadStringW(hShell32, IDS_LNK_FILE, szMessage, _countof(szMessage));
424 szText, szMessage);
425 }
426
427 /* Build a path from szOldFile */
428 StringCchCopyW(szText, _countof(szText), pContext->szOldFile);
429 PathRemoveFileSpecW(szText);
430
431 /* Rename duplicate if necessary */
433 (IsInternetLocation(pContext->szTarget) ? L".url" : L".lnk"));
438
442 }
443 else if (lppsn->hdr.code == PSN_WIZFINISH)
444 {
446 StrTrimW(pContext->szDescription, L" \t");
447
448 if (!DoValidateShortcutName(pContext))
449 {
451
452 LoadStringW(hApplet, IDS_INVALID_NAME, szMessage, _countof(szMessage));
453 MessageBoxW(hwndDlg, szMessage, NULL, MB_ICONERROR);
454
455 /* prevent the wizard to go next */
456 SetWindowLongPtr(hwndDlg, DWLP_MSGRESULT, -1);
457 return TRUE;
458 }
459
460 /* if old shortcut file exists, then delete it now */
461 DeleteFileW(pContext->szOldFile);
463
464 if (IsInternetLocation(pContext->szTarget))
465 {
466 /* internet */
467 StringCchCopyW(pContext->szLinkName, _countof(pContext->szLinkName),
468 pContext->szOrigin);
469 PathAppendW(pContext->szLinkName, pContext->szDescription);
470
471 /* change extension if any */
473 PathAddExtensionW(pContext->szLinkName, L".url");
474
475 if (!CreateInternetShortcut(pContext))
476 {
477 LoadStringW(hApplet, IDS_CANTMAKEINETSHORTCUT, szMessage, _countof(szMessage));
478 MessageBoxW(hwndDlg, szMessage, NULL, MB_ICONERROR);
479 }
480 }
481 else
482 {
483 /* file */
484 StringCchCopyW(pContext->szLinkName, _countof(pContext->szLinkName),
485 pContext->szOrigin);
486 PathAppendW(pContext->szLinkName, pContext->szDescription);
487
488 /* change extension if any */
490 PathAddExtensionW(pContext->szLinkName, L".lnk");
491
492 if (!CreateShortcut(pContext))
493 {
494 WCHAR szMessage[128];
495 LoadStringW(hApplet, IDS_CANTMAKESHORTCUT, szMessage, _countof(szMessage));
496 MessageBoxW(hwndDlg, szMessage, NULL, MB_ICONERROR);
497 }
498 }
499 }
500 else if (lppsn->hdr.code == PSN_RESET && !lppsn->lParam)
501 {
502 /* The user has clicked [Cancel] */
503 DeleteFileW(pContext->szOldFile);
505 }
506 break;
507 }
508 return FALSE;
509}
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
HMODULE WINAPI GetModuleHandleW(LPCWSTR lpModuleName)
Definition: loader.c:838
int WINAPI PathCleanupSpec(LPCWSTR lpszPathW, LPWSTR lpszFileW)
Definition: shellpath.c:736
BOOL WINAPI PathYetAnotherMakeUniqueName(LPWSTR buffer, LPCWSTR path, LPCWSTR shortname, LPCWSTR longname)
Definition: shellpath.c:699
BOOL WINAPI PathRemoveFileSpecW(LPWSTR lpszPath)
Definition: path.c:629
LPWSTR WINAPI PathFindFileNameW(LPCWSTR lpszPath)
Definition: path.c:394
void WINAPI PathRemoveExtensionW(LPWSTR lpszPath)
Definition: path.c:823
BOOL WINAPI StrTrimW(LPWSTR lpszStr, LPCWSTR lpszTrim)
Definition: string.c:1877
static HMODULE hShell32
Definition: string.c:34
__int3264 LONG_PTR
Definition: mstsclib_h.h:276
#define PathAddExtensionW
Definition: pathcch.h:305
#define PathAppendW
Definition: pathcch.h:309
#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:1877
#define SHCNF_PATHW
Definition: shlobj.h:1910
#define IDS_NEWITEMFORMAT
Definition: shresdef.h:143
#define IDS_LNK_FILE
Definition: shresdef.h:177
STRSAFEAPI StringCchPrintfW(STRSAFE_LPWSTR pszDest, size_t cchDest, STRSAFE_LPCWSTR pszFormat,...)
Definition: strsafe.h:530
STRSAFEAPI StringCchCopyW(STRSAFE_LPWSTR pszDest, size_t cchDest, STRSAFE_LPCWSTR pszSrc)
Definition: strsafe.h:149
LPARAM lParam
Definition: prsht.h:227
LPARAM lParam
Definition: prsht.h:331
NMHDR hdr
Definition: prsht.h:330
UINT code
Definition: winuser.h:3159
#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:1619
#define DWLP_USER
Definition: winuser.h:872
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:1740
BOOL WINAPI SetDlgItemTextW(_In_ HWND, _In_ int, _In_ LPCWSTR)
#define WM_INITDIALOG
Definition: winuser.h:1739
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:787
HWND WINAPI SetFocus(_In_opt_ HWND)
#define EM_SETSEL
Definition: winuser.h:2018
HWND WINAPI GetParent(_In_ HWND)
#define DWLP_MSGRESULT
Definition: winuser.h:870
#define SendDlgItemMessage
Definition: winuser.h:5842
#define EN_CHANGE
Definition: winuser.h:2022

Referenced by ShowCreateShortcutWizard().

◆ IsExtensionAShortcut()

BOOL IsExtensionAShortcut ( LPWSTR  lpExtension)

Definition at line 38 of file createlink.c.

39{
40 HKEY hKey;
41 WCHAR Buffer[100];
42 DWORD Size;
43 DWORD Type;
44
46 return FALSE;
47
48 if (IsShortcut(hKey))
49 {
51 return TRUE;
52 }
53
54 Size = sizeof(Buffer);
56 {
58 return FALSE;
59 }
60
62
64 return FALSE;
65
66 if (IsShortcut(hKey))
67 {
69 return TRUE;
70 }
71
73 return FALSE;
74}
Type
Definition: Type.h:7
#define RegCloseKey(hKey)
Definition: registry.h:49
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:3333
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
_In_ LPCSTR _In_opt_ LPCSTR lpExtension
Definition: winbase.h:3072
#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 151 of file createlink.c.

152{
153 return (PathIsURLW(pszLocation) || wcsstr(pszLocation, L"www.") == pszLocation);
154}
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 21 of file createlink.c.

22{
23 WCHAR Value[10];
24 DWORD Size;
25 DWORD Type;
26
27 Size = sizeof(Value);
28 if (RegQueryValueExW(hKey, L"IsShortcut", NULL, &Type, (LPBYTE)Value, &Size) != ERROR_SUCCESS)
29 return FALSE;
30
31 if (Type != REG_SZ)
32 return FALSE;
33
34 return (wcsicmp(Value, L"yes") == 0);
35}
LONG WINAPI RegQueryValueExW(_In_ HKEY hkeyorg, _In_ LPCWSTR name, _In_ LPDWORD reserved, _In_ LPDWORD type, _In_ LPBYTE data, _In_ LPDWORD count)
Definition: reg.c:4103
#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 643 of file createlink.c.

644{
645 WCHAR szFile[MAX_PATH];
646
647 if (MultiByteToWideChar(CP_ACP, 0, (LPSTR)lParam1, -1, szFile, _countof(szFile)))
648 {
650 return ShowCreateShortcutWizard(hwndCPl, szFile);
651 }
652 return -1;
653}
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 635 of file createlink.c.

636{
638 return ShowCreateShortcutWizard(hwndCPl, (LPWSTR)lParam1);
639}

◆ PropSheetProc()

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

Definition at line 512 of file createlink.c.

513{
514 // NOTE: This callback is needed to set large icon correctly.
515 HICON hIcon;
516 switch (uMsg)
517 {
518 case PSCB_INITIALIZED:
519 {
521 SendMessageW(hwndDlg, WM_SETICON, ICON_BIG, (LPARAM)hIcon);
522 break;
523 }
524 }
525 return 0;
526}
#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:2075
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 529 of file createlink.c.

530{
532 HPROPSHEETPAGE ahpsp[2];
533 PROPSHEETPAGE psp;
534 UINT nPages = 0;
536 PCREATE_LINK_CONTEXT pContext;
537 WCHAR szMessage[128];
538 LPWSTR pch;
539
540 pContext = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*pContext));
541 if (!pContext)
542 {
543 /* no memory */
544 LoadStringW(hApplet, IDS_NO_MEMORY, szMessage, _countof(szMessage));
545 MessageBoxW(hwndCPl, szMessage, NULL, MB_ICONERROR);
546 return FALSE;
547 }
548
550 if (!nLength)
551 {
552 HeapFree(GetProcessHeap(), 0, pContext);
553
554 /* no directory given */
555 LoadStringW(hApplet, IDS_NO_DIRECTORY, szMessage, _countof(szMessage));
556 MessageBoxW(hwndCPl, szMessage, NULL, MB_ICONERROR);
557 return FALSE;
558 }
559
561 {
562 HeapFree(GetProcessHeap(), 0, pContext);
563
564 /* invalid path */
565 LoadStringW(hApplet, IDS_INVALID_PATH, szMessage, _countof(szMessage));
566 MessageBoxW(hwndCPl, szMessage, NULL, MB_ICONERROR);
567 return FALSE;
568 }
569
570 /* build the pContext->szOrigin and pContext->szOldFile */
572 {
573 StringCchCopyW(pContext->szOrigin, _countof(pContext->szOrigin), szPath);
574 pContext->szOldFile[0] = 0;
575 }
576 else
577 {
578 StringCchCopyW(pContext->szOrigin, _countof(pContext->szOrigin), szPath);
579 pch = PathFindFileNameW(pContext->szOrigin);
580 if (pch && *pch)
581 *pch = 0;
582
583 StringCchCopyW(pContext->szOldFile, _countof(pContext->szOldFile), szPath);
584
586 if (pch && *pch)
587 {
588 /* build szDescription */
589 StringCchCopyW(pContext->szDescription, _countof(pContext->szDescription), pch);
590 *pch = 0;
591
593 *pch = 0;
594 }
595 }
596 PathAddBackslashW(pContext->szOrigin);
597
598 /* Create the Welcome page */
599 psp.dwSize = sizeof(PROPSHEETPAGE);
600 psp.dwFlags = PSP_DEFAULT | PSP_HIDEHEADER;
601 psp.hInstance = hApplet;
602 psp.pfnDlgProc = WelcomeDlgProc;
603 psp.pszTemplate = MAKEINTRESOURCEW(IDD_SHORTCUT_LOCATION);
604 psp.lParam = (LPARAM)pContext;
605 ahpsp[nPages++] = CreatePropertySheetPage(&psp);
606
607 /* Create the Finish page */
608 psp.dwFlags = PSP_DEFAULT | PSP_HIDEHEADER;
609 psp.pfnDlgProc = FinishDlgProc;
610 psp.pszTemplate = MAKEINTRESOURCEW(IDD_SHORTCUT_FINISH);
611 ahpsp[nPages++] = CreatePropertySheetPage(&psp);
612
613 /* Create the property sheet */
614 psh.dwSize = sizeof(PROPSHEETHEADER);
615 psh.dwFlags = PSH_WIZARD97 | PSH_WATERMARK | PSH_USEICONID | PSH_USECALLBACK;
616 psh.hInstance = hApplet;
618 psh.hwndParent = NULL;
619 psh.nPages = nPages;
620 psh.nStartPage = 0;
621 psh.phpage = ahpsp;
622 psh.pszbmWatermark = MAKEINTRESOURCEW(IDB_SHORTCUT);
624
625 /* Display the wizard */
626 PropertySheet(&psh);
627
628 CoTaskMemFree(pContext->pidlTarget);
629 HeapFree(GetProcessHeap(), 0, pContext);
630 return TRUE;
631}
#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
BOOL WINAPI PathFileExistsW(LPCWSTR lpszPath)
Definition: path.c:1777
BOOL WINAPI PathIsDirectoryW(LPCWSTR lpszPath)
Definition: path.c:1723
VOID WINAPI CoTaskMemFree(LPVOID ptr)
Definition: ifs.c:442
struct _PSP * HPROPSHEETPAGE
Definition: mstask.idl:90
unsigned int UINT
Definition: ndis.h:50
#define PathAddBackslashW
Definition: pathcch.h:301
#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 202 of file createlink.c.

206{
207 LPPROPSHEETPAGEW ppsp;
209 LPPSHNOTIFY lppsn;
210 WCHAR szPath[MAX_PATH * 2], szDisplayName[MAX_PATH];
211 WCHAR szDesc[100];
212 WCHAR szTitle[100];
213 BROWSEINFOW brws;
214 LPITEMIDLIST pidllist;
216
217 switch(uMsg)
218 {
219 case WM_INITDIALOG:
220 ppsp = (LPPROPSHEETPAGEW)lParam;
221 pContext = (PCREATE_LINK_CONTEXT) ppsp->lParam;
222 SetWindowLongPtr(hwndDlg, DWLP_USER, (LONG_PTR)pContext);
225 break;
226 case WM_COMMAND:
227 {
228 switch (LOWORD(wParam))
229 {
231 {
232 if (HIWORD(wParam) == EN_CHANGE)
233 {
234 /* The text was changed by user. Invalidate pidlTarget. */
235 if (pContext->pidlTarget)
236 {
237 CoTaskMemFree(pContext->pidlTarget);
238 pContext->pidlTarget = NULL;
239 }
240
243 else
245 }
246 break;
247 }
249 {
251 ZeroMemory(&brws, sizeof(brws));
252 brws.hwndOwner = hwndDlg;
253 brws.pidlRoot = NULL;
254 brws.pszDisplayName = szDisplayName;
255 brws.lpszTitle = szTitle;
257 brws.lpfn = NULL;
258 pidllist = SHBrowseForFolderW(&brws);
259 if (!pidllist)
260 break;
261
263 szDisplayName);
264
265 SHGetPathFromIDListW(pidllist, szPath);
266
269 else
270 SetDlgItemTextW(hwndDlg, IDC_LINK_LOCATION, szDisplayName);
271
273
274 if (pContext->pidlTarget)
275 CoTaskMemFree(pContext->pidlTarget);
276 pContext->pidlTarget = pidllist;
277 break;
278 }
279 }
280 break;
281 case WM_NOTIFY:
282 lppsn = (LPPSHNOTIFY) lParam;
283 if (lppsn->hdr.code == PSN_SETACTIVE)
284 {
285 SetDlgItemTextW(hwndDlg, IDC_LINK_LOCATION, pContext->szTarget);
286 }
287 else if (lppsn->hdr.code == PSN_WIZNEXT)
288 {
289 GetDlgItemTextW(hwndDlg, IDC_LINK_LOCATION, pContext->szTarget, _countof(pContext->szTarget));
290 StrTrimW(pContext->szTarget, L" \t");
292
293 if (IsInternetLocation(szPath)) /* The internet location */
294 {
295 WCHAR szName[128];
298 pContext->szArguments[0] = 0;
299 return FALSE;
300 }
301
302 if (pContext->pidlTarget) /* The result of SHBrowseForFolderW */
303 {
304 SHGetPathFromIDListW(pContext->pidlTarget, pContext->szTarget);
305 pContext->szArguments[0] = 0;
306 return FALSE;
307 }
308
309 /* Otherwise, the target is a command line or pathname */
310
311 /* Split and build args */
312 LPWSTR pszArgs = PathGetArgsW(szPath);
313 if (pszArgs && pszArgs > szPath)
314 {
316 StringCchCopyW(pContext->szArguments, _countof(pContext->szArguments), pszArgs);
317 }
318 else
319 {
320 pContext->szArguments[0] = 0;
321 }
322
323 /* Find the file */
326 {
327 /* Not found */
329
332
333 WCHAR szError[MAX_PATH + 100];
334 StringCchPrintfW(szError, _countof(szError), szPath, pContext->szTarget);
335 MessageBoxW(hwndDlg, szError, szDesc, MB_ICONERROR);
336
337 /* Prevent the wizard to go next */
338 SetWindowLongPtr(hwndDlg, DWLP_MSGRESULT, -1);
339 return TRUE;
340 }
341
342 /* Rebuild target */
344 GetFullPathNameW(szPath, _countof(pContext->szTarget), pContext->szTarget, NULL);
345 else
346 StringCchCopyW(pContext->szTarget, _countof(pContext->szTarget), szPath);
347
348 /* Get display name */
349 FileInfo.szDisplayName[0] = UNICODE_NULL;
350 if (SHGetFileInfoW(pContext->szTarget, 0, &FileInfo, sizeof(FileInfo), SHGFI_DISPLAYNAME))
351 StringCchCopyW(pContext->szDescription, _countof(pContext->szDescription), FileInfo.szDisplayName);
352
353 break;
354 }
355 else if (lppsn->hdr.code == PSN_RESET && !lppsn->lParam)
356 {
357 /* The user has clicked [Cancel] */
358 DeleteFileW(pContext->szOldFile);
360 }
361 break;
362 }
363 }
364 return FALSE;
365}
#define IDS_NEW_INTERNET_SHORTCUT
Definition: resource.h:25
#define IDS_CREATE_SHORTCUT
Definition: resource.h:23
#define IDC_LINK_LOCATION
Definition: resource.h:40
#define IDS_ERROR_NOT_FOUND
Definition: resource.h:24
#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:1419
void WINAPI PathRemoveArgsW(LPWSTR lpszPath)
Definition: path.c:779
BOOL WINAPI PathFindOnPathExW(LPWSTR lpszFile, LPCWSTR *lppszOtherDirs, DWORD dwWhich)
Definition: path.c:1351
LPWSTR WINAPI PathGetArgsW(LPCWSTR lpszPath)
Definition: path.c:506
BOOL WINAPI PathIsRelativeW(LPCWSTR lpszPath)
Definition: path.c:1579
TCHAR szTitle[MAX_LOADSTRING]
Definition: magnifier.c:35
#define UNICODE_NULL
#define LOWORD(l)
Definition: pedump.c:82
BOOL WINAPI SHGetPathFromIDListW(LPCITEMIDLIST pidl, LPWSTR pszPath)
Definition: pidl.c:1353
#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:166
#define BIF_BROWSEINCLUDEFILES
Definition: shlobj.h:1225
#define BIF_NEWDIALOGSTYLE
Definition: shlobj.h:1216
#define BIF_SHAREABLE
Definition: shlobj.h:1226
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
BFFCALLBACK lpfn
Definition: shlobj.h:1198
PCIDLIST_ABSOLUTE pidlRoot
Definition: shlobj.h:1194
UINT ulFlags
Definition: shlobj.h:1197
LPWSTR pszDisplayName
Definition: shlobj.h:1195
HWND hwndOwner
Definition: shlobj.h:1193
LPCWSTR lpszTitle
Definition: shlobj.h:1196
#define ZeroMemory
Definition: winbase.h:1712

Referenced by ShowCreateShortcutWizard().