ReactOS  0.4.14-dev-98-gb0d4763
general.c
Go to the documentation of this file.
1 #include "openglcfg.h"
2 
3 #include <winreg.h>
4 #include <debug.h>
5 
7 static DWORD dwNumDrivers = 0;
8 
9 static VOID InitSettings(HWND hWndDlg)
10 {
11  HKEY hKeyRenderer;
12  HKEY hKeyDrivers;
13  WCHAR szBuffer[MAX_KEY_LENGTH];
14  WCHAR szBultin[MAX_KEY_LENGTH];
15  WCHAR szDriver[MAX_KEY_LENGTH];
16  DWORD dwType = 0;
18 
20  return;
21 
23  {
24  RegCloseKey(hKeyDrivers);
25  return;
26  }
27 
28  LoadString(hApplet, IDS_DEBUG_DNM, (LPTSTR)szBultin, 127);
30 
31  LoadString(hApplet, IDS_DEBUG_SET, (LPTSTR)szBultin, 127);
33 
34  LoadString(hApplet, IDS_DEBUG_CLEAR, (LPTSTR)szBultin, 127);
36 
38 
40  SendDlgItemMessageW(hWndDlg, IDC_RENDERER, CB_ADDSTRING, 0, (LPARAM)szBultin);
41 
42  LoadString(hApplet, IDS_RENDERER_RSWR, (LPTSTR)szBultin, 127);
43  SendDlgItemMessageW(hWndDlg, IDC_RENDERER, CB_ADDSTRING, 0, (LPARAM)szBultin);
44 
45  if (RegQueryValueExW(hKeyRenderer, NULL, NULL, &dwType, (LPBYTE)szDriver, &dwSize) != ERROR_SUCCESS || dwSize == sizeof(WCHAR))
47 
48  if (dwType == REG_SZ)
49  {
50  DWORD ret;
51  INT iKey;
52 
53  if (wcsncmp(szBultin, szDriver, MAX_KEY_LENGTH) == 0)
55 
57 
58  if (ret != ERROR_SUCCESS || dwNumDrivers <= 0)
59  {
60  RegCloseKey(hKeyDrivers);
61  RegCloseKey(hKeyRenderer);
62  return;
63  }
64 
66 
67  if (!pOglDrivers)
68  dwNumDrivers = 0;
69 
70  for (iKey = 0; iKey < dwNumDrivers; iKey++)
71  {
73  ret = RegEnumKeyEx(hKeyDrivers, iKey, szBuffer, &dwSize, NULL, NULL, NULL, NULL);
74 
75  if (ret != ERROR_SUCCESS)
76  break;
77 
78  /* Mind the null terminator */
79  dwSize++;
80 
81  pOglDrivers[iKey] = HeapAlloc(GetProcessHeap(), 0, dwSize * sizeof(WCHAR));
82 
83  if (!pOglDrivers[iKey])
84  break;
85 
86  SendDlgItemMessageW(hWndDlg, IDC_RENDERER, CB_ADDSTRING, 0, (LPARAM)szBuffer);
87 
88  StringCchCopy(pOglDrivers[iKey], dwSize, szBuffer);
89 
90  if (wcsncmp(szBuffer, szDriver, MAX_KEY_LENGTH) == 0)
91  SendDlgItemMessageW(hWndDlg, IDC_RENDERER, CB_SETCURSEL, iKey + 2, 0);
92  }
93  }
94 
95  RegCloseKey(hKeyDrivers);
96  RegCloseKey(hKeyRenderer);
97 
98  return;
99 }
100 
101 static VOID SaveSettings(HWND hWndDlg)
102 {
103  HKEY hKeyRenderer;
104  HKEY hKeyDebug;
105  INT iSel = 0;
106 
108  return;
109 
111  {
112  iSel = (INT)SendDlgItemMessageW(hWndDlg, IDC_DEBUG_OUTPUT, CB_GETCURSEL, 0, 0);
113 
114  switch (iSel)
115  {
116  case DEBUG_SET:
117  RegSetValueExW(hKeyDebug, L"DEBUGCHANNEL", 0, REG_SZ, (PBYTE)L"+opengl,+wgl", 13 * sizeof(WCHAR));
118  break;
119 
120  case DEBUG_CLEAR:
121  RegSetValueExW(hKeyDebug, L"DEBUGCHANNEL", 0, REG_SZ, (PBYTE)L"", sizeof(WCHAR));
122  break;
123  }
124  RegCloseKey(hKeyDebug);
125  }
126 
127  iSel = (INT)SendDlgItemMessageW(hWndDlg, IDC_RENDERER, CB_GETCURSEL, 0, 0);
128 
129  switch (iSel)
130  {
131  case CB_ERR:
132  break;
133 
134  case RENDERER_DEFAULT:
135  RegSetValueExW(hKeyRenderer, L"", 0, REG_SZ, (PBYTE)L"", sizeof(WCHAR));
136  break;
137 
138  case RENDERER_RSWR:
139  {
140  WCHAR szBuffer[MAX_KEY_LENGTH];
141  LoadString(hApplet, IDS_RENDERER_RSWR, (LPTSTR)szBuffer, 127);
142  RegSetValueExW(hKeyRenderer, L"", 0, REG_SZ, (PBYTE)szBuffer, (wcslen(szBuffer) + 1) * sizeof(WCHAR));
143  break;
144  }
145 
146  default:
147  {
148  /* Adjustment for DEFAULT and RSWR renderers */
149  iSel -= 2;
150 
151  if (iSel >= 0 && iSel <= dwNumDrivers)
152  RegSetValueExW(hKeyRenderer, L"", 0, REG_SZ, (PBYTE)pOglDrivers[iSel], (wcslen(pOglDrivers[iSel]) + 1) * sizeof(WCHAR));
153 
154  break;
155  }
156  }
157 
158  RegCloseKey(hKeyRenderer);
159 }
160 
161 
163 {
164  LPPSHNOTIFY lppsn;
165 
166  switch (uMsg)
167  {
168  case WM_INITDIALOG:
169  InitSettings(hWndDlg);
170  return TRUE;
171 
172  case WM_COMMAND:
173  if (LOWORD(wParam) == IDC_RENDERER ||
175  {
176  if (HIWORD(wParam) == CBN_SELCHANGE)
177  {
178  PropSheet_Changed(GetParent(hWndDlg), hWndDlg);
179  }
180  }
181  break;
182 
183  case WM_NOTIFY:
184  lppsn = (LPPSHNOTIFY)lParam;
185  if (lppsn->hdr.code == PSN_APPLY)
186  {
187  SaveSettings(hWndDlg);
188  return TRUE;
189  }
190  break;
191 
192  case WM_DESTROY:
193  if (pOglDrivers != NULL)
194  {
195  INT iKey;
196  for (iKey = 0; iKey <= dwNumDrivers; iKey++)
197  HeapFree(GetProcessHeap(), 0, pOglDrivers[iKey]);
198 
200  }
201  }
202 
203  return FALSE;
204 }
#define MAXIMUM_ALLOWED
Definition: nt_native.h:83
#define RENDERER_DEFAULT
Definition: openglcfg.h:16
#define TRUE
Definition: types.h:120
#define ERROR_SUCCESS
Definition: deptool.c:10
static PWCHAR * pOglDrivers
Definition: general.c:6
struct _PSHNOTIFY * LPPSHNOTIFY
#define KEY_READ
Definition: nt_native.h:1023
#define HKEY_CURRENT_USER
Definition: winreg.h:11
#define INT
Definition: polytest.cpp:20
#define CALLBACK
Definition: compat.h:27
#define RENDERER_RSWR
Definition: openglcfg.h:17
HINSTANCE hApplet
Definition: access.c:17
#define IDS_RENDERER_DEFAULT
Definition: resource.h:16
UINT_PTR WPARAM
Definition: windef.h:207
uint16_t * PWCHAR
Definition: typedefs.h:54
#define PSN_APPLY
Definition: prsht.h:117
int32_t INT_PTR
Definition: typedefs.h:62
int32_t INT
Definition: typedefs.h:56
#define CB_GETCURSEL
Definition: winuser.h:1925
WPARAM wParam
Definition: combotst.c:138
CHAR * LPTSTR
Definition: xmlstorage.h:192
LONG WINAPI RegCreateKeyExW(_In_ HKEY hKey, _In_ LPCWSTR lpSubKey, _In_ DWORD Reserved, _In_opt_ LPWSTR lpClass, _In_ DWORD dwOptions, _In_ REGSAM samDesired, _In_opt_ LPSECURITY_ATTRIBUTES lpSecurityAttributes, _Out_ PHKEY phkResult, _Out_opt_ LPDWORD lpdwDisposition)
Definition: reg.c:1091
UINT code
Definition: winuser.h:3133
#define MAX_KEY_LENGTH
NMHDR hdr
Definition: prsht.h:312
#define IDS_DEBUG_SET
Definition: resource.h:18
LONG WINAPI RegCloseKey(HKEY hKey)
Definition: reg.c:423
unsigned char * LPBYTE
Definition: typedefs.h:52
#define DEBUG_CLEAR
Definition: openglcfg.h:20
#define CB_ADDSTRING
Definition: winuser.h:1918
static VOID InitSettings(HWND hWndDlg)
Definition: general.c:9
smooth NULL
Definition: ftsmooth.c:416
LONG_PTR LPARAM
Definition: windef.h:208
#define DEBUG_SET
Definition: openglcfg.h:19
INT_PTR CALLBACK GeneralPageProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
Definition: general.c:173
#define CB_ERR
Definition: winuser.h:2410
#define WM_DESTROY
Definition: winuser.h:1591
#define IDC_RENDERER
Definition: resource.h:10
#define IDS_DEBUG_DNM
Definition: resource.h:20
#define KEY_DEBUG_CHANNEL
Definition: openglcfg.h:24
#define KEY_WRITE
Definition: nt_native.h:1031
LONG WINAPI RegSetValueExW(_In_ HKEY hKey, _In_ LPCWSTR lpValueName, _In_ DWORD Reserved, _In_ DWORD dwType, _In_ CONST BYTE *lpData, _In_ DWORD cbData)
Definition: reg.c:4895
static DWORD dwNumDrivers
Definition: general.c:7
#define GetProcessHeap()
Definition: compat.h:395
PVOID WINAPI HeapAlloc(HANDLE, DWORD, SIZE_T)
LONG WINAPI RegQueryValueExW(_In_ HKEY hkeyorg, _In_ LPCWSTR name, _In_ LPDWORD reserved, _In_ LPDWORD type, _In_ LPBYTE data, _In_ LPDWORD count)
Definition: reg.c:4116
__wchar_t WCHAR
Definition: xmlstorage.h:180
#define PropSheet_Changed(d, w)
Definition: prsht.h:326
#define IDC_DEBUG_OUTPUT
Definition: resource.h:11
unsigned long DWORD
Definition: ntddk_ex.h:95
LRESULT WINAPI SendDlgItemMessageW(_In_ HWND, _In_ int, _In_ UINT, _In_ WPARAM, _In_ LPARAM)
_Check_return_ _CRTIMP int __cdecl wcsncmp(_In_reads_or_z_(_MaxCount) const wchar_t *_Str1, _In_reads_or_z_(_MaxCount) const wchar_t *_Str2, _In_ size_t _MaxCount)
LONG WINAPI RegQueryInfoKeyW(HKEY hKey, LPWSTR lpClass, LPDWORD lpcClass, LPDWORD lpReserved, LPDWORD lpcSubKeys, LPDWORD lpcMaxSubKeyLen, LPDWORD lpcMaxClassLen, LPDWORD lpcValues, LPDWORD lpcMaxValueNameLen, LPDWORD lpcMaxValueLen, LPDWORD lpcbSecurityDescriptor, PFILETIME lpftLastWriteTime)
Definition: reg.c:3686
#define IDS_RENDERER_RSWR
Definition: resource.h:17
int ret
static const WCHAR L[]
Definition: oid.c:1250
#define StringCchCopy
Definition: strsafe.h:139
#define CB_SETCURSEL
Definition: winuser.h:1943
#define WM_COMMAND
Definition: winuser.h:1722
#define RegEnumKeyEx
Definition: winreg.h:510
#define IDS_DEBUG_CLEAR
Definition: resource.h:19
HWND WINAPI GetParent(_In_ HWND)
static VOID SaveSettings(HWND hWndDlg)
Definition: general.c:101
unsigned int UINT
Definition: ndis.h:50
#define CBN_SELCHANGE
Definition: winuser.h:1961
#define KEY_DRIVERS
Definition: openglcfg.h:23
#define KEY_RENDERER
Definition: openglcfg.h:22
#define HIWORD(l)
Definition: typedefs.h:246
LONG WINAPI RegOpenKeyExW(HKEY hKey, LPCWSTR lpSubKey, DWORD ulOptions, REGSAM samDesired, PHKEY phkResult)
Definition: reg.c:3366
BYTE * PBYTE
Definition: pedump.c:66
#define WM_INITDIALOG
Definition: winuser.h:1721
LPARAM lParam
Definition: combotst.c:139
#define LOWORD(l)
Definition: pedump.c:82
size_t __cdecl wcslen(_In_z_ const wchar_t *_Str)
#define HeapFree(x, y, z)
Definition: compat.h:394
PSDBQUERYRESULT_VISTA PVOID DWORD * dwSize
Definition: env.c:54
#define LoadString
Definition: winuser.h:5720
#define WM_NOTIFY
Definition: richedit.h:61
#define HKEY_LOCAL_MACHINE
Definition: winreg.h:12
#define REG_SZ
Definition: layer.c:22