Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

770 lines
22 KiB

  1. #include <windows.h>
  2. #include <windowsx.h>
  3. #if WINNT
  4. #else
  5. #include <help.h>
  6. #endif
  7. #include "tchar.h"
  8. #include "prsht.h"
  9. //#define TAPI_API_VERSION 0x00020000
  10. #define TAPI_API_VERSION 0x00010004
  11. #define TAPI_CURRENT_VERSION 0x00010004
  12. #include "tapi.h"
  13. #undef TAPI_CURRENT_VERSION
  14. #define TAPI_CURRENT_VERSION 0x00020000
  15. #include "tspi.h"
  16. #undef TAPI_CURRENT_VERSION
  17. #define TAPI_CURRENT_VERSION 0x00010004
  18. #include "clientr.h"
  19. #include "client.h"
  20. #include "privateold.h"
  21. #include "general.h"
  22. #if DBG
  23. #define InternalDebugOut(_x_) DbgPrt _x_
  24. garbage;
  25. #else
  26. #define InternalDebugOut(_x_)
  27. #endif
  28. //***************************************************************************
  29. TCHAR gszCurrentProfileKey[] = "System\\CurrentControlSet\\Control\\Telephony";
  30. TCHAR gszStaticProfileKey[] = "Config\\%04d\\System\\CurrentControlSet\\Control\\Telephony";
  31. TCHAR gszAutoLaunchKey[] = "Software\\Microsoft\\Windows\\CurrentVersion\\Telephony";
  32. TCHAR gszAutoLaunchValue[] = "AutoLaunchFlags";
  33. TCHAR gszAutoLocationID[] = "AutoLocationID";
  34. UINT gnNumConfigProfiles = 0;
  35. DWORD gdwConfigProfiles[MAX_CONFIGPROFILES];
  36. //***************************************************************************
  37. //***************************************************************************
  38. //***************************************************************************
  39. //Purpose: Gets the appropriately sized translate caps structure
  40. // from TAPI. Return TRUE if successful
  41. #define LOCATION_GROW 4
  42. BOOL GetTranslateCaps(
  43. LPLINETRANSLATECAPS FAR * pptc)
  44. {
  45. LONG lineErr;
  46. LPLINETRANSLATECAPS ptc;
  47. DWORD cbSize;
  48. cbSize = sizeof(*ptc) * LOCATION_GROW + 200;
  49. ptc = (LPLINETRANSLATECAPS)GlobalAllocPtr(GPTR, cbSize);
  50. if (ptc)
  51. {
  52. // Get the translate devcaps
  53. ptc->dwTotalSize = cbSize;
  54. lineErr = lineGetTranslateCaps (0, TAPI_API_VERSION, ptc);
  55. if (LINEERR_STRUCTURETOOSMALL == lineErr ||
  56. ptc->dwNeededSize > ptc->dwTotalSize)
  57. {
  58. // Provided structure was too small, resize and try again
  59. cbSize = ptc->dwNeededSize;
  60. GlobalFreePtr(ptc);
  61. ptc = (LPLINETRANSLATECAPS)GlobalAllocPtr(GPTR, cbSize);
  62. if (ptc)
  63. {
  64. ptc->dwTotalSize = cbSize;
  65. lineErr = lineGetTranslateCaps (0, TAPI_API_VERSION, ptc);
  66. if (0 != lineErr)
  67. {
  68. // Failure
  69. GlobalFreePtr(ptc);
  70. ptc = NULL;
  71. }
  72. }
  73. }
  74. else if (0 != lineErr)
  75. {
  76. // Failure
  77. GlobalFreePtr(ptc);
  78. ptc = NULL;
  79. }
  80. }
  81. *pptc = ptc;
  82. return NULL != *pptc;
  83. }
  84. //***************************************************************************
  85. //***************************************************************************
  86. //***************************************************************************
  87. //
  88. // WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING
  89. // Returns 1 if a problem, 0 if no problem
  90. // Code below assumes that this function ONLY returns 0 or 1 (but I think
  91. // it would be confusing to have the rettype be BOOL, since we want a
  92. // return of '1' on a problem...)
  93. //
  94. LONG FillConfigProfileBox( HWND hWnd,
  95. DWORD dwControl,
  96. LPLINETRANSLATECAPS ptc)
  97. {
  98. UINT n;
  99. DWORD nProfileNumberZ;
  100. WPARAM wIndex;
  101. LINELOCATIONENTRY *ple;
  102. HKEY hKey;
  103. TCHAR szValueName[40];
  104. TCHAR buf[256];
  105. DWORD dwType;
  106. DWORD dwDataSize;
  107. LPSTR lpstrProfileLocation = NULL;
  108. LONG lResult;
  109. //
  110. // Get the zero-based Config Profile Number
  111. //
  112. nProfileNumberZ = dwControl - IDCB_DL_PROFILE1;
  113. //
  114. // Get the profile's name. If this fails, we assume we've run out
  115. // of configs
  116. //
  117. RegOpenKeyEx(
  118. HKEY_LOCAL_MACHINE,
  119. "System\\CurrentControlSet\\Control\\IDConfigDB",
  120. 0,
  121. KEY_ALL_ACCESS,
  122. &hKey
  123. );
  124. wsprintf( szValueName, "FriendlyName%04d", nProfileNumberZ + 1);
  125. dwDataSize = sizeof(buf);
  126. lResult = RegQueryValueEx(
  127. hKey,
  128. szValueName,
  129. 0,
  130. &dwType,
  131. buf,
  132. &dwDataSize
  133. );
  134. RegCloseKey( hKey );
  135. //
  136. // Did we find a name for it?
  137. //
  138. if ( ERROR_SUCCESS != lResult )
  139. {
  140. return (1);
  141. }
  142. //
  143. // Put whatever we found into the field
  144. //
  145. SendMessage( GetDlgItem( hWnd, IDCS_DL_PROFILE1 + nProfileNumberZ ),
  146. WM_SETTEXT,
  147. 0,
  148. (LPARAM)&buf
  149. );
  150. //
  151. // Read what location ID is currently specified for this profile
  152. //
  153. wsprintf( buf, gszStaticProfileKey, nProfileNumberZ + 1);
  154. RegOpenKeyEx(
  155. HKEY_LOCAL_MACHINE,
  156. buf,
  157. 0,
  158. KEY_ALL_ACCESS,
  159. &hKey
  160. );
  161. dwDataSize = sizeof(DWORD);
  162. lResult = RegQueryValueEx(
  163. hKey,
  164. gszAutoLocationID,
  165. 0,
  166. &dwType,
  167. (LPBYTE)&gdwConfigProfiles[ nProfileNumberZ ],
  168. &dwDataSize
  169. );
  170. RegCloseKey( hKey );
  171. //
  172. // If there's no value (maybe it's the first run), use current location
  173. //
  174. if (lResult != ERROR_SUCCESS)
  175. {
  176. gdwConfigProfiles[nProfileNumberZ] = ptc->dwCurrentLocationID;
  177. }
  178. for (n=0; n<ptc->dwNumLocations; n++)
  179. {
  180. ple = (LINELOCATIONENTRY*) ((LPSTR)ptc + ptc->dwLocationListOffset);
  181. wIndex = SendMessage( GetDlgItem(hWnd, dwControl),
  182. CB_ADDSTRING,
  183. 0,
  184. (LPARAM)((LPSTR)ptc + ple[n].dwLocationNameOffset));
  185. SendMessage( GetDlgItem( hWnd, dwControl),
  186. CB_SETITEMDATA,
  187. wIndex,
  188. ple[n].dwPermanentLocationID
  189. );
  190. //{
  191. //// UINT temp;
  192. //
  193. // wsprintf( buf, "prof=%d loop=%d s=%s dw=%ld seek=%ld",
  194. // nProfileNumberZ,
  195. // n,
  196. // (LPARAM)((LPSTR)ptc + ple[n].dwLocationNameOffset),
  197. // (DWORD)ple[n].dwPermanentLocationID,
  198. // (DWORD)gdwConfigProfiles[nProfileNumberZ]);
  199. //
  200. // MessageBox(GetFocus(), buf, "", MB_OK);
  201. //}
  202. //
  203. // If this location is the one this profile wants, select it
  204. //
  205. if ( gdwConfigProfiles[nProfileNumberZ] == ple[n].dwPermanentLocationID )
  206. {
  207. //MessageBox(GetFocus(), "Found profile locationID", "", MB_OK);
  208. lpstrProfileLocation = (LPSTR)((LPSTR)ptc + ple[n].dwLocationNameOffset);
  209. }
  210. }
  211. //{
  212. //// UINT temp;
  213. //
  214. // wsprintf( buf, "profile=%ld loop=%ld s=%s",
  215. // (DWORD)nProfileNumberZ,
  216. // (DWORD)n,
  217. // (LPARAM)((LPSTR)ptc + ple[n].dwLocationNameOffset));
  218. // MessageBox(GetFocus(), buf, "", MB_OK);
  219. //}
  220. SendMessage( GetDlgItem( hWnd, dwControl),
  221. CB_SELECTSTRING,
  222. (WPARAM)-1,
  223. (LPARAM)lpstrProfileLocation
  224. );
  225. return ERROR_SUCCESS;
  226. }
  227. //***************************************************************************
  228. //***************************************************************************
  229. //***************************************************************************
  230. INT_PTR
  231. CALLBACK
  232. GeneralDlgProc(
  233. HWND hWnd,
  234. UINT msg,
  235. WPARAM wParam,
  236. LPARAM lParam
  237. )
  238. {
  239. static DWORD aIds[] = {
  240. 0, 0
  241. };
  242. UINT n;
  243. LONG lResult;
  244. HKEY hKey;
  245. static DWORD dwType;
  246. static DWORD dwDataSize;
  247. static DWORD dwTapiTNAFlags = 0;
  248. // these values are in GENERAL.H
  249. // #define FLAG_AUTOLAUNCH 0x00000001
  250. // #define FLAG_AUTOLOCATIONID 0x00000002
  251. // #define FLAG_PROMPTAUTOLOCATIONID 0x00000004
  252. // #define FLAG_ANNOUNCEAUTOLOCATIONID 0x00000008
  253. LPLINETRANSLATECAPS ptc;
  254. switch (msg)
  255. {
  256. case WM_INITDIALOG:
  257. {
  258. GetTranslateCaps(&ptc);
  259. //BUGBUG What if this fails?
  260. //BUGBUG If the number of hardware configs == 1, don't bother showing these
  261. //
  262. // Fill up the Hardware config boxes
  263. //
  264. if ( ptc )
  265. {
  266. lResult = ERROR_SUCCESS;
  267. for (
  268. n=0;
  269. (n<MAX_CONFIGPROFILES) && (ERROR_SUCCESS == lResult);
  270. n++
  271. )
  272. {
  273. lResult = FillConfigProfileBox( hWnd,
  274. IDCB_DL_PROFILE1 + n,
  275. ptc );
  276. }
  277. gnNumConfigProfiles = n - lResult;
  278. GlobalFreePtr( ptc );
  279. }
  280. //
  281. // Now go disable all the stuff not being used
  282. //
  283. for ( n=gnNumConfigProfiles; n<MAX_CONFIGPROFILES; n++)
  284. {
  285. ShowWindow( GetDlgItem( hWnd, IDCB_DL_PROFILE1 + n),
  286. SW_HIDE
  287. );
  288. ShowWindow( GetDlgItem( hWnd, IDCS_DL_PROFILE1 + n),
  289. SW_HIDE
  290. );
  291. }
  292. //
  293. // Get the TapiTNA flags
  294. //
  295. lResult = RegOpenKeyEx(
  296. HKEY_LOCAL_MACHINE,
  297. gszAutoLaunchKey,
  298. 0,
  299. KEY_ALL_ACCESS,
  300. &hKey
  301. );
  302. dwDataSize = sizeof(dwTapiTNAFlags);
  303. lResult = RegQueryValueEx(
  304. hKey,
  305. gszAutoLaunchValue,
  306. 0,
  307. &dwType,
  308. (LPBYTE)&dwTapiTNAFlags,
  309. &dwDataSize
  310. );
  311. RegCloseKey( hKey );
  312. //
  313. // Now check the boxes as appropriate
  314. //
  315. if ( dwTapiTNAFlags & FLAG_AUTOLAUNCH )
  316. {
  317. CheckDlgButton( hWnd,
  318. IDCK_DL_LAUNCHTAPITNA,
  319. TRUE
  320. );
  321. }
  322. if ( dwTapiTNAFlags & FLAG_AUTOLOCATIONID )
  323. {
  324. CheckDlgButton( hWnd,
  325. IDCK_DL_AUTOLOCATIONID,
  326. TRUE
  327. );
  328. }
  329. if ( dwTapiTNAFlags & FLAG_UPDATEONSTARTUP )
  330. {
  331. CheckDlgButton( hWnd,
  332. IDCK_DL_UPDATEONSTARTUP,
  333. TRUE
  334. );
  335. }
  336. if ( dwTapiTNAFlags & FLAG_PROMPTAUTOLOCATIONID )
  337. {
  338. CheckDlgButton( hWnd,
  339. IDCK_DL_PROMPTAUTOLOCATIONID,
  340. TRUE
  341. );
  342. }
  343. if ( dwTapiTNAFlags & FLAG_ANNOUNCEAUTOLOCATIONID )
  344. {
  345. CheckDlgButton( hWnd,
  346. IDCK_DL_ANNOUNCEAUTOLOCATIONID,
  347. TRUE
  348. );
  349. }
  350. //
  351. // Disable the two checkboxes dependent on this one,
  352. // but keep the settings
  353. //
  354. if ( dwTapiTNAFlags & FLAG_AUTOLOCATIONID )
  355. {
  356. EnableWindow( GetDlgItem(hWnd, IDCK_DL_PROMPTAUTOLOCATIONID),
  357. TRUE
  358. );
  359. EnableWindow( GetDlgItem(hWnd, IDCK_DL_ANNOUNCEAUTOLOCATIONID),
  360. TRUE
  361. );
  362. }
  363. else
  364. {
  365. EnableWindow( GetDlgItem(hWnd, IDCK_DL_PROMPTAUTOLOCATIONID),
  366. FALSE
  367. );
  368. EnableWindow( GetDlgItem(hWnd, IDCK_DL_ANNOUNCEAUTOLOCATIONID),
  369. FALSE
  370. );
  371. }
  372. }
  373. break;
  374. // Process clicks on controls after Context Help mode selected
  375. case WM_HELP:
  376. InternalDebugOut((50, " WM_HELP in LocDefineDlg"));
  377. WinHelp (((LPHELPINFO) lParam)->hItemHandle, "windows.hlp", HELP_WM_HELP,
  378. (ULONG_PTR)(LPSTR) aIds);
  379. break;
  380. // Process right-clicks on controls
  381. case WM_CONTEXTMENU:
  382. InternalDebugOut((50, " WM_CONTEXT_MENU in LocationsDlgProc"));
  383. WinHelp ((HWND) wParam, "windows.hlp", HELP_CONTEXTMENU, (ULONG_PTR)(LPVOID) aIds);
  384. break;
  385. case WM_NOTIFY:
  386. {
  387. LPNMHDR lpnm = (LPNMHDR)lParam;
  388. switch ( lpnm->code )
  389. {
  390. case PSN_APPLY: /* case IDOK */
  391. {
  392. DWORD dwDisposition; // Don't really care about this...
  393. InternalDebugOut((0, " PSN_APPLY - General"));
  394. if ( ((LPPSHNOTIFY)lpnm)->lParam )
  395. InternalDebugOut((0, " (actually, it was the OK button)"));
  396. //
  397. // Write out the new flags
  398. //
  399. lResult = RegCreateKeyEx(
  400. HKEY_LOCAL_MACHINE,
  401. gszAutoLaunchKey,
  402. 0,
  403. "", //Class? Who cares?
  404. REG_OPTION_NON_VOLATILE,
  405. KEY_ALL_ACCESS,
  406. NULL,
  407. &hKey,
  408. &dwDisposition
  409. );
  410. if (ERROR_SUCCESS == lResult)
  411. {
  412. lResult = RegSetValueEx(
  413. hKey,
  414. gszAutoLaunchValue,
  415. 0,
  416. dwType,
  417. (LPBYTE)&dwTapiTNAFlags,
  418. dwDataSize
  419. );
  420. RegCloseKey( hKey );
  421. }
  422. for ( n=0; n < gnNumConfigProfiles; n++)
  423. {
  424. DWORD dwTemp;
  425. TCHAR szKeyName[128];
  426. wsprintf ( szKeyName, gszStaticProfileKey, n+1);
  427. RegCreateKeyEx(
  428. HKEY_LOCAL_MACHINE,
  429. szKeyName,
  430. 0,
  431. "",
  432. REG_OPTION_NON_VOLATILE,
  433. KEY_ALL_ACCESS,
  434. NULL,
  435. &hKey,
  436. &dwTemp
  437. );
  438. RegSetValueEx(
  439. hKey,
  440. gszAutoLocationID,
  441. 0,
  442. REG_DWORD,
  443. (LPBYTE)&gdwConfigProfiles[n],
  444. sizeof(DWORD)
  445. );
  446. RegCloseKey( hKey );
  447. }
  448. break;
  449. }
  450. case PSN_RESET: /* case IDCANCEL: */
  451. InternalDebugOut((0, " PSN_RESET - General"));
  452. break;
  453. #if DBG
  454. case PSN_SETACTIVE:
  455. InternalDebugOut((0, " PSN_SETACTIVE - General"));
  456. break;
  457. case PSN_KILLACTIVE:
  458. InternalDebugOut((0, " PSN_KILLACTIVE - General"));
  459. break;
  460. #endif
  461. }
  462. }
  463. break;
  464. case WM_COMMAND:
  465. {
  466. switch (LOWORD(wParam))
  467. {
  468. case IDCB_DL_PROFILE1:
  469. case IDCB_DL_PROFILE2:
  470. case IDCB_DL_PROFILE3:
  471. case IDCB_DL_PROFILE4:
  472. {
  473. //
  474. // Only process if something is changing
  475. //
  476. switch HIWORD(wParam)
  477. {
  478. case CBN_SELCHANGE:
  479. {
  480. LRESULT m;
  481. gdwConfigProfiles[LOWORD(wParam) - IDCB_DL_PROFILE1] =
  482. n = (UINT) SendMessage( GetDlgItem( hWnd, LOWORD(wParam)),
  483. CB_GETITEMDATA,
  484. ( m= SendMessage(
  485. GetDlgItem( hWnd,
  486. LOWORD(wParam)),
  487. CB_GETCURSEL,
  488. 0,
  489. 0
  490. ) ) ,
  491. 0
  492. );
  493. //{
  494. // TCHAR Buffer[256];
  495. // wsprintf( Buffer, "wParam=0x%08lx lParam=0x%08lx data=0x%08lx m=0x%08lx",
  496. // (DWORD)wParam,
  497. // (DWORD)lParam,
  498. // (DWORD)n,
  499. // (DWORD)m
  500. // );
  501. // MessageBox(GetFocus(), Buffer, "", MB_OK);
  502. //}
  503. //
  504. // Activate the APPLY button if not already done
  505. //
  506. PropSheet_Changed(GetParent(hWnd), hWnd);
  507. }
  508. }
  509. }
  510. break;
  511. case IDCK_DL_LAUNCHTAPITNA:
  512. {
  513. dwTapiTNAFlags ^= FLAG_AUTOLAUNCH;
  514. //
  515. // Activate the APPLY button if not already done
  516. //
  517. PropSheet_Changed(GetParent(hWnd), hWnd);
  518. }
  519. break;
  520. case IDCK_DL_AUTOLOCATIONID:
  521. {
  522. dwTapiTNAFlags ^= FLAG_AUTOLOCATIONID;
  523. //
  524. // Disable the two checkboxes dependent on this one,
  525. // but keep the settings
  526. //
  527. if ( dwTapiTNAFlags & FLAG_AUTOLOCATIONID )
  528. {
  529. EnableWindow( GetDlgItem(hWnd, IDCK_DL_PROMPTAUTOLOCATIONID),
  530. TRUE
  531. );
  532. EnableWindow( GetDlgItem(hWnd, IDCK_DL_ANNOUNCEAUTOLOCATIONID),
  533. TRUE
  534. );
  535. // EnableWindow( GetDlgItem(hWnd, IDCS_DL_PROMPTAUTOLOCATIONID),
  536. // TRUE
  537. // );
  538. // EnableWindow( GetDlgItem(hWnd, IDCS_DL_ANNOUNCEAUTOLOCATIONID),
  539. // TRUE
  540. // );
  541. }
  542. else
  543. {
  544. EnableWindow( GetDlgItem(hWnd, IDCK_DL_PROMPTAUTOLOCATIONID),
  545. FALSE
  546. );
  547. EnableWindow( GetDlgItem(hWnd, IDCK_DL_ANNOUNCEAUTOLOCATIONID),
  548. FALSE
  549. );
  550. // EnableWindow( GetDlgItem(hWnd, IDCS_DL_PROMPTAUTOLOCATIONID),
  551. // FALSE
  552. // );
  553. // EnableWindow( GetDlgItem(hWnd, IDCS_DL_ANNOUNCEAUTOLOCATIONID),
  554. // FALSE
  555. // );
  556. }
  557. //
  558. // Activate the APPLY button if not already done
  559. //
  560. PropSheet_Changed(GetParent(hWnd), hWnd);
  561. }
  562. break;
  563. case IDCK_DL_PROMPTAUTOLOCATIONID:
  564. {
  565. dwTapiTNAFlags ^= FLAG_PROMPTAUTOLOCATIONID;
  566. //
  567. // Activate the APPLY button if not already done
  568. //
  569. PropSheet_Changed(GetParent(hWnd), hWnd);
  570. }
  571. break;
  572. case IDCK_DL_UPDATEONSTARTUP:
  573. {
  574. dwTapiTNAFlags ^= FLAG_UPDATEONSTARTUP;
  575. //
  576. // Activate the APPLY button if not already done
  577. //
  578. PropSheet_Changed(GetParent(hWnd), hWnd);
  579. }
  580. break;
  581. case IDCK_DL_ANNOUNCEAUTOLOCATIONID:
  582. {
  583. dwTapiTNAFlags ^= FLAG_ANNOUNCEAUTOLOCATIONID;
  584. //
  585. // Activate the APPLY button if not already done
  586. //
  587. PropSheet_Changed(GetParent(hWnd), hWnd);
  588. }
  589. break;
  590. default:
  591. {
  592. }
  593. break;
  594. }
  595. }
  596. break;
  597. default:
  598. break;
  599. }
  600. return FALSE;
  601. }