[CLT2012]
[reactos.git] / dll / cpl / sysdm / userprofile.c
1 /*
2 * PROJECT: ReactOS System Control Panel Applet
3 * LICENSE: GPL - See COPYING in the top level directory
4 * FILE: dll/cpl/sysdm/userprofile.c
5 * PURPOSE: Computer settings for networking
6 * COPYRIGHT: Copyright Thomas Weidenmueller <w3seek@reactos.org>
7 * Copyright 2006 Ged Murphy <gedmurphy@gmail.com>
8 *
9 */
10
11 #include "precomp.h"
12
13
14 static VOID
15 SetListViewColumns(HWND hwndListView)
16 {
17 LV_COLUMN column;
18 RECT rect;
19 TCHAR szStr[32];
20
21 GetClientRect(hwndListView, &rect);
22
23 SendMessage(hwndListView, LVM_SETEXTENDEDLISTVIEWSTYLE, 0, LVS_EX_FULLROWSELECT);
24
25 memset(&column, 0x00, sizeof(column));
26 column.mask = LVCF_FMT | LVCF_WIDTH | LVCF_SUBITEM | LVCF_TEXT;
27 column.fmt = LVCFMT_LEFT;
28 column.cx = (INT)((rect.right - rect.left) * 0.40);
29 column.iSubItem = 0;
30 LoadString(hApplet, IDS_USERPROFILE_NAME, szStr, 32);
31 column.pszText = szStr;
32 (void)ListView_InsertColumn(hwndListView, 0, &column);
33
34 column.fmt = LVCFMT_RIGHT;
35 column.cx = (INT)((rect.right - rect.left) * 0.15);
36 column.iSubItem = 1;
37 LoadString(hApplet, IDS_USERPROFILE_SIZE, szStr, 32);
38 column.pszText = szStr;
39 (void)ListView_InsertColumn(hwndListView, 1, &column);
40
41 column.fmt = LVCFMT_LEFT;
42 column.cx = (INT)((rect.right - rect.left) * 0.15);
43 column.iSubItem = 2;
44 LoadString(hApplet, IDS_USERPROFILE_TYPE, szStr, 32);
45 column.pszText = szStr;
46 (void)ListView_InsertColumn(hwndListView, 2, &column);
47
48 column.fmt = LVCFMT_LEFT;
49 column.cx = (INT)((rect.right - rect.left) * 0.15);
50 column.iSubItem = 3;
51 LoadString(hApplet, IDS_USERPROFILE_STATUS, szStr, 32);
52 column.pszText = szStr;
53 (void)ListView_InsertColumn(hwndListView, 3, &column);
54
55 column.fmt = LVCFMT_LEFT;
56 column.cx = (INT)((rect.right - rect.left) * 0.15) - GetSystemMetrics(SM_CYHSCROLL);
57 column.iSubItem = 4;
58 LoadString(hApplet, IDS_USERPROFILE_MODIFIED, szStr, 32);
59 column.pszText = szStr;
60 (void)ListView_InsertColumn(hwndListView, 4, &column);
61 }
62
63
64 static VOID
65 AddUserProfile(HWND hwndListView,
66 LPTSTR lpProfileSid)
67 {
68 LV_ITEM lvi;
69
70 memset(&lvi, 0x00, sizeof(lvi));
71 lvi.mask = LVIF_TEXT | LVIF_STATE;
72 lvi.pszText = lpProfileSid;
73 lvi.state = 0;
74 ListView_InsertItem(hwndListView, &lvi);
75 }
76
77
78 static VOID
79 AddUserProfiles(HWND hwndListView)
80 {
81 HKEY hKeyUserProfiles;
82 DWORD dwIndex;
83 TCHAR szProfileSid[64];
84 DWORD dwSidLength;
85 FILETIME ftLastWrite;
86
87 if (RegOpenKeyEx(HKEY_LOCAL_MACHINE,
88 _T("Software\\Microsoft\\Windows NT\\CurrentVersion\\ProfileList"),
89 0,
90 KEY_READ,
91 &hKeyUserProfiles))
92 return;
93
94 for (dwIndex = 0; ; dwIndex++)
95 {
96 dwSidLength = 64;
97 if (RegEnumKeyEx(hKeyUserProfiles,
98 dwIndex,
99 szProfileSid,
100 &dwSidLength,
101 NULL,
102 NULL,
103 NULL,
104 &ftLastWrite))
105 break;
106
107 AddUserProfile(hwndListView, szProfileSid);
108 }
109
110 RegCloseKey(hKeyUserProfiles);
111 }
112
113
114 static VOID
115 OnInitDialog(HWND hwndDlg)
116 {
117 /* Initialize the list view control */
118 SetListViewColumns(GetDlgItem(hwndDlg, IDC_USERPROFILE_LIST));
119
120 AddUserProfiles(GetDlgItem(hwndDlg, IDC_USERPROFILE_LIST));
121
122 /* Disable the "Delete" and "Copy To" buttons if the user is not an admin */
123 if (!IsUserAnAdmin())
124 {
125 EnableWindow(GetDlgItem(hwndDlg, IDC_USERPROFILE_DELETE), FALSE);
126 EnableWindow(GetDlgItem(hwndDlg, IDC_USERPROFILE_COPY), FALSE);
127 }
128 }
129
130
131 /* Property page dialog callback */
132 INT_PTR CALLBACK
133 UserProfileDlgProc(HWND hwndDlg,
134 UINT uMsg,
135 WPARAM wParam,
136 LPARAM lParam)
137 {
138 switch (uMsg)
139 {
140 case WM_INITDIALOG:
141 OnInitDialog(hwndDlg);
142 break;
143
144 case WM_COMMAND:
145 if ((LOWORD(wParam) == IDOK) || (LOWORD(wParam) == IDCANCEL))
146 {
147 EndDialog(hwndDlg,
148 LOWORD(wParam));
149 return TRUE;
150 }
151 break;
152
153 case WM_NOTIFY:
154 {
155 NMHDR *nmhdr = (NMHDR *)lParam;
156
157 if (nmhdr->idFrom == IDC_USERACCOUNT_LINK && nmhdr->code == NM_CLICK)
158 {
159 ShellExecute(hwndDlg,
160 TEXT("open"),
161 TEXT("rundll32.exe"),
162 TEXT("shell32.dll, Control_RunDLL nusrmgr.cpl"),
163 NULL,
164 SW_SHOWNORMAL);
165 }
166 break;
167 }
168 }
169
170 return FALSE;
171 }