ReactOS  0.4.14-dev-599-g2d4d3f5
environment.c File Reference
#include "precomp.h"
Include dependency graph for environment.c:

Go to the source code of this file.

Classes

struct  _VARIABLE_DATA
 

Typedefs

typedef struct _VARIABLE_DATA VARIABLE_DATA
 
typedef struct _VARIABLE_DATAPVARIABLE_DATA
 

Functions

static INT GetSelectedListViewItem (HWND hwndListView)
 
static INT_PTR CALLBACK EditVariableDlgProc (HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
 
static VOID GetEnvironmentVariables (HWND hwndListView, HKEY hRootKey, LPTSTR lpSubKeyName)
 
static VOID SetEnvironmentDialogListViewColumns (HWND hwndListView)
 
static VOID OnInitEnvironmentDialog (HWND hwndDlg)
 
static VOID OnNewVariable (HWND hwndDlg, INT iDlgItem)
 
static VOID OnEditVariable (HWND hwndDlg, INT iDlgItem)
 
static VOID OnDeleteVariable (HWND hwndDlg, INT iDlgItem)
 
static VOID ReleaseListViewItems (HWND hwndDlg, INT iDlgItem)
 
static VOID SetAllVars (HWND hwndDlg, INT iDlgItem)
 
static BOOL OnNotify (HWND hwndDlg, NMHDR *phdr)
 
INT_PTR CALLBACK EnvironmentDlgProc (HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
 

Typedef Documentation

◆ PVARIABLE_DATA

◆ VARIABLE_DATA

Function Documentation

◆ EditVariableDlgProc()

static INT_PTR CALLBACK EditVariableDlgProc ( HWND  hwndDlg,
UINT  uMsg,
WPARAM  wParam,
LPARAM  lParam 
)
static

Definition at line 50 of file environment.c.

54 {
55  PVARIABLE_DATA VarData;
56  DWORD dwNameLength;
57  DWORD dwValueLength;
58 
59  VarData = (PVARIABLE_DATA)GetWindowLongPtr(hwndDlg, GWLP_USERDATA);
60 
61  switch (uMsg)
62  {
63  case WM_INITDIALOG:
65  VarData = (PVARIABLE_DATA)lParam;
66 
67  if (VarData->lpName != NULL)
68  {
70  }
71 
72  if (VarData->lpRawValue != NULL)
73  {
75  }
76  break;
77 
78  case WM_COMMAND:
79  switch (LOWORD(wParam))
80  {
81  case IDOK:
82  dwNameLength = (DWORD)SendDlgItemMessage(hwndDlg, IDC_VARIABLE_NAME, WM_GETTEXTLENGTH, 0, 0);
83  dwValueLength = (DWORD)SendDlgItemMessage(hwndDlg, IDC_VARIABLE_VALUE, WM_GETTEXTLENGTH, 0, 0);
84  if (dwNameLength > 0 && dwValueLength > 0)
85  {
86  LPTSTR p;
87 
88  if (VarData->lpName == NULL)
89  {
90  VarData->lpName = GlobalAlloc(GPTR, (dwNameLength + 1) * sizeof(TCHAR));
91  }
92  else if (_tcslen(VarData->lpName) < dwNameLength)
93  {
94  GlobalFree(VarData->lpName);
95  VarData->lpName = GlobalAlloc(GPTR, (dwNameLength + 1) * sizeof(TCHAR));
96  }
97  SendDlgItemMessage(hwndDlg, IDC_VARIABLE_NAME, WM_GETTEXT, dwNameLength + 1, (LPARAM)VarData->lpName);
98 
99  if (VarData->lpRawValue == NULL)
100  {
101  VarData->lpRawValue = GlobalAlloc(GPTR, (dwValueLength + 1) * sizeof(TCHAR));
102  }
103  else if (_tcslen(VarData->lpRawValue) < dwValueLength)
104  {
105  GlobalFree(VarData->lpRawValue);
106  VarData->lpRawValue = GlobalAlloc(GPTR, (dwValueLength + 1) * sizeof(TCHAR));
107  }
108  SendDlgItemMessage(hwndDlg, IDC_VARIABLE_VALUE, WM_GETTEXT, dwValueLength + 1, (LPARAM)VarData->lpRawValue);
109 
110  if (VarData->lpCookedValue != NULL)
111  {
112  GlobalFree(VarData->lpCookedValue);
113  VarData->lpCookedValue = NULL;
114  }
115 
116  p = _tcschr(VarData->lpRawValue, _T('%'));
117  if (p && _tcschr(++p, _T('%')))
118  {
119  VarData->dwType = REG_EXPAND_SZ;
120  VarData->lpCookedValue = GlobalAlloc(GPTR, 2 * MAX_PATH * sizeof(TCHAR));
121 
123  VarData->lpCookedValue,
124  2 * MAX_PATH);
125  }
126  else
127  {
128  VarData->dwType = REG_SZ;
129  VarData->lpCookedValue = GlobalAlloc(GPTR, (dwValueLength + 1) * sizeof(TCHAR));
130  _tcscpy(VarData->lpCookedValue, VarData->lpRawValue);
131  }
132  }
133  EndDialog(hwndDlg, 1);
134  return TRUE;
135 
136  case IDCANCEL:
137  EndDialog(hwndDlg, 0);
138  return TRUE;
139  }
140  break;
141  }
142 
143  return FALSE;
144 }
#define WM_GETTEXTLENGTH
Definition: winuser.h:1601
#define TRUE
Definition: types.h:120
HGLOBAL NTAPI GlobalAlloc(UINT uFlags, SIZE_T dwBytes)
Definition: heapmem.c:368
#define IDOK
Definition: winuser.h:824
#define GPTR
Definition: winbase.h:293
LPTSTR lpCookedValue
Definition: environment.c:17
LPTSTR lpRawValue
Definition: environment.c:16
#define WM_GETTEXT
Definition: winuser.h:1600
#define ExpandEnvironmentStrings
Definition: winbase.h:3608
_TCHAR * _tcscpy(_TCHAR *to, const _TCHAR *from)
Definition: tcscpy.h:8
#define SendDlgItemMessage
Definition: winuser.h:5817
#define DWORD
Definition: nt_native.h:44
#define SetWindowLongPtr
Definition: treelist.c:70
BOOL WINAPI EndDialog(_In_ HWND, _In_ INT_PTR)
WPARAM wParam
Definition: combotst.c:138
CHAR * LPTSTR
Definition: xmlstorage.h:192
#define GWLP_USERDATA
Definition: treelist.c:63
size_t __cdecl _tcslen(const _TCHAR *str)
Definition: tcslen.h:9
smooth NULL
Definition: ftsmooth.c:416
LONG_PTR LPARAM
Definition: windef.h:208
#define WM_SETTEXT
Definition: winuser.h:1599
_TCHAR * _tcschr(const _TCHAR *s, _XINT c)
Definition: tcschr.h:4
char TCHAR
Definition: xmlstorage.h:189
#define _T(x)
Definition: vfdio.h:22
#define MAX_PATH
Definition: compat.h:26
unsigned long DWORD
Definition: ntddk_ex.h:95
HGLOBAL NTAPI GlobalFree(HGLOBAL hMem)
Definition: heapmem.c:611
struct _VARIABLE_DATA * PVARIABLE_DATA
#define WM_COMMAND
Definition: winuser.h:1722
#define IDC_VARIABLE_VALUE
Definition: resource.h:135
#define IDC_VARIABLE_NAME
Definition: resource.h:134
#define REG_EXPAND_SZ
Definition: nt_native.h:1494
__int3264 LONG_PTR
Definition: mstsclib_h.h:276
#define GetWindowLongPtr
Definition: treelist.c:73
GLfloat GLfloat p
Definition: glext.h:8902
#define IDCANCEL
Definition: winuser.h:825
#define WM_INITDIALOG
Definition: winuser.h:1721
LPARAM lParam
Definition: combotst.c:139
#define LOWORD(l)
Definition: pedump.c:82
#define REG_SZ
Definition: layer.c:22

Referenced by OnEditVariable(), and OnNewVariable().

◆ EnvironmentDlgProc()

INT_PTR CALLBACK EnvironmentDlgProc ( HWND  hwndDlg,
UINT  uMsg,
WPARAM  wParam,
LPARAM  lParam 
)

Definition at line 685 of file environment.c.

689 {
690  switch (uMsg)
691  {
692  case WM_INITDIALOG:
693  OnInitEnvironmentDialog(hwndDlg);
694  break;
695 
696  case WM_COMMAND:
697  switch (LOWORD(wParam))
698  {
701  return TRUE;
702 
705  return TRUE;
706 
709  return TRUE;
710 
713  return TRUE;
714 
717  return TRUE;
718 
721  return TRUE;
722 
723  case IDOK:
727  0, (LPARAM)_T("Environment"));
728  EndDialog(hwndDlg, 0);
729  return TRUE;
730 
731  case IDCANCEL:
732  EndDialog(hwndDlg, 0);
733  return TRUE;
734  }
735  break;
736 
737  case WM_DESTROY:
740  break;
741 
742  case WM_NOTIFY:
743  return OnNotify(hwndDlg, (NMHDR*)lParam);
744  }
745 
746  return FALSE;
747 }
#define TRUE
Definition: types.h:120
#define IDOK
Definition: winuser.h:824
#define IDC_USER_VARIABLE_LIST
Definition: resource.h:123
static VOID ReleaseListViewItems(HWND hwndDlg, INT iDlgItem)
Definition: environment.c:477
static BOOL OnNotify(HWND hwndDlg, NMHDR *phdr)
Definition: environment.c:655
#define IDC_SYSTEM_VARIABLE_NEW
Definition: resource.h:128
BOOL WINAPI EndDialog(_In_ HWND, _In_ INT_PTR)
WPARAM wParam
Definition: combotst.c:138
static VOID OnNewVariable(HWND hwndDlg, INT iDlgItem)
Definition: environment.c:344
static VOID OnEditVariable(HWND hwndDlg, INT iDlgItem)
Definition: environment.c:391
#define WM_WININICHANGE
Definition: winuser.h:1612
LONG_PTR LPARAM
Definition: windef.h:208
static VOID OnInitEnvironmentDialog(HWND hwndDlg)
Definition: environment.c:299
#define IDC_USER_VARIABLE_EDIT
Definition: resource.h:125
#define WM_DESTROY
Definition: winuser.h:1591
#define _T(x)
Definition: vfdio.h:22
static VOID SetAllVars(HWND hwndDlg, INT iDlgItem)
Definition: environment.c:519
#define IDC_SYSTEM_VARIABLE_DELETE
Definition: resource.h:130
#define IDC_SYSTEM_VARIABLE_EDIT
Definition: resource.h:129
#define IDC_USER_VARIABLE_NEW
Definition: resource.h:124
#define WM_COMMAND
Definition: winuser.h:1722
#define IDC_USER_VARIABLE_DELETE
Definition: resource.h:126
#define SendMessage
Definition: winuser.h:5818
#define IDCANCEL
Definition: winuser.h:825
#define HWND_BROADCAST
Definition: winuser.h:1190
static VOID OnDeleteVariable(HWND hwndDlg, INT iDlgItem)
Definition: environment.c:427
#define WM_INITDIALOG
Definition: winuser.h:1721
LPARAM lParam
Definition: combotst.c:139
#define LOWORD(l)
Definition: pedump.c:82
#define IDC_SYSTEM_VARIABLE_LIST
Definition: resource.h:127
#define WM_NOTIFY
Definition: richedit.h:61

Referenced by AdvancedPageProc().

◆ GetEnvironmentVariables()

static VOID GetEnvironmentVariables ( HWND  hwndListView,
HKEY  hRootKey,
LPTSTR  lpSubKeyName 
)
static

Definition at line 148 of file environment.c.

151 {
152  HKEY hKey;
153  DWORD dwValues;
154  DWORD dwMaxValueNameLength;
155  DWORD dwMaxValueDataLength;
156  DWORD i;
157  LPTSTR lpName;
158  LPTSTR lpData;
159  LPTSTR lpExpandData;
160  DWORD dwNameLength;
161  DWORD dwDataLength;
162  DWORD dwType;
163  PVARIABLE_DATA VarData;
164 
165  LV_ITEM lvi;
166  int iItem;
167 
168  if (RegOpenKeyEx(hRootKey,
169  lpSubKeyName,
170  0,
171  KEY_READ,
172  &hKey))
173  return;
174 
175  if (RegQueryInfoKey(hKey,
176  NULL,
177  NULL,
178  NULL,
179  NULL,
180  NULL,
181  NULL,
182  &dwValues,
183  &dwMaxValueNameLength,
184  &dwMaxValueDataLength,
185  NULL,
186  NULL))
187  {
188  RegCloseKey(hKey);
189  return;
190  }
191 
192  lpName = GlobalAlloc(GPTR, (dwMaxValueNameLength + 1) * sizeof(TCHAR));
193  if (lpName == NULL)
194  {
195  RegCloseKey(hKey);
196  return;
197  }
198 
199  lpData = GlobalAlloc(GPTR, (dwMaxValueDataLength + 1) * sizeof(TCHAR));
200  if (lpData == NULL)
201  {
203  RegCloseKey(hKey);
204  return;
205  }
206 
207  lpExpandData = GlobalAlloc(GPTR, 2048 * sizeof(TCHAR));
208  if (lpExpandData == NULL)
209  {
211  GlobalFree(lpData);
212  RegCloseKey(hKey);
213  return;
214  }
215 
216  for (i = 0; i < dwValues; i++)
217  {
218  dwNameLength = dwMaxValueNameLength + 1;
219  dwDataLength = dwMaxValueDataLength + 1;
220 
221  if (RegEnumValue(hKey,
222  i,
223  lpName,
224  &dwNameLength,
225  NULL,
226  &dwType,
227  (LPBYTE)lpData,
228  &dwDataLength))
229  {
230  GlobalFree(lpExpandData);
232  GlobalFree(lpData);
233  RegCloseKey(hKey);
234  return;
235  }
236 
237  if (dwType != REG_SZ && dwType != REG_EXPAND_SZ)
238  continue;
239 
240  VarData = GlobalAlloc(GPTR, sizeof(VARIABLE_DATA));
241 
242  VarData->dwType = dwType;
243 
244  VarData->lpName = GlobalAlloc(GPTR, (dwNameLength + 1) * sizeof(TCHAR));
245  _tcscpy(VarData->lpName, lpName);
246 
247  VarData->lpRawValue = GlobalAlloc(GPTR, (dwDataLength + 1) * sizeof(TCHAR));
248  _tcscpy(VarData->lpRawValue, lpData);
249 
250  ExpandEnvironmentStrings(lpData, lpExpandData, 2048);
251 
252  VarData->lpCookedValue = GlobalAlloc(GPTR, (_tcslen(lpExpandData) + 1) * sizeof(TCHAR));
253  _tcscpy(VarData->lpCookedValue, lpExpandData);
254 
255  memset(&lvi, 0x00, sizeof(lvi));
256  lvi.mask = LVIF_TEXT | LVIF_STATE | LVIF_PARAM;
257  lvi.lParam = (LPARAM)VarData;
258  lvi.pszText = VarData->lpName;
259  lvi.state = (i == 0) ? LVIS_SELECTED : 0;
260  iItem = ListView_InsertItem(hwndListView, &lvi);
261 
262  ListView_SetItemText(hwndListView, iItem, 1, VarData->lpCookedValue);
263  }
264 
265  GlobalFree(lpExpandData);
267  GlobalFree(lpData);
268  RegCloseKey(hKey);
269 }
#define LV_ITEM
Definition: commctrl.h:2333
HGLOBAL NTAPI GlobalAlloc(UINT uFlags, SIZE_T dwBytes)
Definition: heapmem.c:368
#define RegQueryInfoKey
Definition: winreg.h:521
#define GPTR
Definition: winbase.h:293
LPTSTR lpCookedValue
Definition: environment.c:17
#define KEY_READ
Definition: nt_native.h:1023
LPTSTR lpRawValue
Definition: environment.c:16
#define ExpandEnvironmentStrings
Definition: winbase.h:3608
_In_ LPCSTR lpName
Definition: winbase.h:2746
_TCHAR * _tcscpy(_TCHAR *to, const _TCHAR *from)
Definition: tcscpy.h:8
#define ListView_InsertItem(hwnd, pitem)
Definition: commctrl.h:2404
CHAR * LPTSTR
Definition: xmlstorage.h:192
#define LVIF_TEXT
Definition: commctrl.h:2305
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
LONG WINAPI RegCloseKey(HKEY hKey)
Definition: reg.c:423
unsigned char * LPBYTE
Definition: typedefs.h:52
size_t __cdecl _tcslen(const _TCHAR *str)
Definition: tcslen.h:9
HWND hwndListView
Definition: eventvwr.c:83
smooth NULL
Definition: ftsmooth.c:416
#define LVIS_SELECTED
Definition: commctrl.h:2315
LONG_PTR LPARAM
Definition: windef.h:208
#define ListView_SetItemText(hwndLV, i, iSubItem_, pszText_)
Definition: commctrl.h:2687
char TCHAR
Definition: xmlstorage.h:189
unsigned long DWORD
Definition: ntddk_ex.h:95
HGLOBAL NTAPI GlobalFree(HGLOBAL hMem)
Definition: heapmem.c:611
#define RegOpenKeyEx
Definition: winreg.h:520
#define REG_EXPAND_SZ
Definition: nt_native.h:1494
#define LVIF_PARAM
Definition: commctrl.h:2307
#define LVIF_STATE
Definition: commctrl.h:2308
#define memset(x, y, z)
Definition: compat.h:39
#define RegEnumValue
Definition: winreg.h:511
#define REG_SZ
Definition: layer.c:22

Referenced by OnInitEnvironmentDialog().

◆ GetSelectedListViewItem()

static INT GetSelectedListViewItem ( HWND  hwndListView)
static

Definition at line 22 of file environment.c.

23 {
24  INT iCount;
25  INT iItem;
26 
27  iCount = SendMessage(hwndListView,
29  0,
30  0);
31  if (iCount != LB_ERR)
32  {
33  for (iItem = 0; iItem < iCount; iItem++)
34  {
37  iItem,
39  {
40  return iItem;
41  }
42  }
43  }
44 
45  return -1;
46 }
#define LVM_GETITEMSTATE
Definition: commctrl.h:2671
int32_t INT
Definition: typedefs.h:56
#define LB_ERR
Definition: winuser.h:2407
#define LVM_GETITEMCOUNT
Definition: commctrl.h:2302
HWND hwndListView
Definition: eventvwr.c:83
#define LVIS_SELECTED
Definition: commctrl.h:2315
LONG_PTR LPARAM
Definition: windef.h:208
#define SendMessage
Definition: winuser.h:5818

Referenced by OnDeleteVariable(), and OnEditVariable().

◆ OnDeleteVariable()

static VOID OnDeleteVariable ( HWND  hwndDlg,
INT  iDlgItem 
)
static

Definition at line 427 of file environment.c.

429 {
431  PVARIABLE_DATA VarData;
432  LV_ITEM lvi;
433  INT iItem;
434 
435  hwndListView = GetDlgItem(hwndDlg, iDlgItem);
436 
438  if (iItem != -1)
439  {
440  memset(&lvi, 0x00, sizeof(lvi));
441  lvi.mask = LVIF_PARAM;
442  lvi.iItem = iItem;
443 
444  if (ListView_GetItem(hwndListView, &lvi))
445  {
446  VarData = (PVARIABLE_DATA)lvi.lParam;
447  if (VarData != NULL)
448  {
449  if (VarData->lpName != NULL)
450  GlobalFree(VarData->lpName);
451 
452  if (VarData->lpRawValue != NULL)
453  GlobalFree(VarData->lpRawValue);
454 
455  if (VarData->lpCookedValue != NULL)
456  GlobalFree(VarData->lpCookedValue);
457 
458  GlobalFree(VarData);
459  lvi.lParam = 0;
460  }
461  }
462 
464 
465  /* Select the previous item */
466  if (iItem > 0)
467  iItem--;
468 
472  }
473 }
#define LV_ITEM
Definition: commctrl.h:2333
struct png_info_def **typedef void(__cdecl typeof(png_destroy_read_struct))(struct png_struct_def **
Definition: typeof.h:49
LPTSTR lpCookedValue
Definition: environment.c:17
LPTSTR lpRawValue
Definition: environment.c:16
int32_t INT
Definition: typedefs.h:56
#define ListView_SetItemState(hwndLV, i, data, mask)
Definition: commctrl.h:2669
HWND hwndListView
Definition: eventvwr.c:83
smooth NULL
Definition: ftsmooth.c:416
#define LVIS_SELECTED
Definition: commctrl.h:2315
#define ListView_DeleteItem(hwnd, i)
Definition: commctrl.h:2407
if(!(yy_init))
Definition: macro.lex.yy.c:714
HWND WINAPI GetDlgItem(_In_opt_ HWND, _In_ int)
HGLOBAL NTAPI GlobalFree(HGLOBAL hMem)
Definition: heapmem.c:611
static INT GetSelectedListViewItem(HWND hwndListView)
Definition: environment.c:22
struct _VARIABLE_DATA * PVARIABLE_DATA
#define ListView_GetItem(hwnd, pitem)
Definition: commctrl.h:2390
#define LVIF_PARAM
Definition: commctrl.h:2307
#define memset(x, y, z)
Definition: compat.h:39
#define LVIS_FOCUSED
Definition: commctrl.h:2314

Referenced by EnvironmentDlgProc(), and OnNotify().

◆ OnEditVariable()

static VOID OnEditVariable ( HWND  hwndDlg,
INT  iDlgItem 
)
static

Definition at line 391 of file environment.c.

393 {
395  PVARIABLE_DATA VarData;
396  LV_ITEM lvi;
397  INT iItem;
398 
399  hwndListView = GetDlgItem(hwndDlg, iDlgItem);
400 
402  if (iItem != -1)
403  {
404  memset(&lvi, 0x00, sizeof(lvi));
405  lvi.mask = LVIF_PARAM;
406  lvi.iItem = iItem;
407 
408  if (ListView_GetItem(hwndListView, &lvi))
409  {
410  VarData = (PVARIABLE_DATA)lvi.lParam;
411 
414  hwndDlg,
416  (LPARAM)VarData) > 0)
417  {
418  ListView_SetItemText(hwndListView, iItem, 0, VarData->lpName);
419  ListView_SetItemText(hwndListView, iItem, 1, VarData->lpCookedValue);
420  }
421  }
422  }
423 }
#define LV_ITEM
Definition: commctrl.h:2333
#define MAKEINTRESOURCE
Definition: winuser.h:591
HINSTANCE hApplet
Definition: access.c:17
int32_t INT
Definition: typedefs.h:56
HWND hwndListView
Definition: eventvwr.c:83
LONG_PTR LPARAM
Definition: windef.h:208
#define ListView_SetItemText(hwndLV, i, iSubItem_, pszText_)
Definition: commctrl.h:2687
if(!(yy_init))
Definition: macro.lex.yy.c:714
HWND WINAPI GetDlgItem(_In_opt_ HWND, _In_ int)
static INT GetSelectedListViewItem(HWND hwndListView)
Definition: environment.c:22
#define DialogBoxParam
Definition: winuser.h:5739
struct _VARIABLE_DATA * PVARIABLE_DATA
#define IDD_EDIT_VARIABLE
Definition: resource.h:133
#define ListView_GetItem(hwnd, pitem)
Definition: commctrl.h:2390
#define LVIF_PARAM
Definition: commctrl.h:2307
static INT_PTR CALLBACK EditVariableDlgProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
Definition: environment.c:50
#define memset(x, y, z)
Definition: compat.h:39

Referenced by EnvironmentDlgProc(), and OnNotify().

◆ OnInitEnvironmentDialog()

static VOID OnInitEnvironmentDialog ( HWND  hwndDlg)
static

Definition at line 299 of file environment.c.

300 {
302 
303  /* Set user environment variables */
305 
307 
309 
312  _T("Environment"));
313 
315 
319 
321 
322  /* Set system environment variables */
324 
326 
328 
331  _T("SYSTEM\\CurrentControlSet\\Control\\Session Manager\\Environment"));
332 
334 
338 
340 }
struct png_info_def **typedef void(__cdecl typeof(png_destroy_read_struct))(struct png_struct_def **
Definition: typeof.h:49
#define IDC_USER_VARIABLE_LIST
Definition: resource.h:123
#define HKEY_CURRENT_USER
Definition: winreg.h:11
#define LVS_EX_FULLROWSELECT
Definition: commctrl.h:2730
#define ListView_SetColumnWidth(hwnd, iCol, cx)
Definition: commctrl.h:2644
#define ListView_SetItemState(hwndLV, i, data, mask)
Definition: commctrl.h:2669
HWND hwndListView
Definition: eventvwr.c:83
#define LVIS_SELECTED
Definition: commctrl.h:2315
#define _T(x)
Definition: vfdio.h:22
HWND WINAPI GetDlgItem(_In_opt_ HWND, _In_ int)
#define ListView_SetExtendedListViewStyle(hwndLV, dw)
Definition: commctrl.h:2721
static VOID SetEnvironmentDialogListViewColumns(HWND hwndListView)
Definition: environment.c:273
#define LVSCW_AUTOSIZE_USEHEADER
Definition: commctrl.h:2641
static VOID GetEnvironmentVariables(HWND hwndListView, HKEY hRootKey, LPTSTR lpSubKeyName)
Definition: environment.c:148
#define ListView_Update(hwndLV, i)
Definition: commctrl.h:2667
#define IDC_SYSTEM_VARIABLE_LIST
Definition: resource.h:127
#define LVIS_FOCUSED
Definition: commctrl.h:2314
#define HKEY_LOCAL_MACHINE
Definition: winreg.h:12

Referenced by EnvironmentDlgProc().

◆ OnNewVariable()

static VOID OnNewVariable ( HWND  hwndDlg,
INT  iDlgItem 
)
static

Definition at line 344 of file environment.c.

346 {
348  PVARIABLE_DATA VarData;
349  LV_ITEM lvi;
350  INT iItem;
351 
352  hwndListView = GetDlgItem(hwndDlg, iDlgItem);
353 
354  VarData = GlobalAlloc(GPTR, sizeof(VARIABLE_DATA));
355 
358  hwndDlg,
360  (LPARAM)VarData) <= 0)
361  {
362  if (VarData->lpName != NULL)
363  GlobalFree(VarData->lpName);
364 
365  if (VarData->lpRawValue != NULL)
366  GlobalFree(VarData->lpRawValue);
367 
368  if (VarData->lpCookedValue != NULL)
369  GlobalFree(VarData->lpCookedValue);
370 
371  GlobalFree(VarData);
372  }
373  else
374  {
375  if (VarData->lpName != NULL && (VarData->lpCookedValue || VarData->lpRawValue))
376  {
377  memset(&lvi, 0x00, sizeof(lvi));
378  lvi.mask = LVIF_TEXT | LVIF_STATE | LVIF_PARAM;
379  lvi.lParam = (LPARAM)VarData;
380  lvi.pszText = VarData->lpName;
381  lvi.state = 0;
382  iItem = ListView_InsertItem(hwndListView, &lvi);
383 
384  ListView_SetItemText(hwndListView, iItem, 1, VarData->lpCookedValue);
385  }
386  }
387 }
#define LV_ITEM
Definition: commctrl.h:2333
#define MAKEINTRESOURCE
Definition: winuser.h:591
HGLOBAL NTAPI GlobalAlloc(UINT uFlags, SIZE_T dwBytes)
Definition: heapmem.c:368
#define GPTR
Definition: winbase.h:293
HINSTANCE hApplet
Definition: access.c:17
#define ListView_InsertItem(hwnd, pitem)
Definition: commctrl.h:2404
int32_t INT
Definition: typedefs.h:56
#define LVIF_TEXT
Definition: commctrl.h:2305
HWND hwndListView
Definition: eventvwr.c:83
smooth NULL
Definition: ftsmooth.c:416
LONG_PTR LPARAM
Definition: windef.h:208
#define ListView_SetItemText(hwndLV, i, iSubItem_, pszText_)
Definition: commctrl.h:2687
HWND WINAPI GetDlgItem(_In_opt_ HWND, _In_ int)
HGLOBAL NTAPI GlobalFree(HGLOBAL hMem)
Definition: heapmem.c:611
#define DialogBoxParam
Definition: winuser.h:5739
#define IDD_EDIT_VARIABLE
Definition: resource.h:133
#define LVIF_PARAM
Definition: commctrl.h:2307
static INT_PTR CALLBACK EditVariableDlgProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
Definition: environment.c:50
#define LVIF_STATE
Definition: commctrl.h:2308
#define memset(x, y, z)
Definition: compat.h:39

Referenced by EnvironmentDlgProc().

◆ OnNotify()

static BOOL OnNotify ( HWND  hwndDlg,
NMHDR phdr 
)
static

Definition at line 655 of file environment.c.

656 {
657  switch(phdr->code)
658  {
659  case NM_DBLCLK:
660  if (phdr->idFrom == IDC_USER_VARIABLE_LIST ||
662  {
663  OnEditVariable(hwndDlg, (INT)phdr->idFrom);
664  return TRUE;
665  }
666  break;
667 
668  case LVN_KEYDOWN:
669  if (((LPNMLVKEYDOWN)phdr)->wVKey == VK_DELETE &&
670  (phdr->idFrom == IDC_USER_VARIABLE_LIST ||
671  phdr->idFrom == IDC_SYSTEM_VARIABLE_LIST))
672  {
673  OnDeleteVariable(hwndDlg, (INT)phdr->idFrom);
674  return TRUE;
675  }
676  break;
677  }
678 
679  return FALSE;
680 }
#define TRUE
Definition: types.h:120
#define IDC_USER_VARIABLE_LIST
Definition: resource.h:123
int32_t INT
Definition: typedefs.h:56
UINT code
Definition: winuser.h:3134
static VOID OnEditVariable(HWND hwndDlg, INT iDlgItem)
Definition: environment.c:391
#define LVN_KEYDOWN
Definition: commctrl.h:3180
UINT_PTR idFrom
Definition: winuser.h:3133
#define VK_DELETE
Definition: winuser.h:2208
#define NM_DBLCLK
Definition: commctrl.h:131
static VOID OnDeleteVariable(HWND hwndDlg, INT iDlgItem)
Definition: environment.c:427
#define IDC_SYSTEM_VARIABLE_LIST
Definition: resource.h:127

Referenced by EnvironmentDlgProc().

◆ ReleaseListViewItems()

static VOID ReleaseListViewItems ( HWND  hwndDlg,
INT  iDlgItem 
)
static

Definition at line 477 of file environment.c.

479 {
481  PVARIABLE_DATA VarData;
482  LV_ITEM lvi;
483  INT nItemCount;
484  INT i;
485 
486  hwndListView = GetDlgItem(hwndDlg, iDlgItem);
487 
488  memset(&lvi, 0x00, sizeof(lvi));
489 
490  nItemCount = ListView_GetItemCount(hwndListView);
491  for (i = 0; i < nItemCount; i++)
492  {
493  lvi.mask = LVIF_PARAM;
494  lvi.iItem = i;
495 
496  if (ListView_GetItem(hwndListView, &lvi))
497  {
498  VarData = (PVARIABLE_DATA)lvi.lParam;
499  if (VarData != NULL)
500  {
501  if (VarData->lpName != NULL)
502  GlobalFree(VarData->lpName);
503 
504  if (VarData->lpRawValue != NULL)
505  GlobalFree(VarData->lpRawValue);
506 
507  if (VarData->lpCookedValue != NULL)
508  GlobalFree(VarData->lpCookedValue);
509 
510  GlobalFree(VarData);
511  lvi.lParam = 0;
512  }
513  }
514  }
515 }
#define LV_ITEM
Definition: commctrl.h:2333
LPTSTR lpCookedValue
Definition: environment.c:17
LPTSTR lpRawValue
Definition: environment.c:16
int32_t INT
Definition: typedefs.h:56
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
HWND hwndListView
Definition: eventvwr.c:83
smooth NULL
Definition: ftsmooth.c:416
#define ListView_GetItemCount(hwnd)
Definition: commctrl.h:2303
if(!(yy_init))
Definition: macro.lex.yy.c:714
HWND WINAPI GetDlgItem(_In_opt_ HWND, _In_ int)
HGLOBAL NTAPI GlobalFree(HGLOBAL hMem)
Definition: heapmem.c:611
struct _VARIABLE_DATA * PVARIABLE_DATA
#define ListView_GetItem(hwnd, pitem)
Definition: commctrl.h:2390
#define LVIF_PARAM
Definition: commctrl.h:2307
#define memset(x, y, z)
Definition: compat.h:39

Referenced by EnvironmentDlgProc().

◆ SetAllVars()

static VOID SetAllVars ( HWND  hwndDlg,
INT  iDlgItem 
)
static

Definition at line 519 of file environment.c.

521 {
523  PVARIABLE_DATA VarData;
524  LV_ITEM lvi;
525  INT iItem;
526  HKEY hKey;
527  DWORD dwValueCount;
528  DWORD dwMaxValueNameLength;
529  LPTSTR *aValueArray;
530  DWORD dwNameLength;
531  DWORD i;
532  TCHAR szBuffer[256];
534 
535  memset(&lvi, 0x00, sizeof(lvi));
536 
537  /* Get the handle to the list box with all system vars in it */
538  hwndListView = GetDlgItem(hwndDlg, iDlgItem);
539  /* First item is 0 */
540  iItem = 0;
541  /* Set up struct to retrieve item */
542  lvi.mask = LVIF_PARAM;
543  lvi.iItem = iItem;
544 
545  /* Open or create the key */
547  (iDlgItem == IDC_SYSTEM_VARIABLE_LIST ? _T("SYSTEM\\CurrentControlSet\\Control\\Session Manager\\Environment") : _T("Environment")),
548  0,
549  NULL,
552  NULL,
553  &hKey,
554  NULL))
555  {
556  return;
557  }
558 
559  /* Get the number of values and the maximum value name length */
560  if (RegQueryInfoKey(hKey,
561  NULL,
562  NULL,
563  NULL,
564  NULL,
565  NULL,
566  NULL,
567  &dwValueCount,
568  &dwMaxValueNameLength,
569  NULL,
570  NULL,
571  NULL))
572  {
573  RegCloseKey(hKey);
574  return;
575  }
576 
577  if (dwValueCount > 0)
578  {
579  /* Allocate the value array */
580  aValueArray = GlobalAlloc(GPTR, dwValueCount * sizeof(LPTSTR));
581  if (aValueArray != NULL)
582  {
583  /* Get all value names */
584  for (i = 0; i < dwValueCount; i++)
585  {
586  dwNameLength = 256;
587  if (!RegEnumValue(hKey,
588  i,
589  szBuffer,
590  &dwNameLength,
591  NULL,
592  NULL,
593  NULL,
594  NULL))
595  {
596  /* Allocate a value name buffer, fill it and attach it to the array */
597  lpBuffer = (LPTSTR)GlobalAlloc(GPTR, (dwNameLength + 1) * sizeof(TCHAR));
598  if (lpBuffer != NULL)
599  {
600  _tcscpy(lpBuffer, szBuffer);
601  aValueArray[i] = lpBuffer;
602  }
603  }
604  }
605 
606  /* Delete all values */
607  for (i = 0; i < dwValueCount; i++)
608  {
609  if (aValueArray[i] != NULL)
610  {
611  /* Delete the value */
612  RegDeleteValue(hKey,
613  aValueArray[i]);
614 
615  /* Free the value name */
616  GlobalFree(aValueArray[i]);
617  }
618  }
619 
620  /* Free the value array */
621  GlobalFree(aValueArray);
622  }
623  }
624 
625  /* Loop through all variables */
626  while (ListView_GetItem(hwndListView, &lvi))
627  {
628  /* Get the data in each item */
629  VarData = (PVARIABLE_DATA)lvi.lParam;
630  if (VarData != NULL)
631  {
632  /* Set the new value */
633  if (RegSetValueEx(hKey,
634  VarData->lpName,
635  0,
636  VarData->dwType,
637  (LPBYTE)VarData->lpRawValue,
638  (DWORD)(_tcslen(VarData->lpRawValue) + 1) * sizeof(TCHAR)))
639  {
640  RegCloseKey(hKey);
641  return;
642  }
643  }
644 
645  /* Fill struct for next item */
646  lvi.mask = LVIF_PARAM;
647  lvi.iItem = ++iItem;
648  }
649 
650  RegCloseKey(hKey);
651 }
#define LV_ITEM
Definition: commctrl.h:2333
HGLOBAL NTAPI GlobalAlloc(UINT uFlags, SIZE_T dwBytes)
Definition: heapmem.c:368
#define RegQueryInfoKey
Definition: winreg.h:521
#define GPTR
Definition: winbase.h:293
#define KEY_READ
Definition: nt_native.h:1023
#define HKEY_CURRENT_USER
Definition: winreg.h:11
LPTSTR lpRawValue
Definition: environment.c:16
_TCHAR * _tcscpy(_TCHAR *to, const _TCHAR *from)
Definition: tcscpy.h:8
int32_t INT
Definition: typedefs.h:56
CHAR * LPTSTR
Definition: xmlstorage.h:192
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
LONG WINAPI RegCloseKey(HKEY hKey)
Definition: reg.c:423
unsigned char * LPBYTE
Definition: typedefs.h:52
static TAGREF LPCWSTR LPDWORD LPVOID lpBuffer
Definition: db.cpp:173
size_t __cdecl _tcslen(const _TCHAR *str)
Definition: tcslen.h:9
HWND hwndListView
Definition: eventvwr.c:83
smooth NULL
Definition: ftsmooth.c:416
#define REG_OPTION_NON_VOLATILE
Definition: nt_native.h:1057
#define KEY_WRITE
Definition: nt_native.h:1031
char TCHAR
Definition: xmlstorage.h:189
#define RegDeleteValue
Definition: winreg.h:508
#define _T(x)
Definition: vfdio.h:22
if(!(yy_init))
Definition: macro.lex.yy.c:714
HWND WINAPI GetDlgItem(_In_opt_ HWND, _In_ int)
unsigned long DWORD
Definition: ntddk_ex.h:95
HGLOBAL NTAPI GlobalFree(HGLOBAL hMem)
Definition: heapmem.c:611
struct _VARIABLE_DATA * PVARIABLE_DATA
#define ListView_GetItem(hwnd, pitem)
Definition: commctrl.h:2390
#define LVIF_PARAM
Definition: commctrl.h:2307
#define memset(x, y, z)
Definition: compat.h:39
#define RegEnumValue
Definition: winreg.h:511
#define RegSetValueEx
Definition: winreg.h:533
#define RegCreateKeyEx
Definition: winreg.h:501
#define IDC_SYSTEM_VARIABLE_LIST
Definition: resource.h:127
#define HKEY_LOCAL_MACHINE
Definition: winreg.h:12

Referenced by EnvironmentDlgProc().

◆ SetEnvironmentDialogListViewColumns()

static VOID SetEnvironmentDialogListViewColumns ( HWND  hwndListView)
static

Definition at line 273 of file environment.c.

274 {
275  RECT rect;
277  TCHAR szStr[32];
278 
280 
281  memset(&column, 0x00, sizeof(column));
283  column.fmt=LVCFMT_LEFT;
284  column.cx = (INT)((rect.right - rect.left) * 0.32);
285  column.iSubItem = 0;
286  LoadString(hApplet, IDS_VARIABLE, szStr, sizeof(szStr) / sizeof(szStr[0]));
287  column.pszText = szStr;
289 
290  column.cx = (INT)((rect.right - rect.left) * 0.63);
291  column.iSubItem = 1;
292  LoadString(hApplet, IDS_VALUE, szStr, sizeof(szStr) / sizeof(szStr[0]));
293  column.pszText = szStr;
295 }
struct png_info_def **typedef void(__cdecl typeof(png_destroy_read_struct))(struct png_struct_def **
Definition: typeof.h:49
#define LVCF_WIDTH
Definition: commctrl.h:2583
#define LVCF_TEXT
Definition: commctrl.h:2584
#define LV_COLUMN
Definition: commctrl.h:2543
#define INT
Definition: polytest.cpp:20
#define LVCFMT_LEFT
Definition: commctrl.h:2594
HINSTANCE hApplet
Definition: access.c:17
& rect
Definition: startmenu.cpp:1413
#define LVCF_SUBITEM
Definition: commctrl.h:2585
#define ListView_InsertColumn(hwnd, iCol, pcol)
Definition: commctrl.h:2632
HWND hwndListView
Definition: eventvwr.c:83
char TCHAR
Definition: xmlstorage.h:189
#define IDS_VALUE
Definition: resource.h:25
BOOL WINAPI GetClientRect(_In_ HWND, _Out_ LPRECT)
#define LVCF_FMT
Definition: commctrl.h:2582
#define IDS_VARIABLE
Definition: resource.h:24
GLenum GLenum GLvoid GLvoid * column
Definition: glext.h:5664
#define memset(x, y, z)
Definition: compat.h:39
#define LoadString
Definition: winuser.h:5794

Referenced by OnInitEnvironmentDialog().