1 /* $Id: appwiz.c 29364 2007-10-02 23:34:00Z janderwald $
3 * PROJECT: ReactOS Software Control Panel
4 * FILE: dll/cpl/appwiz/createlink.c
5 * PURPOSE: ReactOS Software Control Panel
6 * PROGRAMMER: Gero Kuehn (reactos.filter@gkware.com)
7 * Dmitry Chapyshev (lentind@yandex.ru)
17 CreateShortcut(PCREATE_LINK_CONTEXT pContext
)
19 IShellLinkW
*pShellLink
;
20 IPersistFile
*pPersistFile
;
23 hr
= CoCreateInstance(&CLSID_ShellLink
, NULL
, CLSCTX_ALL
,
24 &IID_IShellLink
, (void**)&pShellLink
);
30 pShellLink
->lpVtbl
->SetPath(pShellLink
, pContext
->szTarget
);
31 pShellLink
->lpVtbl
->SetDescription(pShellLink
, pContext
->szDescription
);
32 pShellLink
->lpVtbl
->SetWorkingDirectory(pShellLink
, pContext
->szWorkingDirectory
);
34 hr
= pShellLink
->lpVtbl
->QueryInterface(pShellLink
, &IID_IPersistFile
, (void**)&pPersistFile
);
37 pShellLink
->lpVtbl
->Release(pShellLink
);
41 hr
= pPersistFile
->lpVtbl
->Save(pPersistFile
, pContext
->szLinkName
, TRUE
);
42 pPersistFile
->lpVtbl
->Release(pPersistFile
);
43 pShellLink
->lpVtbl
->Release(pShellLink
);
52 WelcomeDlgProc(HWND hwndDlg
,
57 LPPROPSHEETPAGEW ppsp
;
58 PCREATE_LINK_CONTEXT pContext
;
60 WCHAR szPath
[MAX_PATH
];
63 LPITEMIDLIST pidllist
;
69 ppsp
= (LPPROPSHEETPAGEW
)lParam
;
70 pContext
= (PCREATE_LINK_CONTEXT
) ppsp
->lParam
;
71 SetWindowLongPtr(hwndDlg
, DWLP_USER
, (LONG_PTR
)pContext
);
72 PropSheet_SetWizButtons(GetParent(hwndDlg
), 0);
75 switch(HIWORD(wParam
))
78 if (SendDlgItemMessage(hwndDlg
, IDC_SHORTCUT_LOCATION
, WM_GETTEXTLENGTH
, 0, 0))
80 PropSheet_SetWizButtons(GetParent(hwndDlg
), PSWIZB_NEXT
);
84 PropSheet_SetWizButtons(GetParent(hwndDlg
), 0);
88 switch(LOWORD(wParam
))
90 case IDC_SHORTCUT_BROWSE
:
91 ZeroMemory(&brws
, sizeof(brws
));
92 brws
.hwndOwner
= hwndDlg
;
94 brws
.pszDisplayName
= szPath
;
95 brws
.ulFlags
= BIF_BROWSEINCLUDEFILES
;
97 pidllist
= SHBrowseForFolder(&brws
);
101 if (SHGetPathFromIDList(pidllist
, szPath
))
102 SendDlgItemMessage(hwndDlg
, IDC_SHORTCUT_LOCATION
, WM_SETTEXT
, 0, (LPARAM
)szPath
);
104 /* Free memory, if possible */
105 if (SUCCEEDED(SHGetMalloc(&malloc
)))
107 IMalloc_Free(malloc
, pidllist
);
108 IMalloc_Release(malloc
);
115 lppsn
= (LPPSHNOTIFY
) lParam
;
116 if (lppsn
->hdr
.code
== PSN_WIZNEXT
)
118 pContext
= (PCREATE_LINK_CONTEXT
) GetWindowLongPtr(hwndDlg
, DWLP_USER
);
119 SendDlgItemMessageW(hwndDlg
, IDC_SHORTCUT_LOCATION
, WM_GETTEXT
, MAX_PATH
, (LPARAM
)pContext
->szTarget
);
122 /// it should also be possible to create a link to folders, shellobjects etc....
124 if (GetFileAttributesW(pContext
->szTarget
) == INVALID_FILE_ATTRIBUTES
)
128 if (LoadStringW(hApplet
, IDS_CREATE_SHORTCUT
, szDesc
, 100) < 100 &&
129 LoadStringW(hApplet
, IDS_ERROR_NOT_FOUND
, szPath
, MAX_PATH
) < MAX_PATH
)
131 WCHAR szError
[MAX_PATH
+ 100];
133 _swprintf(szError
, szPath
, pContext
->szTarget
);
135 swprintf(szError
, szPath
, pContext
->szTarget
);
137 MessageBoxW(hwndDlg
, szError
, szDesc
, MB_ICONERROR
);
139 SendDlgItemMessage(hwndDlg
, IDC_SHORTCUT_LOCATION
, EM_SETSEL
, 0, -1);
140 SetFocus(GetDlgItem(hwndDlg
, IDC_SHORTCUT_LOCATION
));
141 SetWindowLong(hwndDlg
, DWL_MSGRESULT
, PSNRET_INVALID_NOCHANGEPAGE
);
146 WCHAR
* first
, *last
;
147 wcscpy(pContext
->szWorkingDirectory
, pContext
->szTarget
);
148 first
= wcschr(pContext
->szWorkingDirectory
, L
'\\');
149 last
= wcsrchr(pContext
->szWorkingDirectory
, L
'\\');
150 wcscpy(pContext
->szDescription
, &last
[1]);
157 first
= wcsrchr(pContext
->szDescription
, L
'.');
169 FinishDlgProc(HWND hwndDlg
,
174 LPPROPSHEETPAGEW ppsp
;
175 PCREATE_LINK_CONTEXT pContext
;
181 ppsp
= (LPPROPSHEETPAGEW
)lParam
;
182 pContext
= (PCREATE_LINK_CONTEXT
) ppsp
->lParam
;
183 SetWindowLongPtr(hwndDlg
, DWLP_USER
, (LONG_PTR
)pContext
);
184 SendDlgItemMessageW(hwndDlg
, IDC_SHORTCUT_NAME
, WM_SETTEXT
, 0, (LPARAM
)pContext
->szDescription
);
185 PropSheet_SetWizButtons(GetParent(hwndDlg
), PSWIZB_BACK
| PSWIZB_FINISH
);
188 switch(HIWORD(wParam
))
191 if (SendDlgItemMessage(hwndDlg
, IDC_SHORTCUT_NAME
, WM_GETTEXTLENGTH
, 0, 0))
193 PropSheet_SetWizButtons(GetParent(hwndDlg
), PSWIZB_BACK
| PSWIZB_FINISH
);
197 PropSheet_SetWizButtons(GetParent(hwndDlg
), PSWIZB_BACK
);
203 lppsn
= (LPPSHNOTIFY
) lParam
;
204 pContext
= (PCREATE_LINK_CONTEXT
) GetWindowLongPtr(hwndDlg
, DWLP_USER
);
205 if (lppsn
->hdr
.code
== PSN_WIZFINISH
)
207 SendDlgItemMessageW(hwndDlg
, IDC_SHORTCUT_NAME
, WM_GETTEXT
, MAX_PATH
, (LPARAM
)pContext
->szDescription
);
208 wcscat(pContext
->szLinkName
, pContext
->szDescription
);
209 wcscat(pContext
->szLinkName
, L
".lnk");
210 if (!CreateShortcut(pContext
))
212 MessageBox(hwndDlg
, _T("Failed to create shortcut"), _T("Error"), MB_ICONERROR
);
222 ShowCreateShortcutWizard(HWND hwndCPl
, LPWSTR szPath
)
224 PROPSHEETHEADERW psh
;
225 HPROPSHEETPAGE ahpsp
[2];
230 PCREATE_LINK_CONTEXT pContext
= (PCREATE_LINK_CONTEXT
) HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(CREATE_LINK_CONTEXT
));
236 nLength
= wcslen(szPath
);
239 /* no directory given */
244 /// check if path is valid
247 wcscpy(pContext
->szLinkName
, szPath
);
248 if (pContext
->szLinkName
[nLength
-1] != L
'\\')
250 pContext
->szLinkName
[nLength
] = L
'\\';
251 pContext
->szLinkName
[nLength
+1] = L
'\0';
255 /* Create the Welcome page */
256 psp
.dwSize
= sizeof(PROPSHEETPAGE
);
257 psp
.dwFlags
= PSP_DEFAULT
| PSP_HIDEHEADER
;
258 psp
.hInstance
= hApplet
;
259 psp
.pfnDlgProc
= WelcomeDlgProc
;
260 psp
.pszTemplate
= MAKEINTRESOURCE(IDD_SHORTCUT_LOCATION
);
261 psp
.lParam
= (LPARAM
)pContext
;
262 ahpsp
[nPages
++] = CreatePropertySheetPage(&psp
);
264 /* Create the Finish page */
265 psp
.dwFlags
= PSP_DEFAULT
| PSP_HIDEHEADER
;
266 psp
.pfnDlgProc
= FinishDlgProc
;
267 psp
.pszTemplate
= MAKEINTRESOURCE(IDD_SHORTCUT_FINISH
);
268 ahpsp
[nPages
++] = CreatePropertySheetPage(&psp
);
271 /* Create the property sheet */
272 psh
.dwSize
= sizeof(PROPSHEETHEADER
);
273 psh
.dwFlags
= PSH_WIZARD97
| PSH_WATERMARK
;
274 psh
.hInstance
= hApplet
;
275 psh
.hwndParent
= NULL
;
279 psh
.pszbmWatermark
= MAKEINTRESOURCE(IDB_WATERMARK
);
281 /* Display the wizard */
283 HeapFree(GetProcessHeap(), 0, pContext
);
290 NewLinkHere(HWND hwndCPl
, UINT uMsg
, LPARAM lParam1
, LPARAM lParam2
)
292 WCHAR szFile
[MAX_PATH
];
294 if (MultiByteToWideChar(CP_ACP
, 0, (char*)lParam1
, strlen((char*)lParam1
)+1, szFile
, MAX_PATH
))
296 return ShowCreateShortcutWizard(hwndCPl
, szFile
);
304 NewLinkHereW(HWND hwndCPl
, UINT uMsg
, LPARAM lParam1
, LPARAM lParam2
)
306 return ShowCreateShortcutWizard(hwndCPl
, (LPWSTR
)lParam1
);
311 NewLinkHereA(HWND hwndCPl
, UINT uMsg
, LPARAM lParam1
, LPARAM lParam2
)
313 WCHAR szFile
[MAX_PATH
];
315 if (MultiByteToWideChar(CP_ACP
, 0, (char*)lParam1
, strlen((char*)lParam1
)+1, szFile
, MAX_PATH
))
317 return ShowCreateShortcutWizard(hwndCPl
, szFile
);