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