ReactOS  0.4.15-dev-1197-g8081ba9
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  DWORD dwType = 0;
15  WCHAR szBuffer[MAX_KEY_LENGTH];
16  WCHAR szBultin[MAX_KEY_LENGTH];
17  WCHAR szDriver[MAX_KEY_LENGTH];
18 
19  LoadString(hApplet, IDS_DEBUG_DNM, (LPTSTR)szBultin, 127);
21 
22  LoadString(hApplet, IDS_DEBUG_SET, (LPTSTR)szBultin, 127);
24 
25  LoadString(hApplet, IDS_DEBUG_CLEAR, (LPTSTR)szBultin, 127);
27 
29 
31  SendDlgItemMessageW(hWndDlg, IDC_RENDERER, CB_ADDSTRING, 0, (LPARAM)szBultin);
32 
33  LoadString(hApplet, IDS_RENDERER_RSWR, (LPTSTR)szBultin, 127);
34  SendDlgItemMessageW(hWndDlg, IDC_RENDERER, CB_ADDSTRING, 0, (LPARAM)szBultin);
35 
37  return;
38 
39  if (RegQueryValueExW(hKeyRenderer, NULL, NULL, &dwType, (LPBYTE)szDriver, &dwSize) != ERROR_SUCCESS || dwSize == sizeof(WCHAR))
41 
42  RegCloseKey(hKeyRenderer);
43 
44  if (dwType == REG_SZ)
45  {
46  DWORD ret;
47  DWORD iKey;
48 
49  if (wcsncmp(szBultin, szDriver, MAX_KEY_LENGTH) == 0)
51 
53  return;
54 
56 
57  if (ret != ERROR_SUCCESS || dwNumDrivers == 0)
58  {
59  RegCloseKey(hKeyDrivers);
60  return;
61  }
62 
64 
65  if (!pOglDrivers)
66  dwNumDrivers = 0;
67 
68  for (iKey = 0; iKey < dwNumDrivers; iKey++)
69  {
71  ret = RegEnumKeyEx(hKeyDrivers, iKey, szBuffer, &dwSize, NULL, NULL, NULL, NULL);
72 
73  if (ret != ERROR_SUCCESS)
74  break;
75 
76  /* Mind the null terminator */
77  dwSize++;
78 
79  pOglDrivers[iKey] = HeapAlloc(GetProcessHeap(), 0, dwSize * sizeof(WCHAR));
80 
81  if (!pOglDrivers[iKey])
82  break;
83 
84  SendDlgItemMessageW(hWndDlg, IDC_RENDERER, CB_ADDSTRING, 0, (LPARAM)szBuffer);
85 
86  StringCchCopy(pOglDrivers[iKey], dwSize, szBuffer);
87 
88  if (wcsncmp(szBuffer, szDriver, MAX_KEY_LENGTH) == 0)
89  SendDlgItemMessageW(hWndDlg, IDC_RENDERER, CB_SETCURSEL, iKey + 2, 0);
90  }
91 
92  RegCloseKey(hKeyDrivers);
93  }
94 
95  return;
96 }
97 
98 static VOID SaveSettings(HWND hWndDlg)
99 {
100  HKEY hKeyRenderer;
101  HKEY hKeyDebug;
102  INT iSel = 0;
103 
105  return;
106 
108  {
109  iSel = (INT)SendDlgItemMessageW(hWndDlg, IDC_DEBUG_OUTPUT, CB_GETCURSEL, 0, 0);
110 
111  switch (iSel)
112  {
113  case DEBUG_SET:
114  RegSetValueExW(hKeyDebug, L"DEBUGCHANNEL", 0, REG_SZ, (PBYTE)L"+opengl,+wgl", 13 * sizeof(WCHAR));
115  break;
116 
117  case DEBUG_CLEAR:
118  RegSetValueExW(hKeyDebug, L"DEBUGCHANNEL", 0, REG_SZ, (PBYTE)L"", sizeof(WCHAR));
119  break;
120  }
121  RegCloseKey(hKeyDebug);
122  }
123 
124  iSel = (INT)SendDlgItemMessageW(hWndDlg, IDC_RENDERER, CB_GETCURSEL, 0, 0);
125 
126  switch (iSel)
127  {
128  case CB_ERR:
129  break;
130 
131  case RENDERER_DEFAULT:
132  RegSetValueExW(hKeyRenderer, L"", 0, REG_SZ, (PBYTE)L"", sizeof(WCHAR));
133  break;
134 
135  case RENDERER_RSWR:
136  {
137  WCHAR szBuffer[MAX_KEY_LENGTH];
138  LoadString(hApplet, IDS_RENDERER_RSWR, (LPTSTR)szBuffer, 127);
139  RegSetValueExW(hKeyRenderer, L"", 0, REG_SZ, (PBYTE)szBuffer, (DWORD)((wcslen(szBuffer) + 1) * sizeof(WCHAR)));
140  break;
141  }
142 
143  default:
144  {
145  /* Adjustment for DEFAULT and RSWR renderers */
146  iSel -= 2;
147 
148  if (iSel >= 0 && iSel < dwNumDrivers)
149  RegSetValueExW(hKeyRenderer, L"", 0, REG_SZ, (PBYTE)pOglDrivers[iSel], (DWORD)((wcslen(pOglDrivers[iSel]) + 1) * sizeof(WCHAR)));
150 
151  break;
152  }
153  }
154 
155  RegCloseKey(hKeyRenderer);
156 }
157 
158 
160 {
161  LPPSHNOTIFY lppsn;
162 
163  switch (uMsg)
164  {
165  case WM_INITDIALOG:
166  InitSettings(hWndDlg);
167  return TRUE;
168 
169  case WM_COMMAND:
170  if (LOWORD(wParam) == IDC_RENDERER ||
172  {
173  if (HIWORD(wParam) == CBN_SELCHANGE)
174  {
175  PropSheet_Changed(GetParent(hWndDlg), hWndDlg);
176  }
177  }
178  break;
179 
180  case WM_NOTIFY:
181  lppsn = (LPPSHNOTIFY)lParam;
182  if (lppsn->hdr.code == PSN_APPLY)
183  {
184  SaveSettings(hWndDlg);
185  return TRUE;
186  }
187  break;
188 
189  case WM_DESTROY:
190  if (pOglDrivers != NULL)
191  {
192  DWORD iKey;
193 
194  for (iKey = 0; iKey < dwNumDrivers; ++iKey)
195  HeapFree(GetProcessHeap(), 0, pOglDrivers[iKey]);
196 
198  }
199  }
200 
201  return FALSE;
202 }
#define MAXIMUM_ALLOWED
Definition: nt_native.h:83
#define RENDERER_DEFAULT
Definition: openglcfg.h:16
#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 TRUE
Definition: types.h:120
#define HKEY_CURRENT_USER
Definition: winreg.h:11
#define INT
Definition: polytest.cpp:20
#define CALLBACK
Definition: compat.h:35
#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:56
#define PSN_APPLY
Definition: prsht.h:117
int32_t INT_PTR
Definition: typedefs.h:64
int32_t INT
Definition: typedefs.h:58
#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:3134
#define MAX_KEY_LENGTH
NMHDR hdr
Definition: prsht.h:330
#define IDS_DEBUG_SET
Definition: resource.h:18
LONG WINAPI RegCloseKey(HKEY hKey)
Definition: reg.c:423
unsigned char * LPBYTE
Definition: typedefs.h:53
#define FALSE
Definition: types.h:117
#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:484
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:344
#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:98
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:247
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:483
PSDBQUERYRESULT_VISTA PVOID DWORD * dwSize
Definition: env.c:54
#define LoadString
Definition: winuser.h:5794
#define WM_NOTIFY
Definition: richedit.h:61
#define HKEY_LOCAL_MACHINE
Definition: winreg.h:12
#define REG_SZ
Definition: layer.c:22