1 /*
2  * ReactOS Explorer
3  *
4  * Copyright 2006 - 2007 Thomas Weidenmueller <w3seek@reactos.org>
5  *                  2015 Robert Naumann <gonzomdx@gmail.com>
6  *
7  * This library is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU Lesser General Public
9  * License as published by the Free Software Foundation; either
10  * version 2.1 of the License, or (at your option) any later version.
11  *
12  * This library is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15  * Lesser General Public License for more details.
16  *
17  * You should have received a copy of the GNU Lesser General Public
18  * License along with this library; if not, write to the Free Software
19  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
20  */
21 
22 #include "precomp.h"
23 
24 // TODO: Windows Explorer appears to be calling NewLinkHere / ConfigStartMenu directly for both items.
25 VOID OnAddStartMenuItems(HWND hDlg)
26 {
27     WCHAR szPath[MAX_PATH];
28 
29     if (SUCCEEDED(SHGetFolderPathW(NULL, CSIDL_PROGRAMS, NULL, 0, szPath)))
30     {
31         WCHAR szCommand[MAX_PATH] = L"appwiz.cpl,NewLinkHere ";
32         if (SUCCEEDED(StringCchCatW(szCommand, _countof(szCommand), szPath)))
33             ShellExecuteW(hDlg, L"open", L"rundll32.exe", szCommand, NULL, SW_SHOWNORMAL);
34     }
35 }
36 
37 VOID OnRemoveStartmenuItems(HWND hDlg)
38 {
39     ShellExecuteW(hDlg, L"open", L"rundll32.exe", L"appwiz.cpl,ConfigStartMenu", NULL, SW_SHOWNORMAL);
40 }
41 
42 VOID OnAdvancedStartMenuItems()
43 {
44     WCHAR szPath[MAX_PATH];
45 
46     if (SUCCEEDED(SHGetFolderPathW(NULL, CSIDL_STARTMENU, NULL, 0, szPath)))
47     {
48         ShellExecuteW(NULL, L"explore", szPath, NULL, NULL, SW_SHOWNORMAL);
49     }
50 }
51 
52 VOID OnClearRecentItems()
53 {
54    WCHAR szPath[MAX_PATH], szFile[MAX_PATH];
55    WIN32_FIND_DATAW info;
56    HANDLE hPath;
57 
58     if (SUCCEEDED(SHGetFolderPathW(NULL, CSIDL_RECENT, NULL, 0, szPath)))
59     {
60         StringCchPrintfW(szFile, _countof(szFile), L"%s\\*.*", szPath);
61         hPath = FindFirstFileW(szFile, &info);
62         do
63         {
64             StringCchPrintfW(szFile, _countof(szFile), L"%s\\%s", szPath, info.cFileName);
65             DeleteFileW(szFile);
66         }
67         while (FindNextFileW(hPath, &info));
68         FindClose(hPath);
69         /* FIXME: Disable the button*/
70     }
71 }
72 
73 INT_PTR CALLBACK CustomizeClassicProc(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lParam)
74 {
75     switch (Message)
76     {
77         case WM_INITDIALOG:
78             /* FIXME: Properly initialize the dialog (check whether 'clear' button must be disabled, for example) */
79             return TRUE;
80         case WM_COMMAND:
81             switch (LOWORD(wParam))
82             {
83                 case IDC_CLASSICSTART_ADD:
84                     OnAddStartMenuItems(hwnd);
85                     break;
86                 case IDC_CLASSICSTART_REMOVE:
87                     OnRemoveStartmenuItems(hwnd);
88                     break;
89                 case IDC_CLASSICSTART_ADVANCED:
90                     OnAdvancedStartMenuItems();
91                     break;
92                 case IDC_CLASSICSTART_CLEAR:
93                     OnClearRecentItems();
94                     break;
95                 case IDOK:
96                     EndDialog(hwnd, IDOK);
97                     break;
98                 case IDCANCEL:
99                     EndDialog(hwnd, IDCANCEL);
100                     break;
101             }
102             break;
103         default:
104             return FALSE;
105     }
106     return TRUE;
107 }
108 
109 VOID ShowCustomizeClassic(HINSTANCE hInst, HWND hExplorer)
110 {
111     DialogBoxW(hInst, MAKEINTRESOURCEW(IDD_CLASSICSTART_CUSTOMIZE), hExplorer, CustomizeClassicProc);
112 }
113