1 #include "openglcfg.h" 2 3 #include <winreg.h> 4 #include <debug.h> 5 6 static PWCHAR *pOglDrivers = NULL; 7 static DWORD dwNumDrivers = 0; 8 9 static VOID InitSettings(HWND hWndDlg) 10 { 11 HKEY hKeyRenderer; 12 HKEY hKeyDrivers; 13 DWORD dwType = 0; 14 DWORD dwSize = MAX_KEY_LENGTH; 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); 20 SendDlgItemMessageW(hWndDlg, IDC_DEBUG_OUTPUT, CB_ADDSTRING, 0, (LPARAM)szBultin); 21 22 LoadString(hApplet, IDS_DEBUG_SET, (LPTSTR)szBultin, 127); 23 SendDlgItemMessageW(hWndDlg, IDC_DEBUG_OUTPUT, CB_ADDSTRING, 0, (LPARAM)szBultin); 24 25 LoadString(hApplet, IDS_DEBUG_CLEAR, (LPTSTR)szBultin, 127); 26 SendDlgItemMessageW(hWndDlg, IDC_DEBUG_OUTPUT, CB_ADDSTRING, 0, (LPARAM)szBultin); 27 28 SendDlgItemMessageW(hWndDlg, IDC_DEBUG_OUTPUT, CB_SETCURSEL, 0, 0); 29 30 LoadString(hApplet, IDS_RENDERER_DEFAULT, (LPTSTR)szBultin, 127); 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 36 if (RegCreateKeyExW(HKEY_CURRENT_USER, KEY_RENDERER, 0, NULL, 0, MAXIMUM_ALLOWED, NULL, &hKeyRenderer, NULL) != ERROR_SUCCESS) 37 return; 38 39 if (RegQueryValueExW(hKeyRenderer, NULL, NULL, &dwType, (LPBYTE)szDriver, &dwSize) != ERROR_SUCCESS || dwSize == sizeof(WCHAR)) 40 SendDlgItemMessageW(hWndDlg, IDC_RENDERER, CB_SETCURSEL, RENDERER_DEFAULT, 0); 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) 50 SendDlgItemMessageW(hWndDlg, IDC_RENDERER, CB_SETCURSEL, RENDERER_RSWR, 0); 51 52 if (RegOpenKeyExW(HKEY_LOCAL_MACHINE, KEY_DRIVERS, 0, KEY_READ, &hKeyDrivers) != ERROR_SUCCESS) 53 return; 54 55 ret = RegQueryInfoKeyW(hKeyDrivers, NULL, NULL, NULL, &dwNumDrivers, NULL, NULL, NULL, NULL, NULL, NULL, NULL); 56 57 if (ret != ERROR_SUCCESS || dwNumDrivers == 0) 58 { 59 RegCloseKey(hKeyDrivers); 60 return; 61 } 62 63 pOglDrivers = HeapAlloc(GetProcessHeap(), 0, dwNumDrivers * sizeof(PWCHAR)); 64 65 if (!pOglDrivers) 66 dwNumDrivers = 0; 67 68 for (iKey = 0; iKey < dwNumDrivers; iKey++) 69 { 70 dwSize = MAX_KEY_LENGTH; 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 104 if (RegOpenKeyExW(HKEY_CURRENT_USER, KEY_RENDERER, 0, KEY_WRITE, &hKeyRenderer) != ERROR_SUCCESS) 105 return; 106 107 if (RegOpenKeyExW(HKEY_LOCAL_MACHINE, KEY_DEBUG_CHANNEL, 0, KEY_WRITE, &hKeyDebug) == ERROR_SUCCESS) 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 159 INT_PTR CALLBACK GeneralPageProc(HWND hWndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam) 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 || 171 LOWORD(wParam) == IDC_DEBUG_OUTPUT) 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 197 HeapFree(GetProcessHeap(), 0, pOglDrivers); 198 } 199 } 200 201 return FALSE; 202 } 203