3 * Copyright (C) 2004 ReactOS Team
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19 /* $Id: environment.c,v 1.1 2004/07/02 20:28:00 ekohl Exp $
21 * PROJECT: ReactOS System Control Panel
22 * FILE: lib/cpl/sysdm/environment.c
23 * PURPOSE: Environment variable settings
24 * PROGRAMMER: Eric Kohl
37 SetEnvironmentVariables(HWND hwndListView
,
43 DWORD dwMaxValueNameLength
;
44 DWORD dwMaxValueDataLength
;
56 if (RegOpenKeyEx(hRootKey
,
63 if (RegQueryInfoKey(hKey
,
71 &dwMaxValueNameLength
,
72 &dwMaxValueDataLength
,
80 lpName
= GlobalAlloc(GPTR
, (dwMaxValueNameLength
+ 1) * sizeof(TCHAR
));
87 lpData
= GlobalAlloc(GPTR
, (dwMaxValueDataLength
+ 1) * sizeof(TCHAR
));
95 for (i
= 0; i
< dwValues
; i
++)
97 dwNameLength
= dwMaxValueNameLength
+ 1;
98 dwDataLength
= dwMaxValueDataLength
+ 1;
99 if (RegEnumValue(hKey
,
114 if (dwType
== REG_EXPAND_SZ
)
116 lpExpandData
= GlobalAlloc(GPTR
, MAX_PATH
* sizeof(TCHAR
));
117 if (lpExpandData
== NULL
)
125 ExpandEnvironmentStrings(lpData
,
130 memset(&lvi
, 0x00, sizeof(lvi
));
131 lvi
.mask
= LVIF_TEXT
| LVIF_STATE
;
132 lvi
.pszText
= lpName
;
134 nIndex
= ListView_InsertItem(hwndListView
, &lvi
);
136 if (dwType
== REG_EXPAND_SZ
)
138 ListView_SetItemText(hwndListView
, nIndex
, 1, lpExpandData
);
139 GlobalFree(lpExpandData
);
143 ListView_SetItemText(hwndListView
, nIndex
, 1, lpData
);
154 SetListViewColumns(HWND hwndListView
)
159 GetClientRect(hwndListView
, &rect
);
161 memset(&column
, 0x00, sizeof(column
));
162 column
.mask
=LVCF_FMT
| LVCF_WIDTH
| LVCF_SUBITEM
|LVCF_TEXT
;
163 column
.fmt
=LVCFMT_LEFT
;
164 column
.cx
= (rect
.right
- rect
.left
) / 3;
166 column
.pszText
= _T("Variable");
167 ListView_InsertColumn(hwndListView
, 0, &column
);
169 column
.cx
= (rect
.right
- rect
.left
) - ((rect
.right
- rect
.left
) / 3) - 1;
171 column
.pszText
= _T("Value");
172 ListView_InsertColumn(hwndListView
, 1, &column
);
177 OnInitDialog(HWND hwndDlg
)
181 /* Set user environment variables */
182 hwndListView
= GetDlgItem(hwndDlg
, IDC_USER_VARIABLE_LIST
);
184 SetListViewColumns(hwndListView
);
186 SetEnvironmentVariables(hwndListView
,
190 ListView_SetColumnWidth(hwndListView
,2,LVSCW_AUTOSIZE_USEHEADER
);
191 ListView_Update(hwndListView
,0);
194 /* Set system environment variables */
195 hwndListView
= GetDlgItem(hwndDlg
, IDC_SYSTEM_VARIABLE_LIST
);
197 SetListViewColumns(hwndListView
);
199 SetEnvironmentVariables(hwndListView
,
201 _T("SYSTEM\\CurrentControlSet\\Control\\Session Manager\\Environment"));
203 ListView_SetColumnWidth(hwndListView
,2,LVSCW_AUTOSIZE_USEHEADER
);
204 ListView_Update(hwndListView
,0);
208 /* Environment dialog procedure */
210 EnvironmentDlgProc(HWND hwndDlg
,
218 OnInitDialog(hwndDlg
);
222 switch (LOWORD(wParam
))
224 case IDC_USER_VARIABLE_NEW
:
225 case IDC_USER_VARIABLE_EDIT
:
226 case IDC_USER_VARIABLE_DELETE
:
229 case IDC_SYSTEM_VARIABLE_NEW
:
230 case IDC_SYSTEM_VARIABLE_EDIT
:
231 case IDC_SYSTEM_VARIABLE_DELETE
:
235 EndDialog(hwndDlg
, 0);
239 EndDialog(hwndDlg
, 0);