1 /* 2 * PROJECT: ReactOS Applications 3 * LICENSE: LGPL - See COPYING in the top level directory 4 * FILE: base/applications/msconfig/toolspage.c 5 * PURPOSE: Tools page message handler 6 * COPYRIGHT: Copyright 2005-2006 Christoph von Wittich <Christoph@ApiViewer.de> 7 * 8 */ 9 10 #include "precomp.h" 11 12 #include <shlwapi.h> 13 14 HWND hToolsPage; 15 HWND hToolsListCtrl; 16 HWND hToolsDialog; 17 18 void AddItem ( DWORD, DWORD, DWORD, DWORD, int ); 19 void FillListView ( void ); 20 21 DWORD ListItems_Cmds[20]; 22 DWORD ListItems_Params[20]; 23 DWORD ListItems_Locations[20]; 24 25 void AddItem ( DWORD name_id, DWORD descr_id, DWORD cmd_id , DWORD param_id, int csidl ) { 26 TCHAR szTemp[256]; 27 LV_ITEM item; 28 29 LoadString(hInst, name_id, szTemp, 256); 30 memset(&item, 0, sizeof(LV_ITEM)); 31 item.mask = LVIF_TEXT; 32 item.iImage = 0; 33 item.pszText = szTemp; 34 item.iItem = ListView_GetItemCount(hToolsListCtrl); 35 item.lParam = 0; 36 (void)ListView_InsertItem(hToolsListCtrl, &item); 37 38 ListItems_Cmds[item.iItem] = cmd_id; 39 ListItems_Params[item.iItem] = param_id; 40 ListItems_Locations[item.iItem] = csidl; 41 42 LoadString(hInst, descr_id, szTemp, 256); 43 item.pszText = szTemp; 44 item.iSubItem = 1; 45 SendMessage(hToolsListCtrl, LVM_SETITEMTEXT, item.iItem, (LPARAM) &item); 46 } 47 48 void FillListView ( void ) { 49 AddItem(IDS_TOOLS_CMD_NAME, IDS_TOOLS_CMD_DESCR, IDS_TOOLS_CMD_CMD, IDS_TOOLS_CMD_PARAM, CSIDL_SYSTEM); 50 AddItem(IDS_TOOLS_REGEDIT_NAME, IDS_TOOLS_REGEDIT_DESCR, IDS_TOOLS_REGEDIT_CMD,IDS_TOOLS_REGEDIT_PARAM, CSIDL_WINDOWS); 51 AddItem(IDS_TOOLS_SYSDM_NAME, IDS_TOOLS_SYSDM_DESCR, IDS_TOOLS_SYSDM_CMD, IDS_TOOLS_SYSDM_PARAM, CSIDL_SYSTEM); 52 AddItem(IDS_TOOLS_INFO_NAME, IDS_TOOLS_INFO_DESCR, IDS_TOOLS_INFO_CMD, IDS_TOOLS_INFO_PARAM, CSIDL_SYSTEM); 53 } 54 55 INT_PTR CALLBACK 56 ToolsPageWndProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam) 57 { 58 LV_COLUMN column; 59 TCHAR szTemp[MAX_PATH*2]; 60 TCHAR szTemp2[256]; 61 TCHAR * Ptr = NULL; 62 LPNMITEMACTIVATE lpnmitem; 63 LPNMHDR nmh; 64 DWORD dwStyle; 65 PROCESS_INFORMATION pi; 66 STARTUPINFO si; 67 68 switch (message) 69 { 70 case WM_INITDIALOG: 71 { 72 hToolsListCtrl = GetDlgItem(hDlg, IDC_TOOLS_LIST); 73 hToolsDialog = hDlg; 74 75 dwStyle = (DWORD) SendMessage(hToolsListCtrl, LVM_GETEXTENDEDLISTVIEWSTYLE, 0, 0); 76 dwStyle = dwStyle | LVS_EX_FULLROWSELECT; 77 SendMessage(hToolsListCtrl, LVM_SETEXTENDEDLISTVIEWSTYLE, 0, dwStyle); 78 79 SetWindowPos(hDlg, NULL, 10, 32, 0, 0, SWP_NOACTIVATE | SWP_NOOWNERZORDER | SWP_NOSIZE | SWP_NOZORDER); 80 81 // Initialize the application page's controls 82 column.mask = LVCF_TEXT | LVCF_WIDTH; 83 84 LoadString(hInst, IDS_TOOLS_COLUMN_NAME, szTemp, 256); 85 column.pszText = szTemp; 86 column.cx = 150; 87 (void)ListView_InsertColumn(hToolsListCtrl, 0, &column); 88 89 column.mask = LVCF_TEXT | LVCF_WIDTH; 90 LoadString(hInst, IDS_TOOLS_COLUMN_DESCR, szTemp, 256); 91 column.pszText = szTemp; 92 column.cx = 500; 93 (void)ListView_InsertColumn(hToolsListCtrl, 1, &column); 94 95 FillListView(); 96 return TRUE; 97 } 98 case WM_COMMAND: 99 { 100 switch (LOWORD(wParam)) 101 { 102 case IDC_BTN_RUN: 103 { 104 if (ListView_GetSelectionMark(hToolsListCtrl) != -1) 105 { 106 if (SHGetSpecialFolderPath(NULL, szTemp, ListItems_Locations[ListView_GetSelectionMark(hToolsListCtrl)], FALSE)) 107 Ptr = PathAddBackslash(szTemp); 108 109 if (!Ptr) 110 Ptr = szTemp; 111 112 szTemp2[0] = _T('\0'); 113 LoadString(hInst, ListItems_Cmds[ListView_GetSelectionMark(hToolsListCtrl)], Ptr, 256); 114 LoadString(hInst, ListItems_Params[ListView_GetSelectionMark(hToolsListCtrl)], szTemp2, 256); 115 if (_tcslen(szTemp2)) 116 { 117 _tcscat(szTemp, _T(" ")); 118 _tcscat(Ptr, szTemp2); 119 } 120 ZeroMemory(&si, sizeof(STARTUPINFO)); 121 si.cb = sizeof(STARTUPINFO); 122 if (CreateProcess(NULL, szTemp, NULL, NULL, FALSE, 0, NULL, NULL, &si, &pi)) 123 { 124 CloseHandle(pi.hThread); 125 CloseHandle(pi.hProcess); 126 } 127 } 128 } 129 } 130 break; 131 } 132 case WM_NOTIFY: 133 { 134 nmh = (LPNMHDR) lParam; 135 if (nmh->hwndFrom == hToolsListCtrl) 136 { 137 switch (nmh->code) 138 { 139 case LVN_ITEMCHANGED: 140 { 141 lpnmitem = (LPNMITEMACTIVATE) lParam; 142 if (lpnmitem->iItem > -1) 143 { 144 LoadString(hInst, ListItems_Cmds[lpnmitem->iItem], szTemp, 256); 145 szTemp2[0] = _T('\0'); 146 LoadString(hInst, ListItems_Params[lpnmitem->iItem], szTemp2, 256); 147 _tcscat(szTemp, _T(" ")); 148 _tcscat(szTemp, szTemp2); 149 SendDlgItemMessage(hToolsDialog, IDC_TOOLS_CMDLINE, WM_SETTEXT, 0, (LPARAM) szTemp); 150 } 151 break; 152 } 153 case NM_DBLCLK: 154 { 155 lpnmitem = (LPNMITEMACTIVATE) lParam; 156 if (lpnmitem->iItem > -1) 157 { 158 if (SHGetSpecialFolderPath(NULL, szTemp, ListItems_Locations[ListView_GetSelectionMark(hToolsListCtrl)], FALSE)) 159 Ptr = PathAddBackslash(szTemp); 160 161 if (!Ptr) 162 Ptr = szTemp; 163 164 szTemp2[0] = _T('\0'); 165 LoadString(hInst, ListItems_Cmds[lpnmitem->iItem], Ptr, 256); 166 LoadString(hInst, ListItems_Params[lpnmitem->iItem], szTemp2, 256); 167 if (_tcslen(szTemp2)) 168 { 169 _tcscat(szTemp, _T(" ")); 170 _tcscat(Ptr, szTemp2); 171 } 172 ZeroMemory(&si, sizeof(STARTUPINFO)); 173 si.cb = sizeof(STARTUPINFO); 174 if (CreateProcess(NULL, szTemp, NULL, NULL, FALSE, 0, NULL, NULL, &si, &pi)) 175 { 176 CloseHandle(pi.hThread); 177 CloseHandle(pi.hProcess); 178 } 179 } 180 break; 181 } 182 } 183 } 184 } 185 break; 186 } 187 return 0; 188 } 189 190