fixed some bugs
[reactos.git] / reactos / subsys / system / msconfig / startuppage.c
1 #include <precomp.h>
2
3 HWND hStartupPage;
4 HWND hStartupListCtrl;
5 HWND hStartupDialog;
6
7 void GetAutostartEntriesFromRegistry ( HKEY hRootKey, TCHAR* KeyName );
8
9 INT_PTR CALLBACK
10 StartupPageWndProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
11 {
12 LV_COLUMN column;
13 TCHAR szTemp[256];
14 DWORD dwStyle;
15
16 switch (message) {
17 case WM_INITDIALOG:
18
19 hStartupListCtrl = GetDlgItem(hDlg, IDC_STARTUP_LIST);
20 hStartupDialog = hDlg;
21
22 dwStyle = (DWORD) SendMessage(hStartupListCtrl, LVM_GETEXTENDEDLISTVIEWSTYLE, 0, 0);
23 dwStyle = dwStyle | LVS_EX_FULLROWSELECT | LVS_EX_CHECKBOXES;
24 SendMessage(hStartupListCtrl, LVM_SETEXTENDEDLISTVIEWSTYLE, 0, dwStyle);
25
26 SetWindowPos(hDlg, NULL, 10, 32, 0, 0, SWP_NOACTIVATE | SWP_NOOWNERZORDER | SWP_NOSIZE | SWP_NOZORDER);
27
28 // Initialize the application page's controls
29 column.mask = LVCF_TEXT | LVCF_WIDTH;
30
31 LoadString(hInst, IDS_STARTUP_COLUMN_ELEMENT, szTemp, 256);
32 column.pszText = szTemp;
33 column.cx = 150;
34 ListView_InsertColumn(hStartupListCtrl, 0, &column);
35
36 column.mask = LVCF_TEXT | LVCF_WIDTH;
37 LoadString(hInst, IDS_STARTUP_COLUMN_CMD, szTemp, 256);
38 column.pszText = szTemp;
39 column.cx = 150;
40 ListView_InsertColumn(hStartupListCtrl, 1, &column);
41
42 column.mask = LVCF_TEXT | LVCF_WIDTH;
43 LoadString(hInst, IDS_STARTUP_COLUMN_PATH, szTemp, 256);
44 column.pszText = szTemp;
45 column.cx = 250;
46 ListView_InsertColumn(hStartupListCtrl, 2, &column);
47
48 GetAutostartEntriesFromRegistry(HKEY_LOCAL_MACHINE, _T("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run"));
49 GetAutostartEntriesFromRegistry(HKEY_CURRENT_USER, _T("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run"));
50 //FIXME: What about HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon\Userinit
51 //FIXME: Common Startup (startmenu)
52
53 return TRUE;
54 }
55
56 return 0;
57 }
58
59 void
60 GetAutostartEntriesFromRegistry ( HKEY hRootKey, TCHAR* KeyName )
61 {
62 HKEY hKey;
63 DWORD Index, dwValues, retVal, dwType;
64 DWORD dwValueLength, dwDataLength = MAX_VALUE_NAME;
65 TCHAR* Data;
66 TCHAR lpValueName[MAX_KEY_LENGTH];
67 TCHAR Path[MAX_KEY_LENGTH + 5];
68 LV_ITEM item;
69
70 if (RegOpenKeyEx(hRootKey, KeyName, 0, KEY_READ, &hKey) == ERROR_SUCCESS)
71 {
72 if (RegQueryInfoKey(hKey, NULL, NULL, NULL, NULL, NULL, NULL, &dwValues, NULL, NULL, NULL, NULL) == ERROR_SUCCESS)
73 {
74 for (Index = 0, retVal = ERROR_SUCCESS; Index < dwValues; Index++)
75 {
76 dwValueLength = MAX_KEY_LENGTH;
77 dwDataLength = MAX_VALUE_NAME;
78 Data = (TCHAR*) HeapAlloc(GetProcessHeap(), 0, MAX_VALUE_NAME);
79 if (Data == NULL)
80 break;
81 retVal = RegEnumValue(hKey, Index, lpValueName, &dwValueLength, NULL, &dwType, (LPBYTE)Data, &dwDataLength);
82 if (retVal == ERROR_SUCCESS)
83 {
84 memset(&item, 0, sizeof(LV_ITEM));
85 item.mask = LVIF_TEXT;
86 item.iImage = 0;
87 item.pszText = lpValueName;
88 item.iItem = ListView_GetItemCount(hStartupListCtrl);
89 item.lParam = 0;
90 ListView_InsertItem(hStartupListCtrl, &item);
91
92 if (dwType == REG_SZ)
93 {
94 GetLongPathName(Data, Data, (DWORD) _tcsclen(Data));
95 item.pszText = Data;
96 item.iSubItem = 1;
97 SendMessage(hStartupListCtrl, LVM_SETITEMTEXT, item.iItem, (LPARAM) &item);
98 }
99
100 switch (PtrToLong(hRootKey))
101 {
102 case HKEY_LOCAL_MACHINE:
103 _tcscpy(Path, _T("HKLM\\\0"));
104 break;
105 case HKEY_CURRENT_USER:
106 _tcscpy(Path, _T("HKCU\\\0"));
107 break;
108 default:
109 _tcscpy(Path, _T("\0"));
110 }
111
112 _tcscat(Path, KeyName);
113 item.pszText = Path;
114 item.iSubItem = 2;
115 SendMessage(hStartupListCtrl, LVM_SETITEMTEXT, item.iItem, (LPARAM) &item);
116 HeapFree(GetProcessHeap(), 0, Data);
117 }
118 }
119 }
120 RegCloseKey(hKey);
121 }
122
123 }