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.

4029 lines
134 KiB

  1. /*++
  2. Copyright (c) 1996 Microsoft Corporation
  3. Module Name:
  4. dialer.c
  5. --*/
  6. #include "dialer.h"
  7. #include "string.h"
  8. #include "tchar.h"
  9. #include "stdlib.h"
  10. #include "shellapi.h"
  11. #define DIALER_REGISTRY_PATH TEXT("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Dialer")
  12. #define DIALER_REGISTRY_ROOT HKEY_CURRENT_USER
  13. #define ISDIGIT(x) (((x) - TEXT('0')) >= 0) && (((x) - TEXT('0')) <= 9)
  14. enum NumberTypes
  15. {
  16. LOCAL_NUMBER = 7,
  17. EXTENDED_LOCAL_NUMBER,
  18. LONG_DISTANCE_NUMBER = 10,
  19. EXTENDED_LONG_DISTANCE_NUMBER
  20. };
  21. // structs
  22. typedef struct tagLINEINFO
  23. {
  24. DWORD nAddr; // Number of avail. addresses on the line
  25. BOOL fVoiceLine; // Is this a voice line?
  26. DWORD dwAPIVersion; // API version which the line supports
  27. HLINE hLine; // line handle returned by lineOpen
  28. DWORD dwPermanentLineID; // Permanent line ID retreived from devcaps
  29. TCHAR szLineName[MAXBUFSIZE]; // the line's name
  30. } LINEINFO, *LPLINEINFO;
  31. // Global variables
  32. // window/instance variables
  33. HWND ghWndMain;
  34. HWND ghWndDialing = NULL;
  35. HINSTANCE ghInst = 0;
  36. // file name vars.
  37. static TCHAR gszAppName[64];
  38. static TCHAR gszINIfilename [] = TEXT("DIALER.INI";)
  39. static TCHAR gszHELPfilename [] = TEXT("DIALER.HLP");
  40. static TCHAR gszDialerClassName[] = TEXT("DialerClass");
  41. TCHAR const gszNULL[] = TEXT("");
  42. // window item variables
  43. HLINEAPP ghLineApp = 0; // Dialer's usage handle (regist. w/TAPI)
  44. HCALL ghCall = 0; // call handle for Dialer's call
  45. LPTSTR gszCurrentNumber = NULL; // number of destination of current call
  46. LPTSTR gszCurrentName = NULL; // name of destination of current call
  47. BOOL gfRegistered; // was lineRegisterRequestRecipient()
  48. // successful?
  49. BOOL gfNeedToReinit = FALSE; // does Dialer need to re-initialize?
  50. BOOL gfCallRequest = FALSE; // Does a Simple TAPI app want a call?
  51. BOOL gfCurrentLineAvail = TRUE; // Simple TAPI requests are only carried
  52. // out if the current chosen line is avail.
  53. BOOL gfMakeCallReplyPending = FALSE;
  54. LONG gMakeCallRequestID = 0; // request ID returned by async TAPI fns.
  55. LONG gDropCallRequestID = 0; // request ID returned by async TAPI fns.
  56. DWORD gnAvailDevices = 0; // # of line devices avail. to Dialer
  57. LINEINFO gCurrentLineInfo;
  58. DWORD * gnAddr;
  59. // global to remember where the cursor is in the edit control
  60. DWORD gdwStartSel;
  61. DWORD gdwEndSel;
  62. DWORD * gdwPLID; // current line's permanent line ID
  63. DWORD giCurrentLine = (DWORD)-1; // the line selected by the user
  64. DWORD giCurrentAddress = 0; // the address selected by the user
  65. // + 1 so we can work 1-based rather than 0-based (for convenience only)
  66. // global varibles to hold the names and address of the
  67. TCHAR gszSDNumber[ NSPEEDDIALS + 1 ][ TAPIMAXDESTADDRESSSIZE ] = {0};
  68. // Function declarations
  69. // button related functions
  70. VOID DisableDialButtons(BOOL fDisable);
  71. VOID FitTextToButton( HWND, INT, LPTSTR );
  72. // Callback functions
  73. INT_PTR CALLBACK MainWndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam);
  74. INT_PTR CALLBACK DialingProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam);
  75. INT_PTR CALLBACK AboutProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam);
  76. INT_PTR CALLBACK ConnectUsingProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam);
  77. INT_PTR CALLBACK LineInUseProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam);
  78. INT_PTR CALLBACK SpeedDial1Proc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam);
  79. INT_PTR CALLBACK SpeedDial2Proc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam);
  80. VOID CALLBACK tapiCallback (
  81. DWORD hDevice, DWORD dwMsg,
  82. DWORD dwCallbackInstance,
  83. DWORD dwParam1, DWORD dwParam2,
  84. DWORD dwParam3
  85. );
  86. // tapi related functions
  87. VOID ManageAssistedTelephony(VOID);
  88. VOID InitiateCall(LPCTSTR szNumber, LPCTSTR szName);
  89. VOID DialerLineClose(VOID);
  90. VOID DialerCleanup(VOID);
  91. VOID CloseTAPI(VOID);
  92. DWORD GetLineInfo(DWORD iLine, LPLINEINFO lpLineInfo);
  93. VOID GetLineInfoFailed (
  94. DWORD iLine, LPLINEDEVCAPS lpDevCaps,
  95. LPLINEINFO lpLineInfo
  96. );
  97. LPTSTR GetAddressName(DWORD iLine, DWORD iAddress);
  98. BOOL MakeCanonicalNumber( LPCTSTR szName, LPTSTR szCanNumber );
  99. // misc. helper functions
  100. VOID ReadINI(VOID);
  101. int errString(HWND hWnd, UINT errCode, UINT uFlags);
  102. VOID AddToRedialList(LPCTSTR szNumber);
  103. BOOL InitializeLineBox(HWND hwndLineBox);
  104. BOOL InitializeAddressBox(HWND hwndLineBox, HWND hwndAddressBox);
  105. BOOL Is911 ( LPLINETRANSLATEOUTPUT lpTransOut );
  106. VOID AmpersandCompensate( LPCTSTR lpszSrc, LPTSTR lpszDst );
  107. VOID AmpersandDeCompensate( LPCTSTR lpszSrc, LPTSTR lpszDst );
  108. // Dialer memory management functions
  109. LPVOID DialerAlloc(size_t cbToAlloc);
  110. LPVOID DialerFree(LPVOID lpMem);
  111. // Function definitions
  112. //***************************************************************************
  113. //***************************************************************************
  114. //***************************************************************************
  115. DWORD InitializeTAPI (VOID)
  116. {
  117. INT cvLine;
  118. DWORD iLine;
  119. DWORD dwPreferredPLID, dwID = (DWORD) -1;
  120. MSG msg;
  121. LPLINEINFO lpLineInfo = NULL; // LINEINFO for each available line
  122. DWORD errCode;
  123. DWORD tc = GetTickCount();
  124. DWORD dwReturn = ERR_NONE;
  125. TCHAR szBuffer[MAXBUFSIZE]; // to read in dwPreferredPLID as a string first
  126. DWORD dwTapiVersion = TAPI_CURRENT_VERSION;
  127. LINEINITIALIZEEXPARAMS lip = {sizeof (LINEINITIALIZEEXPARAMS),
  128. sizeof (LINEINITIALIZEEXPARAMS),
  129. sizeof (LINEINITIALIZEEXPARAMS),
  130. LINEINITIALIZEEXOPTION_USEHIDDENWINDOW};
  131. HKEY hKey = NULL;
  132. DWORD dwSize;
  133. errCode = lineInitializeEx (
  134. &ghLineApp,
  135. ghInst,
  136. (LINECALLBACK) tapiCallback,
  137. gszAppName,
  138. &gnAvailDevices,
  139. &dwTapiVersion,
  140. &lip
  141. );
  142. if ( errCode == LINEERR_REINIT )
  143. {
  144. // take away dialer functionality
  145. EnableWindow( ghWndMain, FALSE );
  146. DisableDialButtons(TRUE);
  147. // keep trying until the user cancels
  148. // or we stop getting LINEERR_REINIT
  149. while ( ( errCode = lineInitializeEx (
  150. &ghLineApp,
  151. ghInst,
  152. (LINECALLBACK)tapiCallback,
  153. gszAppName,
  154. &gnAvailDevices,
  155. &dwTapiVersion,
  156. &lip
  157. ) )
  158. == LINEERR_REINIT )
  159. {
  160. // flush queue & yield
  161. while ( PeekMessage( &msg, 0, 0, 0, PM_REMOVE ) )
  162. {
  163. TranslateMessage( &msg );
  164. DispatchMessage( &msg );
  165. }
  166. // bring up the box if 5 seconds have passed since
  167. if(GetTickCount() > 5000 + tc)
  168. {
  169. if ( errString( ghWndMain, ikszWarningTapiReInit, MB_RETRYCANCEL )
  170. == IDCANCEL )
  171. {
  172. break;
  173. }
  174. // reset the relative counter
  175. tc = GetTickCount();
  176. }
  177. }
  178. // give back dialer functionality
  179. DisableDialButtons( FALSE );
  180. EnableWindow( ghWndMain, TRUE );
  181. }
  182. if ( errCode )
  183. {
  184. dwReturn = errCode;
  185. goto tapiinit_exit;
  186. }
  187. RegOpenKeyEx (DIALER_REGISTRY_ROOT, DIALER_REGISTRY_PATH, 0, KEY_READ, &hKey);
  188. // retrieve preferred line info from INI file
  189. dwSize = sizeof (szBuffer);
  190. szBuffer[0] = 0;
  191. if (ERROR_SUCCESS ==
  192. RegQueryValueEx (hKey, TEXT("Preferred Line"), NULL, NULL, (LPBYTE)szBuffer, &dwSize))
  193. {
  194. dwPreferredPLID = (DWORD) _ttoi( szBuffer );
  195. }
  196. else
  197. {
  198. dwPreferredPLID = (DWORD) -1;
  199. }
  200. // -1 default - tells us if it ever gets set
  201. giCurrentLine = (DWORD) -1;
  202. // allocate buffer for storing LINEINFO for all of the available lines
  203. // always allocate space for at least one line
  204. if ( gnAvailDevices == 0 )
  205. {
  206. gnAddr = (DWORD *) DialerAlloc( sizeof( DWORD ) );
  207. gdwPLID = (DWORD *) DialerAlloc( sizeof( DWORD ) );
  208. lpLineInfo = (LPLINEINFO) DialerAlloc( sizeof( LINEINFO ) );
  209. }
  210. else
  211. {
  212. gnAddr = (DWORD *) DialerAlloc( sizeof( DWORD ) * (int)gnAvailDevices);
  213. gdwPLID = (DWORD *) DialerAlloc( sizeof( DWORD ) * (int)gnAvailDevices);
  214. lpLineInfo = (LPLINEINFO) DialerAlloc( sizeof( LINEINFO ) * (int)gnAvailDevices );
  215. }
  216. // if no space was set aside...
  217. if ( lpLineInfo == NULL || gnAddr == NULL )
  218. {
  219. dwReturn = LINEERR_NOMEM;
  220. goto tapiinit_exit;
  221. }
  222. // fill lpLineInfo[] and open each line
  223. for ( iLine = 0, cvLine = 0; iLine < gnAvailDevices; ++iLine )
  224. {
  225. // skip remaining processing for this if it didn't open
  226. if ( GetLineInfo( iLine, &lpLineInfo[iLine] ) != ERR_NONE )
  227. continue;
  228. gnAddr [ iLine ] = lpLineInfo[iLine].nAddr;
  229. gdwPLID[ iLine ] = lpLineInfo[iLine].dwPermanentLineID;
  230. if ( lpLineInfo[iLine].dwPermanentLineID == dwPreferredPLID )
  231. giCurrentLine = iLine;
  232. // note number of lines with Interactive voice caps.
  233. // used to select a preferred line by default
  234. if ( lpLineInfo [ iLine ].fVoiceLine )
  235. {
  236. cvLine++;
  237. dwID = iLine;
  238. }
  239. }
  240. // if we couldn't find the preferred line,
  241. // try and assign one by default
  242. // else bring up connect using dialog
  243. if ( giCurrentLine == (DWORD)-1 )
  244. {
  245. // check if there is only one line
  246. // that has interactive voice caps,
  247. // make it default line
  248. if ( cvLine == 1 )
  249. {
  250. giCurrentLine = dwID;
  251. // if the preferred address read from the INI file
  252. // was different i.e we are changing setting, inform
  253. // the user
  254. if ( dwPreferredPLID != -1 )
  255. {
  256. errString( ghWndMain, ERR_NEWDEFAULT, MB_ICONEXCLAMATION | MB_OK );
  257. }
  258. }
  259. else
  260. {
  261. gCurrentLineInfo = lpLineInfo[0];
  262. if ( DialogBoxParam (
  263. ghInst,
  264. MAKEINTRESOURCE(IDD_CONNECTUSING),
  265. ghWndMain,
  266. ConnectUsingProc,
  267. INVALID_LINE
  268. )
  269. == -1)
  270. {
  271. dwReturn = (DWORD) -1;
  272. }
  273. else
  274. {
  275. dwReturn = ERR_NONE;
  276. }
  277. goto tapiinit_exit;
  278. }
  279. }
  280. gCurrentLineInfo = lpLineInfo[ giCurrentLine ];
  281. // select default address
  282. giCurrentAddress = 0;
  283. // get the name of the preferred address from ini file
  284. dwSize = sizeof (szBuffer);
  285. szBuffer[0] = 0;
  286. if (ERROR_SUCCESS ==
  287. RegQueryValueEx (hKey, TEXT("Preferred Address"), NULL, NULL, (LPBYTE)szBuffer, &dwSize))
  288. {
  289. giCurrentAddress = (DWORD) _ttoi( szBuffer );
  290. // if the address is invalid, set default
  291. if ( giCurrentAddress >= gCurrentLineInfo.nAddr )
  292. giCurrentAddress = 0;
  293. }
  294. tapiinit_exit:
  295. if (NULL != hKey)
  296. {
  297. RegCloseKey (hKey);
  298. }
  299. if (lpLineInfo)
  300. {
  301. DialerFree(lpLineInfo);
  302. }
  303. return dwReturn;;
  304. }
  305. //***************************************************************************
  306. //***************************************************************************
  307. //***************************************************************************
  308. int WINAPI WinMain (
  309. HINSTANCE hInstance,
  310. HINSTANCE hPrevInstance,
  311. LPSTR lpCmdLine,
  312. int nCmdShow
  313. )
  314. {
  315. HACCEL hAccel;
  316. MSG msg;
  317. DWORD errCode;
  318. HANDLE hImHere;
  319. ghInst = GetModuleHandle( NULL );
  320. LoadString( ghInst, ikszAppFriendlyName, gszAppName, sizeof(gszAppName)/sizeof(TCHAR) );
  321. //
  322. // Now, let's see if we've already got an instance of ourself
  323. hImHere = CreateMutex(NULL, TRUE, TEXT("DialersIveBeenStartedMutex"));
  324. //
  325. // Is there another one of us already here?
  326. if ( ERROR_ALREADY_EXISTS == GetLastError() )
  327. {
  328. HWND hDialerWnd;
  329. hDialerWnd = FindWindow(gszDialerClassName,
  330. NULL);
  331. SetForegroundWindow(hDialerWnd);
  332. CloseHandle( hImHere );
  333. return 0;
  334. }
  335. {
  336. WNDCLASS wc;
  337. wc.style = CS_DBLCLKS | CS_SAVEBITS | CS_BYTEALIGNWINDOW;
  338. wc.lpfnWndProc = DefDlgProc;
  339. wc.cbClsExtra = 0;
  340. wc.cbWndExtra = DLGWINDOWEXTRA;
  341. wc.hInstance = ghInst;
  342. wc.hIcon = LoadIcon(ghInst, MAKEINTRESOURCE(IDI_DIALER) );
  343. wc.hCursor = LoadCursor(NULL, IDC_ARROW);
  344. wc.hbrBackground = GetStockObject (COLOR_WINDOW + 1);
  345. wc.lpszMenuName = NULL;
  346. wc.lpszClassName = gszDialerClassName;
  347. RegisterClass(&wc);
  348. }
  349. // create the dialog box and set it with info
  350. // from the .INI file
  351. ghWndMain = CreateDialog (
  352. ghInst,
  353. MAKEINTRESOURCE(IDD_DIALER),
  354. (HWND)NULL,
  355. MainWndProc
  356. );
  357. ReadINI();
  358. ShowWindow(ghWndMain, SW_SHOW);
  359. UpdateWindow(ghWndMain);
  360. // limit text in Number field to TAPIMAXDESTADDRESSSIZE
  361. SendDlgItemMessage (
  362. ghWndMain,
  363. IDD_DCOMBO,
  364. CB_LIMITTEXT,
  365. (WPARAM)TAPIMAXDESTADDRESSSIZE,
  366. 0
  367. );
  368. // 0 (ERR_NONE) error code registers success - otherwise terminate
  369. errCode = InitializeTAPI();
  370. if(errCode)
  371. {
  372. errString(ghWndMain, errCode, MB_APPLMODAL | MB_ICONEXCLAMATION );
  373. DialerCleanup();
  374. return errCode;
  375. }
  376. errCode = lineRegisterRequestRecipient (
  377. ghLineApp,
  378. 0, // registration instance
  379. LINEREQUESTMODE_MAKECALL,
  380. TRUE
  381. );
  382. if(errCode)
  383. {
  384. gfRegistered = FALSE;
  385. errString(ghWndMain, errCode, MB_ICONEXCLAMATION | MB_OK );
  386. }
  387. else
  388. {
  389. gfRegistered = TRUE;
  390. }
  391. hAccel = LoadAccelerators(ghInst, gszAppName);
  392. while ( GetMessage( &msg, NULL, 0, 0 ) )
  393. {
  394. if ( ghWndMain == NULL || !IsDialogMessage( ghWndMain, &msg ) )
  395. {
  396. if(!TranslateAccelerator(ghWndMain, hAccel, &msg))
  397. {
  398. TranslateMessage(&msg);
  399. DispatchMessage(&msg);
  400. }
  401. }
  402. // If: 1) Dialer is a call manager (if not, ignore requests)
  403. // 2) the currently chosen line is available
  404. // 3) there is a Simple TAPI request
  405. // Then: process the request
  406. if ( gfCurrentLineAvail && gfCallRequest )
  407. {
  408. ManageAssistedTelephony();
  409. }
  410. }
  411. DialerCleanup();
  412. CloseHandle( hImHere );
  413. return (int)msg.wParam;
  414. }
  415. //***************************************************************************
  416. //***************************************************************************
  417. //***************************************************************************
  418. LPVOID DialerAlloc(size_t cbToAlloc)
  419. {
  420. return LocalAlloc(LPTR, cbToAlloc);
  421. }
  422. LPVOID DialerFree(LPVOID lpMem)
  423. {
  424. return LocalFree( lpMem );
  425. }
  426. //***************************************************************************
  427. //***************************************************************************
  428. //***************************************************************************
  429. VOID ReadINI( VOID )
  430. {
  431. WORD cSDEntry, cLastDialed;
  432. POINT ptLeftTop;
  433. TCHAR szName[ TAPIMAXCALLEDPARTYSIZE ] = {0};
  434. TCHAR szTemp[ TAPIMAXCALLEDPARTYSIZE ];
  435. TCHAR szNum[TAPIMAXDESTADDRESSSIZE];
  436. TCHAR szFieldName[MAXBUFSIZE];
  437. TCHAR *p;
  438. HKEY hKey = NULL;
  439. DWORD dwSize;
  440. RegOpenKeyEx (DIALER_REGISTRY_ROOT, DIALER_REGISTRY_PATH, 0, KEY_READ, &hKey);
  441. // get speed dial settings from INI file
  442. for(cSDEntry = 1; cSDEntry <= NSPEEDDIALS; ++cSDEntry)
  443. {
  444. wsprintf(szFieldName, TEXT("Number%d"), cSDEntry);
  445. *szNum = 0;
  446. dwSize = sizeof (szNum);
  447. RegQueryValueEx (hKey, szFieldName, NULL, NULL, (LPBYTE)szNum, &dwSize);
  448. for (p = szNum; *p == TEXT(' '); p++);
  449. if (0 == *p)
  450. {
  451. continue;
  452. }
  453. lstrcpyn (gszSDNumber[cSDEntry], p, sizeof(gszSDNumber[cSDEntry])/sizeof(TCHAR));
  454. wsprintf(szFieldName, TEXT("Name%d"), cSDEntry);
  455. dwSize = sizeof (szName);
  456. RegQueryValueEx (hKey, szFieldName, NULL, NULL, (LPBYTE)szName, &dwSize);
  457. if (0 == *szName)
  458. {
  459. lstrcpyn( szName, gszSDNumber[ cSDEntry ], sizeof(szName)/sizeof(szName[0]) );
  460. }
  461. FitTextToButton( ghWndMain, IDD_DSPEEDDIAL1 + cSDEntry - 1, szName );
  462. AmpersandCompensate( szName, szTemp );
  463. SetDlgItemText (
  464. ghWndMain,
  465. IDD_DSPEEDDIAL1 + cSDEntry - 1,
  466. (LPCTSTR)szTemp
  467. ); // Label the speed dial button
  468. }
  469. // set up last dialed numbers in combo box (read from INI)
  470. for(cLastDialed = 1; cLastDialed <= NLASTDIALED; ++cLastDialed)
  471. {
  472. wsprintf(szFieldName, TEXT("Last dialed %d"), cLastDialed);
  473. dwSize = sizeof (szNum);
  474. szNum[0] = 0;
  475. RegQueryValueEx (hKey, szFieldName, NULL, NULL, (LPBYTE)szNum, &dwSize);
  476. if (0 != szNum[0])
  477. {
  478. SendDlgItemMessage(
  479. ghWndMain,
  480. IDD_DCOMBO,
  481. CB_ADDSTRING,
  482. 0,
  483. (LPARAM)(LPCTSTR)szNum
  484. );
  485. }
  486. }
  487. // set defaults
  488. ptLeftTop.x = 100;
  489. ptLeftTop.y = 100;
  490. // set the window position based on the INI data
  491. dwSize = sizeof (ptLeftTop);
  492. RegQueryValueEx (hKey, TEXT("Main Window Left/Top"), NULL, NULL, (LPBYTE)&ptLeftTop, &dwSize);
  493. if ( ptLeftTop.x < 0
  494. || ptLeftTop.x + 50 >= GetSystemMetrics(SM_CXSCREEN)
  495. || ptLeftTop.y < 0
  496. || ptLeftTop.y + 50 >= GetSystemMetrics(SM_CYSCREEN)
  497. )
  498. {
  499. ptLeftTop.x = 100; // set defaults if the box is off of the screen
  500. ptLeftTop.y = 100; // set defaults if the box is off of the screen
  501. }
  502. SetWindowPos (
  503. ghWndMain,
  504. NULL,
  505. ptLeftTop.x,
  506. ptLeftTop.y,
  507. 0,
  508. 0,
  509. SWP_NOSIZE | SWP_NOACTIVATE | SWP_NOREDRAW | SWP_NOZORDER
  510. );
  511. RegCloseKey (hKey);
  512. }
  513. //***************************************************************************
  514. //***************************************************************************
  515. //***************************************************************************
  516. VOID DisableDialButtons(BOOL fDisable)
  517. {
  518. int IDD;
  519. // Disable/enable Dial button
  520. EnableWindow( GetDlgItem( ghWndMain, IDD_DDIAL ),!fDisable) ;
  521. // Disable/enable Speed dial buttons
  522. for ( IDD = IDD_DSPEEDDIAL1; IDD <= IDD_DSPEEDDIAL8; ++IDD )
  523. {
  524. EnableWindow(GetDlgItem(ghWndMain, IDD),!fDisable);
  525. }
  526. }
  527. //***************************************************************************
  528. //***************************************************************************
  529. //***************************************************************************
  530. VOID DialerCleanup(VOID)
  531. {
  532. RECT rc;
  533. WORD cItem; // count of numbers in combo box
  534. DWORD cLastDialed;
  535. TCHAR szNumber[TAPIMAXDESTADDRESSSIZE];
  536. TCHAR szFieldName[MAXBUFSIZE];
  537. HKEY hKey = NULL;
  538. DWORD dwSize;
  539. RegCreateKeyEx (DIALER_REGISTRY_ROOT, DIALER_REGISTRY_PATH, 0, NULL, REG_OPTION_NON_VOLATILE, KEY_WRITE, NULL, &hKey, NULL);
  540. CloseTAPI(); // unregister and line close
  541. if(!IsIconic(ghWndMain)) // if the window is not minimized, record position
  542. {
  543. GetWindowRect(ghWndMain, &rc);
  544. RegSetValueEx (hKey,
  545. TEXT("Main Window Left/Top"),
  546. 0,
  547. REG_BINARY,
  548. (LPBYTE)&rc,
  549. sizeof(POINT));
  550. }
  551. cItem = (WORD)SendDlgItemMessage(ghWndMain, IDD_DCOMBO, CB_GETCOUNT, 0, 0);
  552. // write out last dialed numbers from combo box (write to INI)
  553. for(cLastDialed = 1; cLastDialed <= NLASTDIALED; ++cLastDialed)
  554. {
  555. if(cLastDialed <= cItem)
  556. SendDlgItemMessage(
  557. ghWndMain,
  558. IDD_DCOMBO,
  559. CB_GETLBTEXT,
  560. cLastDialed - 1, // it's a zero-based count
  561. (LPARAM)szNumber);
  562. else
  563. szNumber[0] = 0;
  564. wsprintf(szFieldName, TEXT("Last dialed %d"), cLastDialed);
  565. RegSetValueEx (hKey,
  566. szFieldName,
  567. 0,
  568. REG_SZ,
  569. (LPBYTE)szNumber,
  570. (lstrlen(szNumber)+1)*sizeof(TCHAR));
  571. }
  572. RegCloseKey (hKey);
  573. WinHelp(ghWndMain, gszHELPfilename, HELP_QUIT, 0); // unload help
  574. DestroyWindow(ghWndMain);
  575. ghWndMain = NULL;
  576. }
  577. //***************************************************************************
  578. //***************************************************************************
  579. //***************************************************************************
  580. // unregister and line close
  581. VOID CloseTAPI(VOID)
  582. {
  583. // unregister as call manager
  584. lineRegisterRequestRecipient (
  585. ghLineApp,
  586. 0, // registration instance
  587. LINEREQUESTMODE_MAKECALL,
  588. FALSE
  589. );
  590. if ( gCurrentLineInfo.hLine )
  591. {
  592. lineClose ( gCurrentLineInfo.hLine );
  593. gfCurrentLineAvail = FALSE;
  594. gCurrentLineInfo.hLine = 0;
  595. }
  596. lineShutdown(ghLineApp);
  597. }
  598. //***************************************************************************
  599. //***************************************************************************
  600. //***************************************************************************
  601. INT_PTR CALLBACK MainWndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
  602. {
  603. static HICON hIcon;
  604. static const DWORD aMenuHelpIDs[] =
  605. {
  606. IDD_DSPEEDDIALGRP, (DWORD)-1,
  607. IDD_DNUMTODIAL, IDH_DIALER_DIAL_NUMBER,
  608. IDD_DCOMBO, IDH_DIALER_DIAL_NUMBER,
  609. IDD_DDIAL, IDH_DIALER_DIAL_BUTTON,
  610. IDD_DSPEEDDIAL1, IDH_DIALER_DIAL_SPEED_CHOOSE,
  611. IDD_DSPEEDDIAL2, IDH_DIALER_DIAL_SPEED_CHOOSE,
  612. IDD_DSPEEDDIAL3, IDH_DIALER_DIAL_SPEED_CHOOSE,
  613. IDD_DSPEEDDIAL4, IDH_DIALER_DIAL_SPEED_CHOOSE,
  614. IDD_DSPEEDDIAL5, IDH_DIALER_DIAL_SPEED_CHOOSE,
  615. IDD_DSPEEDDIAL6, IDH_DIALER_DIAL_SPEED_CHOOSE,
  616. IDD_DSPEEDDIAL7, IDH_DIALER_DIAL_SPEED_CHOOSE,
  617. IDD_DSPEEDDIAL8, IDH_DIALER_DIAL_SPEED_CHOOSE,
  618. IDD_DSPEEDDIALTEXT1, IDH_DIALER_DIAL_SPEED_CHOOSE,
  619. IDD_DSPEEDDIALTEXT2, IDH_DIALER_DIAL_SPEED_CHOOSE,
  620. IDD_DSPEEDDIALTEXT3, IDH_DIALER_DIAL_SPEED_CHOOSE,
  621. IDD_DSPEEDDIALTEXT4, IDH_DIALER_DIAL_SPEED_CHOOSE,
  622. IDD_DSPEEDDIALTEXT5, IDH_DIALER_DIAL_SPEED_CHOOSE,
  623. IDD_DSPEEDDIALTEXT6, IDH_DIALER_DIAL_SPEED_CHOOSE,
  624. IDD_DSPEEDDIALTEXT7, IDH_DIALER_DIAL_SPEED_CHOOSE,
  625. IDD_DSPEEDDIALTEXT8, IDH_DIALER_DIAL_SPEED_CHOOSE,
  626. IDD_DBUTTON1, IDH_DIALER_DIAL_KEYPAD,
  627. IDD_DBUTTON2, IDH_DIALER_DIAL_KEYPAD,
  628. IDD_DBUTTON3, IDH_DIALER_DIAL_KEYPAD,
  629. IDD_DBUTTON4, IDH_DIALER_DIAL_KEYPAD,
  630. IDD_DBUTTON5, IDH_DIALER_DIAL_KEYPAD,
  631. IDD_DBUTTON6, IDH_DIALER_DIAL_KEYPAD,
  632. IDD_DBUTTON7, IDH_DIALER_DIAL_KEYPAD,
  633. IDD_DBUTTON8, IDH_DIALER_DIAL_KEYPAD,
  634. IDD_DBUTTON9, IDH_DIALER_DIAL_KEYPAD,
  635. IDD_DBUTTONSTAR, IDH_DIALER_DIAL_KEYPAD,
  636. IDD_DBUTTON0, IDH_DIALER_DIAL_KEYPAD,
  637. IDD_DBUTTONPOUND, IDH_DIALER_DIAL_KEYPAD,
  638. 0, 0
  639. };
  640. switch (msg)
  641. {
  642. case WM_INITDIALOG:
  643. hIcon = LoadIcon( ghInst, MAKEINTRESOURCE( IDI_DIALER ) );
  644. return TRUE;
  645. case WM_SYSCOMMAND:
  646. switch( (DWORD) wParam )
  647. {
  648. case SC_CLOSE:
  649. PostQuitMessage(0);
  650. }
  651. break;
  652. // processes clicks on controls when
  653. // context mode help is selected
  654. case WM_HELP:
  655. WinHelp (
  656. ( (LPHELPINFO) lParam)->hItemHandle,
  657. gszHELPfilename,
  658. HELP_WM_HELP,
  659. (ULONG_PTR) aMenuHelpIDs
  660. );
  661. return TRUE;
  662. // processes right-clicks on controls
  663. case WM_CONTEXTMENU:
  664. WinHelp (
  665. (HWND)wParam,
  666. gszHELPfilename,
  667. HELP_CONTEXTMENU,
  668. (ULONG_PTR)aMenuHelpIDs
  669. );
  670. return TRUE;
  671. case WM_INITMENUPOPUP:
  672. // if edit menu
  673. if ( LOWORD(lParam) == 1 )
  674. {
  675. UINT wEnable;
  676. if ( GetParent( GetFocus() ) != GetDlgItem( ghWndMain, IDD_DCOMBO ) )
  677. {
  678. wEnable = MF_GRAYED;
  679. }
  680. else
  681. {
  682. LRESULT lSelect = SendDlgItemMessage (
  683. ghWndMain,
  684. IDD_DCOMBO,
  685. CB_GETEDITSEL,
  686. 0,
  687. 0
  688. );
  689. if ( HIWORD( lSelect ) != LOWORD( lSelect ) )
  690. wEnable = MF_ENABLED;
  691. else
  692. wEnable = MF_GRAYED;
  693. }
  694. EnableMenuItem((HMENU)wParam, IDM_EDIT_CUT, wEnable);
  695. EnableMenuItem((HMENU)wParam, IDM_EDIT_COPY, wEnable);
  696. EnableMenuItem((HMENU)wParam, IDM_EDIT_DELETE, wEnable);
  697. // enable paste option is there is data
  698. // in the clipboard
  699. if ( IsClipboardFormatAvailable( CF_TEXT ) )
  700. {
  701. if ( GetClipboardData ( CF_TEXT ) )
  702. {
  703. wEnable = MF_ENABLED;
  704. }
  705. else
  706. {
  707. wEnable = MF_GRAYED;
  708. }
  709. }
  710. else
  711. {
  712. wEnable = MF_GRAYED;
  713. }
  714. }
  715. break;
  716. case WM_COMMAND:
  717. {
  718. TCHAR szName[TAPIMAXCALLEDPARTYSIZE] = {0};
  719. TCHAR szNumber[TAPIMAXDESTADDRESSSIZE] = {TEXT('\0')};
  720. switch( LOWORD( (DWORD)wParam ) )
  721. {
  722. // FILE menu
  723. case IDM_EXIT:
  724. PostQuitMessage(0);
  725. return TRUE;
  726. // EDIT menu
  727. case IDM_EDIT_CUT:
  728. SendDlgItemMessage(ghWndMain, IDD_DCOMBO, WM_CUT, 0, 0);
  729. return TRUE;
  730. case IDM_EDIT_COPY:
  731. SendDlgItemMessage(ghWndMain, IDD_DCOMBO, WM_COPY, 0, 0);
  732. return TRUE;
  733. case IDM_EDIT_PASTE:
  734. SendDlgItemMessage(ghWndMain, IDD_DCOMBO, WM_PASTE, 0, 0);
  735. return TRUE;
  736. case IDM_EDIT_DELETE:
  737. SendDlgItemMessage(ghWndMain, IDD_DCOMBO, WM_CLEAR, 0, 0);
  738. return TRUE;
  739. case IDM_EDIT_SPEEDDIAL:
  740. DialogBoxParam (
  741. ghInst,
  742. MAKEINTRESOURCE(IDD_SD1),
  743. ghWndMain,
  744. SpeedDial1Proc,
  745. 0
  746. );
  747. SetFocus(GetDlgItem(ghWndMain, IDD_DDIAL));
  748. return TRUE;
  749. // TOOLS menu
  750. case IDM_CONNECTUSING:
  751. DialogBoxParam (
  752. ghInst,
  753. MAKEINTRESOURCE(IDD_CONNECTUSING),
  754. ghWndMain,
  755. ConnectUsingProc,
  756. MENU_CHOICE
  757. );
  758. return TRUE;
  759. case IDM_LOCATION:
  760. {
  761. TCHAR szCanNumber[ TAPIMAXDESTADDRESSSIZE ] = TEXT("");
  762. // fetch the number to be dialed
  763. if ( GetDlgItemText (
  764. ghWndMain,
  765. IDD_DCOMBO,
  766. szNumber,
  767. TAPIMAXDESTADDRESSSIZE
  768. )
  769. )
  770. {
  771. // if a number exists, convert it to
  772. // its canonical form.
  773. if ( !MakeCanonicalNumber ( szNumber, szCanNumber ) )
  774. {
  775. lstrcpy( szCanNumber, szNumber );
  776. }
  777. }
  778. lineTranslateDialog (
  779. ghLineApp,
  780. 0,
  781. TAPI_CURRENT_VERSION,
  782. ghWndMain,
  783. szCanNumber
  784. );
  785. return TRUE;
  786. }
  787. // HELP menu
  788. case IDM_HELP_CONTENTS:
  789. WinHelp(ghWndMain, gszHELPfilename, HELP_CONTENTS, 0);
  790. return TRUE;
  791. case IDM_HELP_WHATSTHIS:
  792. PostMessage(ghWndMain, WM_SYSCOMMAND, SC_CONTEXTHELP, 0);
  793. return TRUE;
  794. case IDM_ABOUT:
  795. #ifdef SDKRELEASE
  796. DialogBoxParam(
  797. ghInst,
  798. MAKEINTRESOURCE(IDD_ABOUT),
  799. ghWndMain,
  800. AboutProc,
  801. 0
  802. );
  803. #else
  804. ShellAbout(
  805. ghWndMain,
  806. gszAppName,
  807. gszNULL,
  808. LoadIcon(ghInst, MAKEINTRESOURCE(IDI_DIALER))
  809. );
  810. #endif
  811. return TRUE;
  812. // Accelerator processing
  813. case IDM_ACCEL_NUMTODIAL:
  814. if(GetActiveWindow() == ghWndMain)
  815. SetFocus(GetDlgItem(ghWndMain, IDD_DCOMBO));
  816. return TRUE;
  817. // Buttons
  818. case IDD_DDIAL:
  819. {
  820. DWORD cSDEntry;
  821. TCHAR szSDNumber[TAPIMAXDESTADDRESSSIZE];
  822. TCHAR szFieldName[MAXBUFSIZE];
  823. HKEY hKey = NULL;
  824. DWORD dwSize;
  825. // check if number entered is dialable
  826. if ( SendMessage (
  827. GetDlgItem(ghWndMain, IDD_DCOMBO),
  828. WM_GETTEXTLENGTH,
  829. 0,
  830. 0
  831. ) > 0
  832. )
  833. {
  834. // get the number to be dialed
  835. GetDlgItemText (
  836. ghWndMain,
  837. IDD_DCOMBO,
  838. szNumber,
  839. TAPIMAXDESTADDRESSSIZE
  840. );
  841. // check if it is a speed dial number.
  842. // If so choose the name to be displayed.
  843. RegOpenKeyEx (DIALER_REGISTRY_ROOT, DIALER_REGISTRY_PATH, 0, KEY_READ, &hKey);
  844. for( cSDEntry = 1; cSDEntry <= NSPEEDDIALS; ++cSDEntry)
  845. {
  846. wsprintf(szFieldName, TEXT("Number%d"), cSDEntry);
  847. dwSize = sizeof (szSDNumber);
  848. if (ERROR_SUCCESS ==
  849. RegQueryValueEx (hKey, szFieldName, NULL, NULL, (LPBYTE)szSDNumber, &dwSize))
  850. {
  851. if ( lstrcmp(szSDNumber, szNumber) == 0 )
  852. {
  853. wsprintf( szFieldName, TEXT("Name%d"), cSDEntry);
  854. dwSize = sizeof (szName);
  855. RegQueryValueEx (hKey, szFieldName, NULL, NULL, (LPBYTE)szName, &dwSize);
  856. break;
  857. }
  858. }
  859. }
  860. RegCloseKey (hKey);
  861. SetFocus( GetDlgItem( ghWndMain, IDD_DDIAL ) );
  862. // once the currentline has been set
  863. // using the connect proc
  864. // the user must hit dial again
  865. if ( giCurrentLine == (DWORD)-1 )
  866. {
  867. DialogBoxParam (
  868. ghInst,
  869. MAKEINTRESOURCE(IDD_CONNECTUSING),
  870. ghWndMain,
  871. ConnectUsingProc,
  872. INVALID_LINE
  873. );
  874. }
  875. else
  876. {
  877. AddToRedialList(szNumber);
  878. InitiateCall(szNumber, szName);
  879. }
  880. }
  881. return TRUE;
  882. }
  883. case IDD_DBUTTON1:
  884. case IDD_DBUTTON2:
  885. case IDD_DBUTTON3:
  886. case IDD_DBUTTON4:
  887. case IDD_DBUTTON5:
  888. case IDD_DBUTTON6:
  889. case IDD_DBUTTON7:
  890. case IDD_DBUTTON8:
  891. case IDD_DBUTTON9:
  892. case IDD_DBUTTON0:
  893. case IDD_DBUTTONSTAR:
  894. case IDD_DBUTTONPOUND:
  895. {
  896. int i;
  897. TCHAR szBuffer[TAPIMAXDESTADDRESSSIZE+1];
  898. static const TCHAR digits[] = {
  899. TEXT('1'),
  900. TEXT('2'),
  901. TEXT('3'),
  902. TEXT('4'),
  903. TEXT('5'),
  904. TEXT('6'),
  905. TEXT('7'),
  906. TEXT('8'),
  907. TEXT('9'),
  908. TEXT('0'),
  909. TEXT('*'),
  910. TEXT('#')
  911. };
  912. i = (int)SendDlgItemMessage(ghWndMain,
  913. IDD_DCOMBO,
  914. WM_GETTEXT,
  915. (WPARAM)TAPIMAXDESTADDRESSSIZE+1,
  916. (LPARAM)szBuffer);
  917. if (i < TAPIMAXDESTADDRESSSIZE)
  918. {
  919. MoveMemory(szBuffer+gdwStartSel+1,
  920. szBuffer+gdwEndSel,
  921. (i - ( gdwEndSel ) + 1)*sizeof(TCHAR) );
  922. szBuffer[gdwStartSel] = digits[LOWORD(wParam) - IDD_DBUTTON1];
  923. SendDlgItemMessage(ghWndMain,
  924. IDD_DCOMBO,
  925. WM_SETTEXT,
  926. 0,
  927. (LPARAM)szBuffer);
  928. gdwStartSel++;
  929. gdwEndSel = gdwStartSel;
  930. }
  931. SetFocus(GetDlgItem(ghWndMain, IDD_DDIAL));
  932. EnableWindow(GetDlgItem(ghWndMain, IDD_DDIAL), TRUE);
  933. return TRUE;
  934. }
  935. case IDD_DCOMBO:
  936. if (HIWORD(wParam) == CBN_SELENDOK)
  937. {
  938. EnableWindow( GetDlgItem(ghWndMain, IDD_DDIAL), TRUE );
  939. }
  940. if ((HIWORD(wParam) == CBN_SELENDOK) ||
  941. (HIWORD(wParam) == CBN_SELENDCANCEL))
  942. {
  943. (DWORD)SendDlgItemMessage(ghWndMain,
  944. IDD_DCOMBO,
  945. CB_GETEDITSEL,
  946. (WPARAM)&gdwStartSel,
  947. (LPARAM)&gdwEndSel);
  948. return FALSE;
  949. }
  950. if ( HIWORD( wParam ) == CBN_EDITCHANGE )
  951. {
  952. EnableWindow (
  953. GetDlgItem( ghWndMain, IDD_DDIAL ),
  954. (BOOL) GetWindowTextLength (
  955. GetDlgItem (
  956. ghWndMain,
  957. IDD_DCOMBO
  958. )
  959. )
  960. );
  961. return TRUE;
  962. }
  963. break;
  964. case IDD_DSPEEDDIAL1:
  965. case IDD_DSPEEDDIAL2:
  966. case IDD_DSPEEDDIAL3:
  967. case IDD_DSPEEDDIAL4:
  968. case IDD_DSPEEDDIAL5:
  969. case IDD_DSPEEDDIAL6:
  970. case IDD_DSPEEDDIAL7:
  971. case IDD_DSPEEDDIAL8:
  972. {
  973. DWORD cSDEntry = LOWORD( (DWORD) wParam) - IDD_DSPEEDDIAL1 + 1;
  974. TCHAR szFieldName [MAXBUFSIZE];
  975. TCHAR szNum[TAPIMAXDESTADDRESSSIZE] ={0};
  976. TCHAR *p;
  977. HKEY hKey = NULL;
  978. DWORD dwSize;
  979. // get information for the speed dial button
  980. // from the INI file
  981. RegOpenKeyEx (DIALER_REGISTRY_ROOT, DIALER_REGISTRY_PATH, 0, KEY_READ, &hKey);
  982. wsprintf(szFieldName, TEXT("Name%d"), cSDEntry);
  983. dwSize = sizeof (szName);
  984. RegQueryValueEx (hKey, szFieldName, NULL, NULL, (LPBYTE)szName, &dwSize);
  985. wsprintf(szFieldName, TEXT("%s%d"), TEXT("Number"), cSDEntry);
  986. dwSize = sizeof (szNum);//gszSDNumber[cSDEntry]);
  987. RegQueryValueEx (hKey, szFieldName, NULL, NULL, (LPBYTE)szNum, &dwSize);
  988. RegCloseKey (hKey);
  989. for (p = szNum; *p == TEXT(' '); p++);
  990. lstrcpyn (gszSDNumber[cSDEntry], p, sizeof(gszSDNumber[cSDEntry])/sizeof(TCHAR));
  991. // entry not set yet
  992. if( gszSDNumber[cSDEntry][0] == 0 )
  993. {
  994. DialogBoxParam (
  995. ghInst,
  996. MAKEINTRESOURCE(IDD_SD2),
  997. ghWndMain,
  998. SpeedDial2Proc,
  999. MAKELPARAM(wParam,0)
  1000. );
  1001. }
  1002. // no line open
  1003. // once the currentline has been set
  1004. // using the connect proc
  1005. // the user must hit dial again
  1006. else if ( giCurrentLine == (DWORD)-1)
  1007. {
  1008. DialogBoxParam (
  1009. ghInst,
  1010. MAKEINTRESOURCE(IDD_CONNECTUSING),
  1011. ghWndMain,
  1012. ConnectUsingProc,
  1013. INVALID_LINE
  1014. );
  1015. }
  1016. // entry is set and valid voice line is open
  1017. else
  1018. {
  1019. // add number to list box combo.
  1020. AddToRedialList( gszSDNumber[cSDEntry] );
  1021. InitiateCall( gszSDNumber[cSDEntry], szName );
  1022. }
  1023. break;
  1024. }
  1025. } // end switch (LOWORD((DWORD)wParam)) { ... }
  1026. break; // end case WM_COMMAND
  1027. }
  1028. case WM_PAINT:
  1029. {
  1030. PAINTSTRUCT ps;
  1031. BeginPaint(ghWndMain, &ps);
  1032. if(IsIconic(ghWndMain))
  1033. DrawIcon(ps.hdc, 0, 0, hIcon);
  1034. else
  1035. {
  1036. HBRUSH hBrush;
  1037. hBrush = GetSysColorBrush( COLOR_3DFACE );
  1038. // FillRect(ps.hdc, &ps.rcPaint, GetStockObject(LTGRAY_BRUSH));
  1039. FillRect(ps.hdc, &ps.rcPaint, hBrush);
  1040. }
  1041. EndPaint(ghWndMain, &ps);
  1042. return TRUE;
  1043. }
  1044. case WM_CTLCOLORLISTBOX:
  1045. case WM_CTLCOLORBTN:
  1046. case WM_CTLCOLORSTATIC:
  1047. SetBkColor((HDC)wParam, GetSysColor(COLOR_BTNFACE));
  1048. return (INT_PTR)GetSysColorBrush( COLOR_3DFACE );
  1049. default:
  1050. ;
  1051. // return DefDlgProc( hwnd, msg, wParam, lParam );
  1052. // return DefWindowProc( hwnd, msg, wParam, lParam );
  1053. } // switch (msg) { ... }
  1054. return FALSE;
  1055. }
  1056. //***************************************************************************
  1057. //***************************************************************************
  1058. //***************************************************************************
  1059. VOID AddToRedialList( LPCTSTR szNumber )
  1060. {
  1061. // NLASTDIALED == 10
  1062. WORD cNum;
  1063. HWND hWndCombo = GetDlgItem(ghWndMain, IDD_DCOMBO);
  1064. DWORD nMatch;
  1065. // if valid number
  1066. if ( szNumber[0] )
  1067. {
  1068. // if list box has entries, check if this number
  1069. // is already present. If so delete old entry
  1070. cNum = (WORD) SendMessage(hWndCombo, CB_GETCOUNT, 0, 0);
  1071. if ( cNum != 0 )
  1072. {
  1073. nMatch = (int)SendMessage ( hWndCombo, CB_FINDSTRING, 0, (LPARAM)szNumber );
  1074. if ( nMatch != CB_ERR )
  1075. {
  1076. SendMessage(hWndCombo, CB_DELETESTRING, nMatch, 0);
  1077. }
  1078. else
  1079. {
  1080. // if the list is full, remove oldest
  1081. if ( cNum == NLASTDIALED )
  1082. {
  1083. SendMessage( hWndCombo, CB_DELETESTRING, NLASTDIALED - 1, 0 );
  1084. }
  1085. }
  1086. }
  1087. SendMessage(hWndCombo, CB_INSERTSTRING, 0, (LPARAM)szNumber);
  1088. SendMessage(hWndCombo, CB_SETCURSEL, 0, 0L);
  1089. EnableWindow ( GetDlgItem( ghWndMain, IDD_DDIAL ), TRUE );
  1090. }
  1091. }
  1092. //***************************************************************************
  1093. //***************************************************************************
  1094. //***************************************************************************
  1095. VOID InitiateCall ( LPCTSTR szNumber, LPCTSTR szName )
  1096. {
  1097. HLINE hLine = 0;
  1098. DWORD errCode;
  1099. // struct size info
  1100. DWORD dwLTPSize = sizeof ( LINETRANSLATEOUTPUT );
  1101. DWORD dwNameLen = lstrlen( szName ) + 1;
  1102. DWORD dwLCPSize = sizeof( LINECALLPARAMS );
  1103. LPLINETRANSLATEOUTPUT lpTransOut = NULL;
  1104. LPLINECALLPARAMS lpLineCallParams = NULL;
  1105. TCHAR szCanNumber[ TAPIMAXDESTADDRESSSIZE ];
  1106. // Open a line
  1107. errCode = lineOpen (
  1108. ghLineApp,
  1109. giCurrentLine,
  1110. &hLine,
  1111. gCurrentLineInfo.dwAPIVersion,
  1112. 0,
  1113. 0,
  1114. LINECALLPRIVILEGE_NONE,
  1115. 0,
  1116. NULL
  1117. );
  1118. if (errCode)
  1119. {
  1120. errString ( ghWndMain, errCode, MB_ICONEXCLAMATION | MB_OK );
  1121. goto error;
  1122. }
  1123. // call translate address before dialing
  1124. do
  1125. {
  1126. lpTransOut = (LPLINETRANSLATEOUTPUT) DialerAlloc( dwLTPSize );
  1127. if ( !lpTransOut )
  1128. {
  1129. errString( ghWndMain, LINEERR_NOMEM, MB_ICONSTOP | MB_OK );
  1130. goto error;
  1131. }
  1132. lpTransOut-> dwTotalSize = dwLTPSize;
  1133. if ( !MakeCanonicalNumber( szNumber, szCanNumber ) )
  1134. {
  1135. lstrcpy( szCanNumber, szNumber );
  1136. }
  1137. errCode = lineTranslateAddress (
  1138. ghLineApp,
  1139. giCurrentLine,
  1140. gCurrentLineInfo.dwAPIVersion,
  1141. szCanNumber,
  1142. 0,
  1143. 0,
  1144. lpTransOut
  1145. );
  1146. if ( ((LONG)errCode) < 0 )
  1147. {
  1148. errString( ghWndMain, errCode, MB_ICONEXCLAMATION | MB_OK );
  1149. goto error;
  1150. }
  1151. if ( lpTransOut-> dwNeededSize <= lpTransOut->dwTotalSize )
  1152. {
  1153. // ok we are done
  1154. break;
  1155. }
  1156. else
  1157. {
  1158. dwLTPSize = lpTransOut-> dwNeededSize;
  1159. DialerFree ( lpTransOut );
  1160. lpTransOut = NULL;
  1161. }
  1162. } while ( TRUE );
  1163. // if number dialed is 911, bring up a warning
  1164. if ( Is911( lpTransOut) )
  1165. {
  1166. INT nRes = errString ( ghWndMain, ERR_911WARN, MB_ICONSTOP | MB_YESNO );
  1167. if ( nRes == IDNO )
  1168. {
  1169. goto error;
  1170. }
  1171. }
  1172. // set call parameters
  1173. dwLCPSize += dwNameLen + lpTransOut-> dwDisplayableStringSize;
  1174. lpLineCallParams = (LPLINECALLPARAMS) DialerAlloc( dwLCPSize );
  1175. if ( !lpLineCallParams )
  1176. {
  1177. errString( ghWndMain, LINEERR_NOMEM, MB_ICONSTOP | MB_OK );
  1178. goto error;
  1179. }
  1180. lpLineCallParams->dwTotalSize = dwLCPSize;
  1181. lpLineCallParams->dwBearerMode = LINEBEARERMODE_VOICE;
  1182. lpLineCallParams->dwMediaMode = LINEMEDIAMODE_INTERACTIVEVOICE;
  1183. lpLineCallParams->dwCallParamFlags = LINECALLPARAMFLAGS_IDLE;
  1184. lpLineCallParams->dwAddressMode = LINEADDRESSMODE_ADDRESSID;
  1185. lpLineCallParams->dwAddressID = giCurrentAddress;
  1186. if ( szName[ 0 ] )
  1187. {
  1188. lpLineCallParams->dwCalledPartySize = dwNameLen;
  1189. lpLineCallParams->dwCalledPartyOffset = sizeof( LINECALLPARAMS );
  1190. lstrcpy ((LPTSTR)((char*)lpLineCallParams + sizeof(LINECALLPARAMS)),
  1191. szName);
  1192. }
  1193. lpLineCallParams-> dwDisplayableAddressSize = lpTransOut-> dwDisplayableStringSize;
  1194. lpLineCallParams-> dwDisplayableAddressOffset = sizeof( LINECALLPARAMS ) + dwNameLen;
  1195. lstrcpy (
  1196. (LPTSTR) ((char*)lpLineCallParams + sizeof(LINECALLPARAMS) + dwNameLen),
  1197. (LPTSTR) ((char*)lpTransOut + lpTransOut-> dwDisplayableStringOffset)
  1198. );
  1199. // save dialing information
  1200. // Free old allocs.
  1201. if ( gszCurrentName )
  1202. {
  1203. DialerFree ( gszCurrentName );
  1204. }
  1205. if ( gszCurrentNumber )
  1206. {
  1207. DialerFree ( gszCurrentNumber );
  1208. }
  1209. // save new stuff
  1210. gszCurrentName = (LPTSTR) DialerAlloc( dwNameLen*sizeof(TCHAR) );
  1211. if ( !gszCurrentName )
  1212. {
  1213. errString( ghWndMain, LINEERR_NOMEM, MB_ICONSTOP | MB_OK );
  1214. goto error;
  1215. }
  1216. lstrcpy ( gszCurrentName, szName );
  1217. gszCurrentNumber = (LPTSTR) DialerAlloc( lpTransOut->dwDisplayableStringSize);
  1218. if ( !gszCurrentNumber )
  1219. {
  1220. errString( ghWndMain, LINEERR_NOMEM, MB_ICONSTOP | MB_OK );
  1221. goto error;
  1222. }
  1223. lstrcpy (
  1224. gszCurrentNumber,
  1225. (LPTSTR) ((char*)lpTransOut + lpTransOut-> dwDisplayableStringOffset)
  1226. );
  1227. gCurrentLineInfo.hLine = hLine;
  1228. ghCall = 0;
  1229. // finally make the call.
  1230. gMakeCallRequestID = 0;
  1231. gMakeCallRequestID = lineMakeCall (
  1232. hLine,
  1233. &ghCall,
  1234. (LPTSTR) ((char*)lpTransOut + lpTransOut-> dwDialableStringOffset),
  1235. 0,
  1236. lpLineCallParams
  1237. );
  1238. // async request ID
  1239. // - the call is going out
  1240. if ( (LONG) gMakeCallRequestID > 0 )
  1241. {
  1242. gfCurrentLineAvail = FALSE;
  1243. gfMakeCallReplyPending = TRUE;
  1244. DialogBoxParam (
  1245. ghInst,
  1246. MAKEINTRESOURCE(IDD_DIALING),
  1247. ghWndMain,
  1248. DialingProc,
  1249. 0
  1250. );
  1251. }
  1252. else
  1253. {
  1254. if ( gMakeCallRequestID == LINEERR_CALLUNAVAIL )
  1255. {
  1256. DialogBoxParam (
  1257. ghInst,
  1258. MAKEINTRESOURCE(IDD_CALLFAILED),
  1259. ghWndMain,
  1260. LineInUseProc,
  1261. 0
  1262. );
  1263. }
  1264. else
  1265. {
  1266. errString( ghWndMain, gMakeCallRequestID, MB_ICONEXCLAMATION | MB_OK );
  1267. }
  1268. DialerLineClose();
  1269. gfCurrentLineAvail = TRUE;
  1270. }
  1271. error :
  1272. if ( lpLineCallParams )
  1273. {
  1274. DialerFree( lpLineCallParams );
  1275. }
  1276. if ( lpTransOut )
  1277. {
  1278. DialerFree( lpTransOut );
  1279. }
  1280. // if makecall did not succeed but line
  1281. // was opened, close it.
  1282. if ( ( gMakeCallRequestID <= 0 ) && ( gCurrentLineInfo.hLine ) )
  1283. {
  1284. DialerLineClose ();
  1285. gfCurrentLineAvail = TRUE;
  1286. }
  1287. SetFocus( GetDlgItem( ghWndMain, IDD_DCOMBO ) );
  1288. return;
  1289. }
  1290. //***************************************************************************
  1291. //***************************************************************************
  1292. //***************************************************************************
  1293. DWORD GetLineInfo ( DWORD iLine, LPLINEINFO lpLineInfo )
  1294. {
  1295. DWORD errCode = 0;
  1296. DWORD dwNeededSize = 0;
  1297. LINEEXTENSIONID ExtensionID;
  1298. LPTSTR pszLineName = NULL;
  1299. LPLINEDEVCAPS lpDevCaps = NULL;
  1300. int lineNameLen;
  1301. errCode = lineNegotiateAPIVersion (
  1302. ghLineApp,
  1303. iLine,
  1304. TAPI_VERSION_1_0,
  1305. TAPI_CURRENT_VERSION,
  1306. &( lpLineInfo->dwAPIVersion ),
  1307. &ExtensionID
  1308. );
  1309. if ( errCode )
  1310. {
  1311. GetLineInfoFailed( iLine, lpDevCaps, lpLineInfo );
  1312. goto error;
  1313. }
  1314. dwNeededSize = sizeof( LINEDEVCAPS );
  1315. do
  1316. {
  1317. lpDevCaps = ( LPLINEDEVCAPS ) DialerAlloc( dwNeededSize );
  1318. if ( !lpDevCaps )
  1319. {
  1320. GetLineInfoFailed( iLine, lpDevCaps, lpLineInfo );
  1321. errCode = LINEERR_NOMEM;
  1322. goto error;
  1323. }
  1324. lpDevCaps->dwTotalSize = dwNeededSize;
  1325. errCode = lineGetDevCaps (
  1326. ghLineApp,
  1327. iLine,
  1328. lpLineInfo->dwAPIVersion,
  1329. 0,
  1330. lpDevCaps
  1331. );
  1332. if ( errCode )
  1333. {
  1334. GetLineInfoFailed( iLine, lpDevCaps, lpLineInfo );
  1335. goto error;
  1336. }
  1337. if ( lpDevCaps-> dwNeededSize <= lpDevCaps-> dwTotalSize )
  1338. {
  1339. break;
  1340. }
  1341. dwNeededSize = lpDevCaps->dwNeededSize;
  1342. DialerFree( lpDevCaps );
  1343. lpDevCaps = NULL;
  1344. } while ( TRUE );
  1345. lpLineInfo->nAddr = lpDevCaps->dwNumAddresses;
  1346. lpLineInfo->fVoiceLine =
  1347. ( (lpDevCaps->dwMediaModes & LINEMEDIAMODE_INTERACTIVEVOICE) != 0 );
  1348. pszLineName = (LPTSTR) DialerAlloc( MAXBUFSIZE*sizeof(TCHAR) );
  1349. if ( !pszLineName )
  1350. {
  1351. errCode = LINEERR_NOMEM;
  1352. goto error;
  1353. }
  1354. if ( lpDevCaps->dwLineNameSize > 0 )
  1355. {
  1356. lineNameLen = 1 + (lpDevCaps->dwLineNameSize / sizeof (TCHAR));
  1357. if (lineNameLen > MAXBUFSIZE)
  1358. {
  1359. lstrcpyn (
  1360. pszLineName,
  1361. (LPTSTR) ((char*)lpDevCaps + lpDevCaps->dwLineNameOffset),
  1362. MAXBUFSIZE
  1363. );
  1364. }
  1365. else
  1366. {
  1367. lstrcpyn (
  1368. pszLineName,
  1369. (LPTSTR) ((char*)lpDevCaps + lpDevCaps->dwLineNameOffset),
  1370. lineNameLen);
  1371. }
  1372. }
  1373. else
  1374. {
  1375. wsprintf ( pszLineName, TEXT("Line %d"), iLine );
  1376. }
  1377. lstrcpy( lpLineInfo->szLineName, pszLineName );
  1378. lpLineInfo->dwPermanentLineID = lpDevCaps->dwPermanentLineID;
  1379. error:
  1380. if ( lpDevCaps )
  1381. DialerFree( lpDevCaps );
  1382. if ( pszLineName )
  1383. DialerFree( pszLineName );
  1384. return errCode;
  1385. }
  1386. //***************************************************************************
  1387. //***************************************************************************
  1388. //***************************************************************************
  1389. VOID GetLineInfoFailed ( DWORD iLine, LPLINEDEVCAPS lpDevCaps, LPLINEINFO lpLineInfo )
  1390. {
  1391. if ( lpDevCaps )
  1392. DialerFree(lpDevCaps);
  1393. lpLineInfo->nAddr = 0;
  1394. lpLineInfo->fVoiceLine = FALSE;
  1395. lpLineInfo->dwAPIVersion = 0;
  1396. lpLineInfo->hLine = (HLINE)0;
  1397. lpLineInfo->dwPermanentLineID = 0;
  1398. lpLineInfo->szLineName[0] = 0;
  1399. }
  1400. //***************************************************************************
  1401. //***************************************************************************
  1402. //***************************************************************************
  1403. LPTSTR GetAddressName(DWORD iLine, DWORD iAddress)
  1404. {
  1405. DWORD errCode = 0;
  1406. DWORD dwNeededSize = 0;
  1407. LPTSTR pszAddressName = NULL;
  1408. LPLINEADDRESSCAPS lpAddressCaps = NULL;
  1409. // allocate space for lineGetAddressCaps data
  1410. dwNeededSize = sizeof( LINEADDRESSCAPS );
  1411. do
  1412. {
  1413. lpAddressCaps = ( LPLINEADDRESSCAPS )DialerAlloc( dwNeededSize );
  1414. if ( !lpAddressCaps )
  1415. {
  1416. goto error;
  1417. }
  1418. lpAddressCaps->dwTotalSize = dwNeededSize;
  1419. errCode = lineGetAddressCaps (
  1420. ghLineApp,
  1421. iLine,
  1422. iAddress,
  1423. gCurrentLineInfo.dwAPIVersion,
  1424. 0,
  1425. lpAddressCaps
  1426. );
  1427. if ( errCode )
  1428. {
  1429. errString (NULL, errCode, MB_ICONSTOP | MB_OK );
  1430. goto error;
  1431. }
  1432. if ( lpAddressCaps-> dwNeededSize <= lpAddressCaps-> dwTotalSize )
  1433. {
  1434. break;
  1435. }
  1436. dwNeededSize = lpAddressCaps->dwNeededSize;
  1437. DialerFree( lpAddressCaps );
  1438. lpAddressCaps = NULL;
  1439. } while( TRUE );
  1440. // get the address name
  1441. pszAddressName = DialerAlloc( MAXBUFSIZE * sizeof(TCHAR));
  1442. if ( !pszAddressName )
  1443. {
  1444. goto error;
  1445. }
  1446. if ( lpAddressCaps-> dwAddressSize > 0 )
  1447. {
  1448. // keep string length bounded
  1449. if ( lpAddressCaps-> dwAddressSize > (MAXBUFSIZE - 1 ) )
  1450. {
  1451. lstrcpyn(
  1452. pszAddressName,
  1453. (LPTSTR) ((char*)lpAddressCaps + lpAddressCaps->dwAddressOffset),
  1454. MAXBUFSIZE
  1455. );
  1456. pszAddressName[ MAXBUFSIZE - 1] = '\0';
  1457. }
  1458. else
  1459. {
  1460. lstrcpy (
  1461. pszAddressName,
  1462. (LPTSTR) ((char*)lpAddressCaps + lpAddressCaps->dwAddressOffset)
  1463. );
  1464. }
  1465. }
  1466. else
  1467. // use default name
  1468. {
  1469. wsprintf(pszAddressName, TEXT("Address %d"), iAddress);
  1470. }
  1471. error:
  1472. if ( lpAddressCaps )
  1473. {
  1474. DialerFree( lpAddressCaps );
  1475. }
  1476. return pszAddressName;
  1477. }
  1478. //***************************************************************************
  1479. //***************************************************************************
  1480. //***************************************************************************
  1481. INT_PTR CALLBACK DialingProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
  1482. {
  1483. switch(msg)
  1484. {
  1485. TCHAR szTemp[ TAPIMAXCALLEDPARTYSIZE ];
  1486. case WM_INITDIALOG:
  1487. // set global handle to window
  1488. ghWndDialing = hwnd;
  1489. AmpersandCompensate( gszCurrentName, szTemp );
  1490. SetDlgItemText(hwnd, IDD_DGNUMBERTEXT, gszCurrentNumber);
  1491. SetDlgItemText(hwnd, IDD_DGNAMETEXT, szTemp );
  1492. break;
  1493. case WM_COMMAND:
  1494. switch ( LOWORD( (DWORD)wParam ) )
  1495. {
  1496. // hang up
  1497. case IDCANCEL:
  1498. // if lineMakeCall has completed
  1499. // only then drop call.
  1500. if (!gfMakeCallReplyPending && ghCall )
  1501. {
  1502. if ( ( gDropCallRequestID = lineDrop ( ghCall, NULL, 0 ) ) < 0 )
  1503. {
  1504. errString ( ghWndDialing, gDropCallRequestID, MB_ICONSTOP | MB_OK );
  1505. }
  1506. }
  1507. else
  1508. {
  1509. DialerLineClose();
  1510. gfCurrentLineAvail = TRUE;
  1511. gfMakeCallReplyPending = FALSE;
  1512. }
  1513. ghWndDialing = NULL;
  1514. EndDialog(hwnd, FALSE);
  1515. return TRUE;
  1516. // something else terminated the call
  1517. // all we have to do is terminate this dialog box
  1518. case IDOK:
  1519. ghWndDialing = NULL;
  1520. EndDialog(hwnd, TRUE);
  1521. return TRUE;
  1522. }
  1523. break;
  1524. default:
  1525. ;
  1526. }
  1527. return FALSE;
  1528. }
  1529. //***************************************************************************
  1530. //***************************************************************************
  1531. //***************************************************************************
  1532. INT_PTR CALLBACK AboutProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
  1533. {
  1534. switch(msg)
  1535. {
  1536. case WM_INITDIALOG:
  1537. {
  1538. TCHAR sz[MAXBUFSIZE];
  1539. TCHAR szLabel[MAXBUFSIZE];
  1540. // sets up the version number for Windows
  1541. GetDlgItemText(hwnd, IDD_ATEXTTITLE, sz, MAXBUFSIZE);
  1542. wsprintf(
  1543. szLabel,
  1544. sz,
  1545. LOWORD(GetVersion()) & 0xFF,
  1546. HIBYTE(LOWORD(GetVersion)) == 10 ? 1 : 0
  1547. );
  1548. SetDlgItemText(hwnd, IDD_ATEXTTITLE, szLabel);
  1549. return TRUE;
  1550. }
  1551. case WM_COMMAND:
  1552. if(LOWORD((DWORD)wParam) == IDOK)
  1553. {
  1554. EndDialog(hwnd, TRUE);
  1555. return TRUE;
  1556. }
  1557. break;
  1558. }
  1559. return FALSE;
  1560. }
  1561. //***************************************************************************
  1562. //***************************************************************************
  1563. //***************************************************************************
  1564. INT_PTR CALLBACK ConnectUsingProc( HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam )
  1565. {
  1566. static const DWORD aMenuHelpIDs[] =
  1567. {
  1568. IDD_CUTEXTLINE, IDH_DIALER_OPTIONS_LINE,
  1569. IDD_CULISTLINE, IDH_DIALER_OPTIONS_LINE,
  1570. IDD_CUTEXTADDRESS, IDH_DIALER_OPTIONS_ADDRESS,
  1571. IDD_CULISTADDRESS, IDH_DIALER_OPTIONS_ADDRESS,
  1572. IDD_CUSIMPLETAPICHKBOX, IDH_DIALER_OPTIONS_VOICE,
  1573. IDD_CUPROPERTIES, IDH_DIALER_OPTIONS_PROPERTIES,
  1574. 0, 0
  1575. };
  1576. switch(msg)
  1577. {
  1578. case WM_HELP:
  1579. // processes clicks on controls when
  1580. // context mode help is selected
  1581. WinHelp (
  1582. ((LPHELPINFO)lParam)->hItemHandle,
  1583. gszHELPfilename,
  1584. HELP_WM_HELP,
  1585. (ULONG_PTR)aMenuHelpIDs
  1586. );
  1587. return TRUE;
  1588. case WM_CONTEXTMENU:
  1589. // processes right-clicks on controls
  1590. WinHelp (
  1591. (HWND)wParam,
  1592. gszHELPfilename,
  1593. HELP_CONTEXTMENU,
  1594. (ULONG_PTR)aMenuHelpIDs
  1595. );
  1596. return TRUE;
  1597. case WM_INITDIALOG:
  1598. {
  1599. BOOL fEnable;
  1600. DWORD dwPriority;
  1601. //
  1602. // Is there any point in even showing this dialog box?
  1603. if ( gnAvailDevices == 0 )
  1604. {
  1605. // Nope. Let's tell the user what we don't like.
  1606. errString ( ghWndMain, ERR_NOLINES, MB_ICONEXCLAMATION | MB_OK );
  1607. EndDialog(hwnd, FALSE);
  1608. return TRUE;
  1609. }
  1610. // if not brought up by InitializeTAPI()
  1611. if ( lParam != INVALID_LINE )
  1612. {
  1613. // hide error text
  1614. EnableWindow( GetDlgItem( hwnd, IDD_CUERRORTEXT ), FALSE );
  1615. }
  1616. // get list of lines into the line list box.
  1617. fEnable = InitializeLineBox( GetDlgItem(hwnd, IDD_CULISTLINE) );
  1618. EnableWindow( GetDlgItem( hwnd, IDD_CULISTLINE ), fEnable);
  1619. // get list of addresses into the address list box.
  1620. fEnable = fEnable &&
  1621. InitializeAddressBox (
  1622. GetDlgItem(hwnd, IDD_CULISTLINE),
  1623. GetDlgItem(hwnd, IDD_CULISTADDRESS)
  1624. );
  1625. EnableWindow( GetDlgItem( hwnd, IDD_CULISTADDRESS ), fEnable );
  1626. EnableWindow( GetDlgItem( hwnd, IDOK ), fEnable );
  1627. EnableWindow( GetDlgItem( hwnd, IDD_CUPROPERTIES ), fEnable );
  1628. lineGetAppPriority (
  1629. TEXT("DIALER.EXE"),
  1630. 0, // checking app priority for Assisted Telephony requests
  1631. NULL,
  1632. LINEREQUESTMODE_MAKECALL,
  1633. NULL,
  1634. &dwPriority
  1635. );
  1636. CheckDlgButton(hwnd, IDD_CUSIMPLETAPICHKBOX, (dwPriority == 1));
  1637. // if dwPriority == 1, we're supporting Assisted Telephony AND
  1638. // have the highest priority.
  1639. EnableWindow (
  1640. GetDlgItem(hwnd, IDD_CUSIMPLETAPICHKBOX),
  1641. gfRegistered
  1642. );
  1643. return FALSE;
  1644. }
  1645. case WM_COMMAND:
  1646. {
  1647. switch ( LOWORD( (DWORD)wParam ) )
  1648. {
  1649. case IDD_CULISTLINE:
  1650. if ( HIWORD( wParam ) == CBN_SELENDOK )
  1651. // update address box
  1652. InitializeAddressBox (
  1653. GetDlgItem(hwnd, IDD_CULISTLINE),
  1654. GetDlgItem(hwnd, IDD_CULISTADDRESS)
  1655. );
  1656. break;
  1657. case IDD_CUPROPERTIES:
  1658. {
  1659. HWND hW = GetDlgItem(hwnd, IDD_CULISTLINE);
  1660. lineConfigDialog (
  1661. // device ID
  1662. (DWORD) SendMessage (
  1663. hW,
  1664. CB_GETITEMDATA,
  1665. (WORD) SendMessage(hW, CB_GETCURSEL, 0, 0),
  1666. 0
  1667. ),
  1668. hwnd,
  1669. NULL
  1670. );
  1671. break;
  1672. }
  1673. case IDOK:
  1674. {
  1675. HWND hwndBox;
  1676. TCHAR szBuffer[MAXBUFSIZE];
  1677. DWORD dwPriority;
  1678. HKEY hKey = NULL;
  1679. DWORD dwSize;
  1680. RegCreateKeyEx (DIALER_REGISTRY_ROOT, DIALER_REGISTRY_PATH, 0, NULL, REG_OPTION_NON_VOLATILE, KEY_WRITE, NULL, &hKey, NULL);
  1681. // Update line
  1682. hwndBox = GetDlgItem( hwnd, IDD_CULISTLINE );
  1683. giCurrentLine = (int) SendMessage (
  1684. hwndBox,
  1685. CB_GETITEMDATA,
  1686. SendMessage( hwndBox, CB_GETCURSEL, 0, 0 ),
  1687. 0
  1688. );
  1689. // base 10
  1690. _itot( gdwPLID[giCurrentLine], szBuffer, 10 );
  1691. RegSetValueEx (hKey, TEXT("Preferred Line"), 0, REG_SZ,
  1692. (LPBYTE)szBuffer, (lstrlen(szBuffer)+1)*sizeof(TCHAR));
  1693. // Update address
  1694. hwndBox = GetDlgItem( hwnd, IDD_CULISTADDRESS );
  1695. giCurrentAddress = (int) SendMessage (
  1696. hwndBox,
  1697. CB_GETITEMDATA,
  1698. SendMessage(hwndBox, CB_GETCURSEL, 0, 0),
  1699. 0
  1700. );
  1701. _itot( giCurrentAddress, szBuffer, 10 );
  1702. RegSetValueEx (hKey, TEXT("Preferred Address"), 0, REG_SZ,
  1703. (LPBYTE)szBuffer, (lstrlen(szBuffer)+1)*sizeof(TCHAR));
  1704. RegCloseKey (hKey);
  1705. // Update application priority
  1706. if ( SendDlgItemMessage (
  1707. hwnd,
  1708. IDD_CUSIMPLETAPICHKBOX,
  1709. BM_GETCHECK,
  1710. 0,
  1711. 0L
  1712. )
  1713. == 0)
  1714. {
  1715. dwPriority = 0;
  1716. }
  1717. else
  1718. {
  1719. dwPriority = 1;
  1720. }
  1721. lineSetAppPriority (
  1722. TEXT("DIALER.EXE"),
  1723. 0,
  1724. NULL,
  1725. LINEREQUESTMODE_MAKECALL,
  1726. NULL,
  1727. dwPriority
  1728. );
  1729. EndDialog(hwnd, TRUE);
  1730. return TRUE;
  1731. }
  1732. case IDCANCEL:
  1733. EndDialog(hwnd, FALSE);
  1734. return TRUE;
  1735. }
  1736. }
  1737. default:
  1738. ;
  1739. }
  1740. return FALSE;
  1741. }
  1742. //***************************************************************************
  1743. //***************************************************************************
  1744. //***************************************************************************
  1745. INT_PTR CALLBACK LineInUseProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
  1746. {
  1747. int lNewParam = (int)lParam;
  1748. PTSTR ptStr;
  1749. switch(msg)
  1750. {
  1751. case WM_INITDIALOG:
  1752. {
  1753. switch(lParam)
  1754. {
  1755. case LINEDISCONNECTMODE_REJECT:
  1756. lNewParam = ikszDisconnectedReject;
  1757. break;
  1758. case LINEDISCONNECTMODE_BUSY:
  1759. lNewParam = ikszDisconnectedBusy;
  1760. break;
  1761. case LINEDISCONNECTMODE_NOANSWER:
  1762. lNewParam = ikszDisconnectedNoAnswer;
  1763. break;
  1764. case LINEDISCONNECTMODE_CONGESTION:
  1765. lNewParam = ikszDisconnectedNetwork;
  1766. break;
  1767. case LINEDISCONNECTMODE_INCOMPATIBLE:
  1768. lNewParam = ikszDisconnectedIncompatible;
  1769. break;
  1770. case LINEDISCONNECTMODE_NODIALTONE:
  1771. lNewParam = ikszDisconnectedNoDialTone;
  1772. break;
  1773. default:
  1774. lNewParam = ikszDisconnectedCantDo;
  1775. break;
  1776. }
  1777. ptStr = DialerAlloc( MAXBUFSIZE*sizeof(TCHAR) );
  1778. LoadString( ghInst, lNewParam, ptStr, MAXBUFSIZE );
  1779. SetDlgItemText (hwnd, IDD_CFTEXT, ptStr);
  1780. DialerFree( ptStr );
  1781. return TRUE;
  1782. }
  1783. case WM_COMMAND:
  1784. if(LOWORD((DWORD)wParam) == IDOK)
  1785. {
  1786. EndDialog(hwnd, TRUE);
  1787. return TRUE;
  1788. }
  1789. break;
  1790. }
  1791. return FALSE;
  1792. }
  1793. //***************************************************************************
  1794. //***************************************************************************
  1795. //***************************************************************************
  1796. INT_PTR CALLBACK SpeedDial1Proc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
  1797. {
  1798. static DWORD nCurrentSpeedDial;
  1799. static const DWORD aMenuHelpIDs[] =
  1800. {
  1801. IDOK, IDH_DIALER_SPEED_SAVE,
  1802. IDD_SD1SPEEDDIAL1, IDH_DIALER_BUTTONS,
  1803. IDD_SD1SPEEDDIAL2, IDH_DIALER_BUTTONS,
  1804. IDD_SD1SPEEDDIAL3, IDH_DIALER_BUTTONS,
  1805. IDD_SD1SPEEDDIAL4, IDH_DIALER_BUTTONS,
  1806. IDD_SD1SPEEDDIAL5, IDH_DIALER_BUTTONS,
  1807. IDD_SD1SPEEDDIAL6, IDH_DIALER_BUTTONS,
  1808. IDD_SD1SPEEDDIAL7, IDH_DIALER_BUTTONS,
  1809. IDD_SD1SPEEDDIAL8, IDH_DIALER_BUTTONS,
  1810. IDD_SD1SPEEDDIALTEXT1, IDH_DIALER_BUTTONS,
  1811. IDD_SD1SPEEDDIALTEXT2, IDH_DIALER_BUTTONS,
  1812. IDD_SD1SPEEDDIALTEXT3, IDH_DIALER_BUTTONS,
  1813. IDD_SD1SPEEDDIALTEXT4, IDH_DIALER_BUTTONS,
  1814. IDD_SD1SPEEDDIALTEXT5, IDH_DIALER_BUTTONS,
  1815. IDD_SD1SPEEDDIALTEXT6, IDH_DIALER_BUTTONS,
  1816. IDD_SD1SPEEDDIALTEXT7, IDH_DIALER_BUTTONS,
  1817. IDD_SD1SPEEDDIALTEXT8, IDH_DIALER_BUTTONS,
  1818. IDD_SD1TEXTNAME, IDH_DIALER_SPEED_NAME,
  1819. IDD_SD1EDITNAME, IDH_DIALER_SPEED_NAME,
  1820. IDD_SD1TEXTNUMBER, IDH_DIALER_SPEED_NUMBER,
  1821. IDD_SD1EDITNUMBER, IDH_DIALER_SPEED_NUMBER,
  1822. IDD_SD1TEXTCHOOSE, (DWORD)-1,
  1823. IDD_SD1TEXTENTER, (DWORD)-1,
  1824. 0, 0
  1825. };
  1826. // buffer to store speed dial names till they are saved.
  1827. static TCHAR szSDName[NSPEEDDIALS + 1][TAPIMAXCALLEDPARTYSIZE] = {0};
  1828. switch(msg)
  1829. {
  1830. case WM_HELP:
  1831. // processes clicks on controls when
  1832. // context mode help is selected
  1833. WinHelp(
  1834. ((LPHELPINFO)lParam)->hItemHandle,
  1835. gszHELPfilename,
  1836. HELP_WM_HELP,
  1837. (ULONG_PTR)aMenuHelpIDs
  1838. );
  1839. return TRUE;
  1840. case WM_CONTEXTMENU: // processes right-clicks on controls
  1841. WinHelp(
  1842. (HWND)wParam,
  1843. gszHELPfilename,
  1844. HELP_CONTEXTMENU,
  1845. (ULONG_PTR)aMenuHelpIDs
  1846. );
  1847. return TRUE;
  1848. case WM_INITDIALOG:
  1849. {
  1850. DWORD cSDEntry;
  1851. DWORD idFirstEmpty = (DWORD) -1;
  1852. TCHAR szName[TAPIMAXCALLEDPARTYSIZE] = {0};
  1853. TCHAR szTemp[TAPIMAXCALLEDPARTYSIZE];
  1854. TCHAR szFieldName[MAXBUFSIZE];
  1855. HKEY hKey = NULL;
  1856. DWORD dwSize;
  1857. // Retrieve speed dial info from INI file
  1858. RegOpenKeyEx (DIALER_REGISTRY_ROOT, DIALER_REGISTRY_PATH, 0, KEY_READ, &hKey);
  1859. for(cSDEntry = 1; cSDEntry <= NSPEEDDIALS; ++cSDEntry)
  1860. {
  1861. wsprintf(szFieldName, TEXT("Name%d"), cSDEntry);
  1862. dwSize = sizeof (szSDName[ cSDEntry ]);
  1863. RegQueryValueEx (hKey, szFieldName, NULL, NULL, (LPBYTE)szSDName[cSDEntry], &dwSize);
  1864. // set the first empty speed dial button
  1865. if ( idFirstEmpty == -1 &&
  1866. szSDName[ cSDEntry ][0] == '\0' &&
  1867. gszSDNumber[ cSDEntry ][ 0 ] == '\0' )
  1868. idFirstEmpty = cSDEntry;
  1869. wsprintf(szFieldName, TEXT("Number%d"), cSDEntry);
  1870. dwSize = sizeof (gszSDNumber[cSDEntry]);
  1871. RegQueryValueEx (hKey, szFieldName, NULL, NULL, (LPBYTE)gszSDNumber[cSDEntry], &dwSize);
  1872. // get a copy of the name for editing
  1873. // if name is empty, use the number as the
  1874. // name.
  1875. if (0 != szSDName[ cSDEntry][0])
  1876. {
  1877. lstrcpyn( szName, szSDName[ cSDEntry], sizeof(szName)/sizeof(szName[0]));
  1878. }
  1879. else
  1880. {
  1881. lstrcpyn( szName, gszSDNumber[ cSDEntry ], sizeof(szName)/sizeof(szName[0]) );
  1882. }
  1883. FitTextToButton( hwnd, IDD_SD1SPEEDDIAL1 + cSDEntry - 1, szName );
  1884. AmpersandCompensate( szName, szTemp );
  1885. SetDlgItemText (
  1886. hwnd,
  1887. IDD_SD1SPEEDDIAL1 + cSDEntry - 1,
  1888. (LPCTSTR) szTemp
  1889. );
  1890. }
  1891. RegCloseKey (hKey);
  1892. // for the edit speed dial dialog
  1893. // limit the lengths of text
  1894. SendDlgItemMessage (
  1895. hwnd,
  1896. IDD_SD1EDITNAME,
  1897. EM_LIMITTEXT,
  1898. (WPARAM)(TAPIMAXCALLEDPARTYSIZE - 1),
  1899. 0
  1900. );
  1901. SendDlgItemMessage (
  1902. hwnd,
  1903. IDD_SD1EDITNUMBER,
  1904. EM_LIMITTEXT,
  1905. (WPARAM)(TAPIMAXDESTADDRESSSIZE - 1),
  1906. 0
  1907. );
  1908. // select the first empty button
  1909. // nothing empty, then edit #1
  1910. if ( -1 == idFirstEmpty )
  1911. {
  1912. nCurrentSpeedDial = 1;
  1913. SetDlgItemText(
  1914. hwnd,
  1915. IDD_SD1EDITNAME,
  1916. (LPCTSTR) szSDName[ 1 ]
  1917. );
  1918. SetDlgItemText(
  1919. hwnd,
  1920. IDD_SD1EDITNUMBER,
  1921. (LPCTSTR) gszSDNumber[ 1 ]
  1922. );
  1923. }
  1924. else
  1925. {
  1926. nCurrentSpeedDial = idFirstEmpty;
  1927. }
  1928. SetFocus( GetDlgItem( hwnd, IDD_SD1EDITNAME ) );
  1929. return FALSE;
  1930. }
  1931. case WM_COMMAND:
  1932. {
  1933. TCHAR szName[TAPIMAXCALLEDPARTYSIZE];
  1934. TCHAR szTemp[ TAPIMAXCALLEDPARTYSIZE ];
  1935. switch( LOWORD( (DWORD) wParam ) )
  1936. {
  1937. case IDOK:
  1938. {
  1939. DWORD cSDEntry;
  1940. TCHAR szFieldName[MAXBUFSIZE];
  1941. HKEY hKey = NULL;
  1942. // save new speed dial settings
  1943. RegCreateKeyEx (DIALER_REGISTRY_ROOT, DIALER_REGISTRY_PATH, 0, NULL, REG_OPTION_NON_VOLATILE, KEY_WRITE, NULL, &hKey, NULL);
  1944. for ( cSDEntry = 1; cSDEntry <= NSPEEDDIALS; ++cSDEntry )
  1945. {
  1946. wsprintf(szFieldName, TEXT("Name%d"), cSDEntry);
  1947. RegSetValueEx (hKey, szFieldName, 0, REG_SZ,
  1948. (LPBYTE)(szSDName[cSDEntry]),
  1949. (lstrlen(szSDName[cSDEntry])+1)*sizeof(TCHAR));
  1950. wsprintf(szFieldName, TEXT("Number%d"), cSDEntry);
  1951. RegSetValueEx (hKey, szFieldName, 0, REG_SZ,
  1952. (LPBYTE)(gszSDNumber[cSDEntry]),
  1953. (lstrlen(gszSDNumber[cSDEntry])+1)*sizeof(TCHAR));
  1954. // set the text for the corresponding
  1955. // main window button
  1956. if ( szSDName[ cSDEntry ][ 0 ] == TEXT('\0') )
  1957. {
  1958. lstrcpyn( szName, gszSDNumber[ cSDEntry ], sizeof(szName)/sizeof(szName[0]) );
  1959. }
  1960. else
  1961. {
  1962. lstrcpyn( szName, szSDName[ cSDEntry ], sizeof(szName)/sizeof(szName[0]) );
  1963. }
  1964. FitTextToButton(
  1965. ghWndMain,
  1966. IDD_DSPEEDDIAL1 + cSDEntry - 1,
  1967. szName
  1968. );
  1969. AmpersandCompensate( szName, szTemp );
  1970. SetDlgItemText (
  1971. ghWndMain,
  1972. IDD_DSPEEDDIAL1 + cSDEntry - 1,
  1973. (LPCTSTR) szTemp
  1974. );
  1975. }
  1976. RegCloseKey (hKey);
  1977. EndDialog(hwnd, TRUE);
  1978. return TRUE;
  1979. }
  1980. case IDCANCEL:
  1981. EndDialog(hwnd, FALSE);
  1982. return TRUE;
  1983. case IDD_SD1SPEEDDIAL1:
  1984. case IDD_SD1SPEEDDIAL2:
  1985. case IDD_SD1SPEEDDIAL3:
  1986. case IDD_SD1SPEEDDIAL4:
  1987. case IDD_SD1SPEEDDIAL5:
  1988. case IDD_SD1SPEEDDIAL6:
  1989. case IDD_SD1SPEEDDIAL7:
  1990. case IDD_SD1SPEEDDIAL8:
  1991. nCurrentSpeedDial = LOWORD( (DWORD) wParam ) - IDD_SD1SPEEDDIAL1 + 1;
  1992. SetDlgItemText (
  1993. hwnd,
  1994. IDD_SD1EDITNAME,
  1995. szSDName [ nCurrentSpeedDial ]
  1996. );
  1997. SetDlgItemText (
  1998. hwnd,
  1999. IDD_SD1EDITNUMBER,
  2000. gszSDNumber[nCurrentSpeedDial]
  2001. );
  2002. SetFocus( GetDlgItem( hwnd, IDD_SD1EDITNAME ) );
  2003. SendDlgItemMessage(
  2004. hwnd,
  2005. IDD_SD1EDITNAME,
  2006. EM_SETSEL,
  2007. 0,
  2008. MAKELPARAM(0, -1)
  2009. );
  2010. break;
  2011. case IDD_SD1EDITNAME:
  2012. if ( HIWORD( wParam ) == EN_CHANGE )
  2013. {
  2014. TCHAR *p;
  2015. GetDlgItemText (
  2016. hwnd,
  2017. IDD_SD1EDITNAME,
  2018. szName,
  2019. TAPIMAXCALLEDPARTYSIZE
  2020. );
  2021. for (p = szName; *p == TEXT(' '); p++);
  2022. // if there is no name, label the button with
  2023. // the number
  2024. if ( *p == TEXT('\0') )
  2025. {
  2026. szSDName[ nCurrentSpeedDial ][ 0 ] = TEXT('\0');
  2027. lstrcpyn( szName, gszSDNumber[ nCurrentSpeedDial ], sizeof(szName)/sizeof(szName[0]) );
  2028. p = szName;
  2029. }
  2030. else
  2031. {
  2032. lstrcpy( szSDName[ nCurrentSpeedDial ], p );
  2033. }
  2034. FitTextToButton (
  2035. hwnd,
  2036. IDD_SD1SPEEDDIAL1 + nCurrentSpeedDial - 1,
  2037. szName
  2038. );
  2039. AmpersandCompensate( p, szTemp );
  2040. SetDlgItemText (
  2041. hwnd,
  2042. IDD_SD1SPEEDDIAL1 + nCurrentSpeedDial - 1,
  2043. szTemp
  2044. );
  2045. }
  2046. break;
  2047. case IDD_SD1EDITNUMBER:
  2048. if ( HIWORD( wParam ) == EN_CHANGE )
  2049. {
  2050. GetDlgItemText (
  2051. hwnd,
  2052. IDD_SD1EDITNUMBER,
  2053. gszSDNumber[nCurrentSpeedDial],
  2054. TAPIMAXDESTADDRESSSIZE
  2055. );
  2056. if ( gszSDNumber[ nCurrentSpeedDial ][ 0 ] == '\0' )
  2057. {
  2058. GetDlgItemText (
  2059. hwnd,
  2060. IDD_SD1EDITNAME,
  2061. szName,
  2062. TAPIMAXDESTADDRESSSIZE
  2063. );
  2064. if ( szName[ 0 ] == TEXT('\0') )
  2065. {
  2066. SetDlgItemText (
  2067. hwnd,
  2068. IDD_SD1SPEEDDIAL1 + nCurrentSpeedDial - 1,
  2069. szName
  2070. );
  2071. }
  2072. }
  2073. }
  2074. break;
  2075. } // switch(LOWORD((DWORD)wParam))
  2076. break;
  2077. } // case WM_COMMAND:
  2078. default:
  2079. ;
  2080. } // switch(msg)
  2081. return FALSE;
  2082. }
  2083. //***************************************************************************
  2084. //***************************************************************************
  2085. //***************************************************************************
  2086. INT_PTR CALLBACK SpeedDial2Proc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
  2087. {
  2088. static DWORD nCurrentSpeedDial;
  2089. static const DWORD aMenuHelpIDs[] =
  2090. {
  2091. IDOK, IDH_DIALER_SPEED_SAVE,
  2092. IDD_SD2SAVEANDDIAL, IDH_DIALER_SPEED_SAVE_DIAL,
  2093. IDD_SD2TEXTNAME, IDH_DIALER_SPEED_NAME,
  2094. IDD_SD2EDITNAME, IDH_DIALER_SPEED_NAME,
  2095. IDD_SD2TEXTNUMBER, IDH_DIALER_SPEED_NUMBER,
  2096. IDD_SD2EDITNUMBER, IDH_DIALER_SPEED_NUMBER,
  2097. 0, 0
  2098. };
  2099. switch(msg)
  2100. {
  2101. case WM_HELP:
  2102. // processes clicks on controls when
  2103. // context mode help is selected
  2104. WinHelp (
  2105. ((LPHELPINFO)lParam)->hItemHandle,
  2106. gszHELPfilename,
  2107. HELP_WM_HELP,
  2108. (ULONG_PTR)aMenuHelpIDs
  2109. );
  2110. return TRUE;
  2111. case WM_CONTEXTMENU:
  2112. // processes right-clicks on controls
  2113. WinHelp (
  2114. (HWND)wParam,
  2115. gszHELPfilename,
  2116. HELP_CONTEXTMENU,
  2117. (ULONG_PTR)aMenuHelpIDs
  2118. );
  2119. return TRUE;
  2120. case WM_INITDIALOG:
  2121. {
  2122. TCHAR szFieldName [MAXBUFSIZE];
  2123. TCHAR szName [TAPIMAXCALLEDPARTYSIZE] = {0};
  2124. HKEY hKey = NULL;
  2125. DWORD dwSize;
  2126. nCurrentSpeedDial = LOWORD( lParam ) - IDD_DSPEEDDIAL1 + 1;
  2127. // retrieve speed dial button info
  2128. RegOpenKeyEx (DIALER_REGISTRY_ROOT, DIALER_REGISTRY_PATH, 0, KEY_READ, &hKey);
  2129. wsprintf(szFieldName, TEXT("Name%d"), nCurrentSpeedDial);
  2130. dwSize = sizeof (szName);
  2131. RegQueryValueEx (hKey, szFieldName, NULL, NULL, (LPBYTE)szName, &dwSize);
  2132. RegCloseKey (hKey);
  2133. SetDlgItemText (
  2134. hwnd,
  2135. IDD_SD2EDITNAME,
  2136. szName
  2137. );
  2138. SetDlgItemText (
  2139. hwnd,
  2140. IDD_SD2EDITNUMBER,
  2141. gszSDNumber[nCurrentSpeedDial]
  2142. );
  2143. // limit the lengths of the texts
  2144. SendDlgItemMessage (
  2145. hwnd,
  2146. IDD_SD2EDITNAME,
  2147. EM_LIMITTEXT,
  2148. (WPARAM)(TAPIMAXCALLEDPARTYSIZE - 1),
  2149. 0
  2150. );
  2151. SendDlgItemMessage (
  2152. hwnd,
  2153. IDD_SD2EDITNUMBER,
  2154. EM_LIMITTEXT,
  2155. (WPARAM)(TAPIMAXDESTADDRESSSIZE - 1),
  2156. 0
  2157. );
  2158. SetFocus( GetDlgItem( hwnd, IDD_SD2EDITNAME ) );
  2159. SendDlgItemMessage (
  2160. hwnd,
  2161. IDD_SD2EDITNAME,
  2162. EM_SETSEL,
  2163. 0,
  2164. MAKELPARAM(0, -1)
  2165. );
  2166. return FALSE;
  2167. }
  2168. case WM_COMMAND:
  2169. {
  2170. TCHAR szName[ TAPIMAXDESTADDRESSSIZE ];
  2171. TCHAR szTemp[ TAPIMAXCALLEDPARTYSIZE ];
  2172. TCHAR szFieldName[MAXBUFSIZE];
  2173. TCHAR *p;
  2174. switch ( LOWORD( (DWORD) wParam ) )
  2175. {
  2176. case IDOK:
  2177. case IDD_SD2SAVEANDDIAL:
  2178. {
  2179. HKEY hKey = NULL;
  2180. RegCreateKeyEx (DIALER_REGISTRY_ROOT, DIALER_REGISTRY_PATH, 0, NULL, REG_OPTION_NON_VOLATILE, KEY_WRITE, NULL, &hKey, NULL);
  2181. GetDlgItemText (
  2182. hwnd,
  2183. IDD_SD2EDITNUMBER,
  2184. (LPTSTR) szName,
  2185. TAPIMAXDESTADDRESSSIZE
  2186. );
  2187. for (p = szName; *p == TEXT(' '); p++);
  2188. if (0 == *p)
  2189. {
  2190. wsprintf (szFieldName, TEXT("Name%d"), nCurrentSpeedDial);
  2191. RegDeleteValue (hKey, szFieldName);
  2192. wsprintf (szFieldName, TEXT("Number%d"), nCurrentSpeedDial);
  2193. RegDeleteValue (hKey, szFieldName);
  2194. }
  2195. else
  2196. {
  2197. lstrcpyn (gszSDNumber[nCurrentSpeedDial], p,
  2198. sizeof(gszSDNumber[nCurrentSpeedDial])/sizeof(TCHAR));
  2199. GetDlgItemText (
  2200. hwnd,
  2201. IDD_SD2EDITNAME,
  2202. szName,
  2203. TAPIMAXCALLEDPARTYSIZE
  2204. );
  2205. for (p = szName; *p == TEXT(' '); p++);
  2206. wsprintf ( szFieldName, TEXT("Name%d"), nCurrentSpeedDial );
  2207. RegSetValueEx (hKey, szFieldName, 0, REG_SZ, (LPBYTE)p, (lstrlen(p)+1)*sizeof(TCHAR));
  2208. wsprintf ( szFieldName, TEXT("Number%d"), nCurrentSpeedDial );
  2209. RegSetValueEx (hKey, szFieldName, 0, REG_SZ,
  2210. (LPBYTE)(gszSDNumber[nCurrentSpeedDial]),
  2211. (lstrlen(gszSDNumber[nCurrentSpeedDial])+1)*sizeof(TCHAR));
  2212. // update main window buttons
  2213. // is only number has been entered, label button with it.
  2214. if ( *p == TEXT('\0') )
  2215. {
  2216. lstrcpyn( szName, gszSDNumber[ nCurrentSpeedDial ], sizeof(szName)/sizeof(szName[0]) );
  2217. p = szName;
  2218. }
  2219. FitTextToButton (
  2220. ghWndMain,
  2221. IDD_DSPEEDDIAL1 + nCurrentSpeedDial - 1,
  2222. p
  2223. );
  2224. AmpersandCompensate( p, szTemp );
  2225. SetDlgItemText (
  2226. ghWndMain,
  2227. IDD_DSPEEDDIAL1 + nCurrentSpeedDial - 1,
  2228. szTemp
  2229. );
  2230. // if save and dial, then post dial message to main window
  2231. if ( LOWORD( (DWORD) wParam ) == IDD_SD2SAVEANDDIAL )
  2232. {
  2233. PostMessage (
  2234. ghWndMain,
  2235. WM_COMMAND,
  2236. MAKEWPARAM (
  2237. nCurrentSpeedDial + IDD_DSPEEDDIAL1 - 1,
  2238. BN_CLICKED
  2239. ),
  2240. (LPARAM) GetDlgItem (
  2241. ghWndMain,
  2242. nCurrentSpeedDial + IDD_DSPEEDDIAL1 - 1
  2243. )
  2244. );
  2245. }
  2246. }
  2247. RegCloseKey (hKey);
  2248. EndDialog(hwnd, TRUE);
  2249. return TRUE;
  2250. }
  2251. case IDCANCEL:
  2252. EndDialog(hwnd, FALSE);
  2253. return TRUE;
  2254. case IDD_SD2EDITNAME:
  2255. case IDD_SD2EDITNUMBER:
  2256. if ( HIWORD( wParam ) == EN_CHANGE)
  2257. {
  2258. EnableWindow (
  2259. GetDlgItem( hwnd, IDD_SD2SAVEANDDIAL ),
  2260. GetWindowTextLength ( GetDlgItem( hwnd, IDD_SD2EDITNUMBER ) ) > 0
  2261. );
  2262. }
  2263. break;
  2264. } // switch(LOWORD((DWORD)wParam))
  2265. break;
  2266. }
  2267. default:
  2268. ;
  2269. } // switch(msg)
  2270. return FALSE;
  2271. }
  2272. //***************************************************************************
  2273. //***************************************************************************
  2274. //***************************************************************************
  2275. VOID CALLBACK
  2276. tapiCallback (
  2277. DWORD hDevice,
  2278. DWORD dwMsg,
  2279. DWORD dwCBInstance,
  2280. DWORD dwParam1,
  2281. DWORD dwParam2,
  2282. DWORD dwParam3
  2283. )
  2284. {
  2285. switch (dwMsg)
  2286. {
  2287. INT errCode;
  2288. case LINE_ADDRESSSTATE:
  2289. break;
  2290. case LINE_CALLINFO:
  2291. break;
  2292. case LINE_CALLSTATE:
  2293. if ( (HCALL)hDevice != ghCall )
  2294. return;
  2295. switch ( dwParam1 ) // new state
  2296. {
  2297. case LINECALLSTATE_IDLE:
  2298. // tell "Dialing" window to terminate
  2299. if ( ghWndDialing )
  2300. {
  2301. SendMessage (
  2302. ghWndDialing,
  2303. WM_COMMAND,
  2304. MAKEWPARAM( IDOK, 0 ),
  2305. 0
  2306. );
  2307. }
  2308. // tapi call cleanup
  2309. if ( !gfMakeCallReplyPending && ghCall )
  2310. {
  2311. if ( ( errCode = lineDeallocateCall( ghCall ) ) < 0 )
  2312. {
  2313. errString ( ghWndMain, errCode, MB_ICONSTOP | MB_OK );
  2314. }
  2315. ghCall = 0;
  2316. }
  2317. DialerLineClose();
  2318. gfCurrentLineAvail = TRUE;
  2319. // update main window
  2320. DisableDialButtons( FALSE );
  2321. break;
  2322. case LINECALLSTATE_BUSY:
  2323. tapiCallback (
  2324. hDevice,
  2325. dwMsg,
  2326. dwCBInstance,
  2327. LINECALLSTATE_DISCONNECTED,
  2328. LINEDISCONNECTMODE_BUSY,
  2329. dwParam3
  2330. );
  2331. break;
  2332. case LINECALLSTATE_SPECIALINFO:
  2333. tapiCallback (
  2334. hDevice,
  2335. dwMsg,
  2336. dwCBInstance,
  2337. LINECALLSTATE_DISCONNECTED,
  2338. LINEDISCONNECTMODE_UNREACHABLE,
  2339. dwParam3
  2340. );
  2341. break;
  2342. case LINECALLSTATE_DISCONNECTED:
  2343. {
  2344. BOOL fCallOK;
  2345. DWORD LineDisconnectMode;
  2346. if ( dwParam2 == 0 )
  2347. LineDisconnectMode = LINEDISCONNECTMODE_NORMAL;
  2348. else
  2349. LineDisconnectMode = dwParam2;
  2350. fCallOK = ( LineDisconnectMode == LINEDISCONNECTMODE_NORMAL ||
  2351. LineDisconnectMode == LINEDISCONNECTMODE_UNKNOWN ||
  2352. LineDisconnectMode == LINEDISCONNECTMODE_PICKUP ||
  2353. LineDisconnectMode == LINEDISCONNECTMODE_FORWARDED ||
  2354. LineDisconnectMode == LINEDISCONNECTMODE_UNAVAIL
  2355. );
  2356. if ( !gfMakeCallReplyPending && ghCall )
  2357. {
  2358. //gfDropping = TRUE;
  2359. if ( ( gDropCallRequestID = lineDrop ( ghCall, NULL, 0 ) ) < 0 )
  2360. {
  2361. errString ( ghWndMain, gDropCallRequestID, MB_ICONSTOP | MB_OK );
  2362. }
  2363. }
  2364. if ( !fCallOK )
  2365. DialogBoxParam (
  2366. ghInst,
  2367. MAKEINTRESOURCE(IDD_CALLFAILED),
  2368. ghWndMain,
  2369. LineInUseProc,
  2370. LineDisconnectMode
  2371. );
  2372. break;
  2373. }
  2374. }
  2375. break;
  2376. case LINE_CLOSE:
  2377. if ( gCurrentLineInfo.hLine == (HLINE)hDevice )
  2378. {
  2379. errString(ghWndMain, ERR_LINECLOSE, MB_ICONEXCLAMATION | MB_OK );
  2380. gCurrentLineInfo.hLine = 0;
  2381. gfCurrentLineAvail = FALSE;
  2382. DisableDialButtons(FALSE);
  2383. }
  2384. break;
  2385. case LINE_CREATE:
  2386. // dwParam1 is the new device's ID
  2387. if ( dwParam1 >= gnAvailDevices )
  2388. {
  2389. DWORD* gnAddrTemp;
  2390. DWORD iLine;
  2391. LINEINFO LineInfo;
  2392. // we record new device's address count.
  2393. // we are assuming here that we're just adding a new
  2394. // line and it's sequential and it's the last one
  2395. gnAvailDevices = dwParam1 + 1;
  2396. gnAddrTemp = (DWORD *) DialerAlloc ( sizeof(DWORD) * (int)(gnAvailDevices) );
  2397. for ( iLine = 0; iLine < (gnAvailDevices-1); ++iLine )
  2398. gnAddrTemp[iLine] = gnAddr[iLine];
  2399. DialerFree( gnAddr );
  2400. // we have effectively added one more
  2401. // space in the gnAddr array
  2402. gnAddr = gnAddrTemp;
  2403. if ( GetLineInfo( dwParam1, &LineInfo ) != ERR_NONE )
  2404. break;
  2405. gnAddr[dwParam1] = LineInfo.nAddr;
  2406. }
  2407. break;
  2408. case LINE_DEVSPECIFIC:
  2409. break;
  2410. case LINE_DEVSPECIFICFEATURE:
  2411. break;
  2412. case LINE_GATHERDIGITS:
  2413. break;
  2414. case LINE_GENERATE:
  2415. break;
  2416. case LINE_LINEDEVSTATE:
  2417. if ( dwParam1 & LINEDEVSTATE_REINIT )
  2418. {
  2419. if(dwParam2 != 0)
  2420. {
  2421. // this is another msg translated into REINIT
  2422. tapiCallback( hDevice, dwParam2, dwCBInstance, dwParam3, 0, 0 );
  2423. }
  2424. else
  2425. {
  2426. // Re-initialize TAPI
  2427. gfNeedToReinit = TRUE;
  2428. }
  2429. }
  2430. if ( dwParam1 & LINEDEVSTATE_REMOVED )
  2431. {
  2432. DialerLineClose();
  2433. tapiCallback(hDevice, LINE_CLOSE, dwCBInstance, 0, 0, 0); // is this needed?
  2434. }
  2435. break;
  2436. case LINE_MONITORDIGITS:
  2437. break;
  2438. case LINE_MONITORMEDIA:
  2439. break;
  2440. case LINE_MONITORTONE:
  2441. break;
  2442. // async reply from lineMakeCall() or lineDrop()
  2443. case LINE_REPLY:
  2444. // reply for lineMakeCall
  2445. if ( (LONG) dwParam1 == gMakeCallRequestID )
  2446. {
  2447. // error on make call
  2448. if ( dwParam2 != ERR_NONE )
  2449. {
  2450. // Get rid of the Dialing Dialog box if it's up
  2451. if ( ghWndDialing )
  2452. {
  2453. SendMessage(
  2454. ghWndDialing,
  2455. WM_COMMAND,
  2456. MAKEWPARAM(IDOK,0),
  2457. 0
  2458. );
  2459. }
  2460. if ( dwParam2 == LINEERR_CALLUNAVAIL )
  2461. {
  2462. DialogBoxParam (
  2463. ghInst,
  2464. MAKEINTRESOURCE(IDD_CALLFAILED),
  2465. ghWndMain,
  2466. LineInUseProc,
  2467. 0
  2468. );
  2469. }
  2470. else
  2471. {
  2472. errString ( ghWndMain, dwParam2, MB_ICONEXCLAMATION | MB_OK );
  2473. }
  2474. ghCall = 0;
  2475. DialerLineClose();
  2476. gfCurrentLineAvail = TRUE;
  2477. }
  2478. gfMakeCallReplyPending = FALSE;
  2479. }
  2480. // reply from lineDrop()
  2481. if ( (LONG) dwParam1 == gDropCallRequestID )
  2482. {
  2483. // tell "Dialing" window to terminate
  2484. if ( ghWndDialing )
  2485. {
  2486. SendMessage (
  2487. ghWndDialing,
  2488. WM_COMMAND,
  2489. MAKEWPARAM( IDOK,0 ),
  2490. 0
  2491. );
  2492. }
  2493. // tapi call cleanup
  2494. if ( dwParam2 == ERR_NONE )
  2495. {
  2496. if ( !gfMakeCallReplyPending && ghCall )
  2497. {
  2498. if ( ( errCode = lineDeallocateCall( ghCall ) ) < 0 )
  2499. {
  2500. errString ( ghWndMain, errCode, MB_ICONSTOP | MB_OK );
  2501. }
  2502. ghCall = 0;
  2503. }
  2504. }
  2505. DialerLineClose ();
  2506. gfCurrentLineAvail = TRUE;
  2507. }
  2508. break;
  2509. case LINE_REQUEST:
  2510. // Simple TAPI request
  2511. if ( dwParam1 == LINEREQUESTMODE_MAKECALL )
  2512. {
  2513. gfCallRequest = TRUE;
  2514. }
  2515. break;
  2516. }
  2517. }
  2518. //***************************************************************************
  2519. //***************************************************************************
  2520. //***************************************************************************
  2521. BOOL InitializeLineBox(HWND hwndLineBox)
  2522. {
  2523. DWORD iLine, iItem, iItemCurrent = (DWORD)-1;
  2524. DWORD errCode;
  2525. LPLINEINFO lpLineInfo = NULL;
  2526. // allocate buffer for storing LINEINFO for all of
  2527. // the available lines. Always allocate space for
  2528. // at least one line
  2529. if ( gnAvailDevices == 0 )
  2530. {
  2531. lpLineInfo = (LPLINEINFO) DialerAlloc( sizeof(LINEINFO) );
  2532. }
  2533. else
  2534. {
  2535. lpLineInfo = (LPLINEINFO) DialerAlloc ( sizeof(LINEINFO) * (int)gnAvailDevices );
  2536. }
  2537. // if no space was set aside...
  2538. if ( lpLineInfo == NULL )
  2539. return LINEERR_NOMEM;
  2540. // fill lpLineInfo[] and open each line
  2541. for ( iLine = 0; iLine < gnAvailDevices; ++iLine )
  2542. {
  2543. // skip remaining processing for this line if it didn't open
  2544. if ( GetLineInfo( iLine, &lpLineInfo[iLine] ) != ERR_NONE )
  2545. {
  2546. continue;
  2547. }
  2548. iItem = (int) SendMessage (
  2549. hwndLineBox,
  2550. CB_ADDSTRING,
  2551. 0,
  2552. (LPARAM)(lpLineInfo[iLine].szLineName)
  2553. );
  2554. // error, bail out.
  2555. if ( iItem == CB_ERR || iItem == CB_ERRSPACE )
  2556. {
  2557. if (lpLineInfo)
  2558. {
  2559. DialerFree(lpLineInfo);
  2560. }
  2561. return FALSE;
  2562. }
  2563. errCode = (int) SendMessage (
  2564. hwndLineBox,
  2565. CB_SETITEMDATA,
  2566. (WPARAM)iItem,
  2567. (LPARAM)iLine
  2568. );
  2569. if ( iLine == giCurrentLine )
  2570. {
  2571. iItemCurrent = iItem;
  2572. }
  2573. else if ( iItemCurrent != -1 && iItem <= iItemCurrent )
  2574. {
  2575. // if the item we are putting is before the
  2576. // "current" item, we must increment iItemCurrent
  2577. // to reflect that something is being placed before
  2578. // it, due to sorting
  2579. ++iItemCurrent;
  2580. }
  2581. }
  2582. if ( iItemCurrent == (DWORD)-1 )
  2583. iItemCurrent = 0;
  2584. if ( SendMessage( hwndLineBox, CB_GETCOUNT, 0, 0) != 0 )
  2585. {
  2586. SendMessage( hwndLineBox, CB_SETCURSEL, (WPARAM)iItemCurrent, 0 );
  2587. return TRUE;
  2588. }
  2589. DialerFree(lpLineInfo);
  2590. return FALSE;
  2591. }
  2592. //***************************************************************************
  2593. //***************************************************************************
  2594. //***************************************************************************
  2595. BOOL InitializeAddressBox( HWND hwndLineBox, HWND hwndAddressBox )
  2596. {
  2597. DWORD errCode;
  2598. DWORD iAddress, iItem, iItemCurrent = (DWORD)-1;
  2599. DWORD iLineBoxCurrent;
  2600. LPTSTR pszAddressName;
  2601. if ( SendMessage( hwndLineBox, CB_GETCOUNT, 0, 0 ) == 0 )
  2602. {
  2603. return FALSE;
  2604. }
  2605. // select current entry in line box
  2606. iLineBoxCurrent = (int) SendMessage (
  2607. hwndLineBox,
  2608. CB_GETITEMDATA,
  2609. SendMessage( hwndLineBox, CB_GETCURSEL, 0, 0 ),
  2610. 0
  2611. );
  2612. // empty address list box
  2613. SendMessage ( hwndAddressBox, CB_RESETCONTENT, 0, 0);
  2614. // get all the address for this line
  2615. for ( iAddress = 0; iAddress < gnAddr[iLineBoxCurrent]; ++iAddress )
  2616. {
  2617. pszAddressName = GetAddressName (iLineBoxCurrent, iAddress );
  2618. // if this address if fails, try the next one
  2619. if ( !pszAddressName )
  2620. continue;
  2621. iItem = (int) SendMessage (
  2622. hwndAddressBox,
  2623. CB_ADDSTRING,
  2624. 0,
  2625. (LPARAM)pszAddressName
  2626. );
  2627. // error, bail out
  2628. if ( iItem == CB_ERR || iItem == CB_ERRSPACE )
  2629. return FALSE;
  2630. errCode = (int)SendMessage (
  2631. hwndAddressBox,
  2632. CB_SETITEMDATA,
  2633. (WPARAM) iItem,
  2634. (LPARAM) iAddress
  2635. );
  2636. if ( iLineBoxCurrent == giCurrentLine )
  2637. {
  2638. if(iAddress == giCurrentAddress)
  2639. {
  2640. iItemCurrent = iItem;
  2641. }
  2642. else
  2643. {
  2644. // if the item we are putting is before the
  2645. // "current" item, we must increment iItemCur
  2646. // to reflect that something is being placed
  2647. // before it, due to sorting
  2648. if ( iItemCurrent != -1 && iItem <= iItemCurrent )
  2649. {
  2650. ++iItemCurrent;
  2651. }
  2652. }
  2653. }
  2654. DialerFree( pszAddressName );
  2655. }
  2656. if ( iLineBoxCurrent != giCurrentLine )
  2657. {
  2658. // if we're not looking at the current line
  2659. // then highlight address 0
  2660. iItemCurrent = 0;
  2661. }
  2662. SendMessage (
  2663. hwndAddressBox,
  2664. CB_SETCURSEL,
  2665. iItemCurrent,
  2666. 0
  2667. );
  2668. return TRUE;
  2669. }
  2670. //***************************************************************************
  2671. //***************************************************************************
  2672. //***************************************************************************
  2673. VOID ManageAssistedTelephony(VOID)
  2674. {
  2675. DWORD errCode;
  2676. LINEREQMAKECALL *lpRequestBuffer;
  2677. lpRequestBuffer = (LINEREQMAKECALL*) DialerAlloc( sizeof( LINEREQMAKECALL ) );
  2678. if ( !lpRequestBuffer )
  2679. {
  2680. goto error;
  2681. }
  2682. // bring window to front
  2683. SetForegroundWindow(ghWndMain);
  2684. // get next queued request.
  2685. errCode = lineGetRequest (
  2686. ghLineApp,
  2687. LINEREQUESTMODE_MAKECALL,
  2688. lpRequestBuffer
  2689. );
  2690. if ( errCode )
  2691. {
  2692. // if no more call requests pending, reset flag.
  2693. if ( errCode == LINEERR_NOREQUEST )
  2694. {
  2695. gfCallRequest = FALSE;
  2696. }
  2697. else
  2698. {
  2699. errString ( ghWndMain, errCode, MB_ICONEXCLAMATION | MB_OK );
  2700. }
  2701. goto error;
  2702. }
  2703. // if a line has not been selected
  2704. if ( giCurrentLine == (DWORD)-1 )
  2705. {
  2706. if (!DialogBoxParam (
  2707. ghInst,
  2708. MAKEINTRESOURCE(IDD_CONNECTUSING),
  2709. ghWndMain,
  2710. ConnectUsingProc,
  2711. INVALID_LINE
  2712. ))
  2713. {
  2714. // failed to get a line
  2715. goto error;
  2716. }
  2717. }
  2718. // make the reuested call.
  2719. InitiateCall (
  2720. lpRequestBuffer->szDestAddress,
  2721. lpRequestBuffer->szCalledParty
  2722. );
  2723. error :
  2724. if ( lpRequestBuffer )
  2725. {
  2726. DialerFree( lpRequestBuffer );
  2727. }
  2728. return;
  2729. }
  2730. //***************************************************************************
  2731. //***************************************************************************
  2732. //***************************************************************************
  2733. VOID DialerLineClose()
  2734. {
  2735. DWORD errCode;
  2736. if ( gCurrentLineInfo.hLine )
  2737. {
  2738. if ( errCode = lineClose ( gCurrentLineInfo.hLine ) )
  2739. {
  2740. errString ( ghWndMain, errCode, MB_ICONSTOP | MB_OK );
  2741. }
  2742. gCurrentLineInfo.hLine = 0;
  2743. }
  2744. // re-initialize TAPI if it needs to be re-initialized
  2745. if ( gfNeedToReinit )
  2746. {
  2747. CloseTAPI();
  2748. errCode = InitializeTAPI();
  2749. if(errCode)
  2750. {
  2751. errString(ghWndMain, errCode, MB_APPLMODAL | MB_ICONEXCLAMATION );
  2752. DialerCleanup(); // terminate program if we can't init
  2753. return;
  2754. }
  2755. errCode = lineRegisterRequestRecipient (
  2756. ghLineApp,
  2757. 0,
  2758. LINEREQUESTMODE_MAKECALL,
  2759. TRUE
  2760. );
  2761. if (errCode)
  2762. {
  2763. errString(ghWndMain, errCode, MB_ICONEXCLAMATION | MB_OK );
  2764. }
  2765. gfNeedToReinit = FALSE;
  2766. }
  2767. }
  2768. //***************************************************************************
  2769. //***************************************************************************
  2770. //***************************************************************************
  2771. int errString( HWND hWndOwner, UINT errCode, UINT uFlags )
  2772. {
  2773. PTSTR ptStrTitle;
  2774. PTSTR ptStrError;
  2775. int nResult;
  2776. BOOL bDefault = FALSE;
  2777. ptStrTitle = DialerAlloc( MAXBUFSIZE*sizeof(TCHAR) );
  2778. if ( NULL == ptStrTitle )
  2779. {
  2780. // Now, _this_ is a problem.
  2781. return 0;
  2782. }
  2783. ptStrError = DialerAlloc( MAXBUFSIZE*sizeof(TCHAR) );
  2784. if ( NULL == ptStrError )
  2785. {
  2786. // Now, _this_ is a problem.
  2787. DialerFree( ptStrTitle);
  2788. return 0;
  2789. }
  2790. switch(errCode)
  2791. {
  2792. case ERR_NOLINES:
  2793. errCode = ikszErrNoVoiceLine;
  2794. break;
  2795. case ERR_NOVOICELINE:
  2796. errCode = ikszErrNoVoiceLine;
  2797. break;
  2798. case ERR_LINECLOSE:
  2799. errCode = ikszErrLineClose;
  2800. break;
  2801. case ERR_911WARN:
  2802. errCode = ikszWarningFor911;
  2803. break;
  2804. case ERR_NEWDEFAULT:
  2805. errCode = ikszWarningNewDefault;
  2806. break;
  2807. case LINEERR_NODRIVER:
  2808. errCode = ikszErrLineInitNoDriver;
  2809. break;
  2810. case LINEERR_NODEVICE:
  2811. errCode = ikszErrLineInitNoDevice;
  2812. break;
  2813. case LINEERR_INIFILECORRUPT:
  2814. errCode = ikszErrLineInitBadIniFile ;
  2815. break;
  2816. case LINEERR_NOMEM:
  2817. errCode = ikszErrOOM;
  2818. break;
  2819. case LINEERR_INCOMPATIBLEAPIVERSION:
  2820. errCode = ikszErrLineInitWrongDrivers ;
  2821. break;
  2822. case LINEERR_OPERATIONFAILED:
  2823. errCode = ikszErrTAPI;
  2824. break;
  2825. case LINEERR_INVALADDRESS:
  2826. errCode = ikszErrInvalAddress;
  2827. break;
  2828. case LINEERR_ADDRESSBLOCKED:
  2829. errCode = ikszErrAddrBlocked;
  2830. break;
  2831. case LINEERR_BILLINGREJECTED:
  2832. errCode = ikszErrBillingRejected;
  2833. break;
  2834. case LINEERR_RESOURCEUNAVAIL:
  2835. case LINEERR_ALLOCATED:
  2836. case LINEERR_INUSE:
  2837. errCode = ikszErrResUnavail;
  2838. break;
  2839. case LINEERR_NOMULTIPLEINSTANCE:
  2840. errCode = ikszErrNoMultipleInstance;
  2841. break;
  2842. case LINEERR_INVALCALLSTATE:
  2843. errCode = ikszErrInvalCallState;
  2844. break;
  2845. case LINEERR_INVALCOUNTRYCODE:
  2846. errCode = ikszErrInvalidCountryCode;
  2847. break;
  2848. case LINEERR_INVALCALLPARAMS:
  2849. errCode = ikszDisconnectedCantDo;
  2850. break;
  2851. default:
  2852. bDefault = TRUE;
  2853. break;
  2854. }
  2855. if (bDefault)
  2856. {
  2857. // if using default error, get TAPI's
  2858. // error message from FormatError()
  2859. if (!FormatMessage(FORMAT_MESSAGE_FROM_HMODULE,
  2860. (LPCVOID)GetModuleHandle(TEXT("TAPI32.DLL")),
  2861. (DWORD)TAPIERROR_FORMATMESSAGE(errCode),
  2862. 0,
  2863. (LPTSTR)ptStrError,
  2864. MAXBUFSIZE,
  2865. NULL))
  2866. {
  2867. // if this fails, fall back on default
  2868. LoadString( ghInst, ikszErrDefault, ptStrError, MAXBUFSIZE);
  2869. }
  2870. }
  2871. else // not the default error message
  2872. {
  2873. if ( 0 == LoadString( ghInst, errCode, ptStrError, MAXBUFSIZE ) )
  2874. {
  2875. LoadString( ghInst, ikszErrDefault, ptStrError, MAXBUFSIZE );
  2876. }
  2877. }
  2878. LoadString( ghInst, ikszWarningTitle, ptStrTitle, MAXBUFSIZE );
  2879. nResult = MessageBox( hWndOwner, ptStrError, ptStrTitle, uFlags );
  2880. DialerFree( ptStrTitle );
  2881. DialerFree( ptStrError );
  2882. return nResult;
  2883. }
  2884. /*
  2885. * Name :
  2886. * FitTextToButton
  2887. *
  2888. * Arguements :
  2889. * hDlg handle for the dialog in which this button is embedded
  2890. * nButtonID button id of this button
  2891. * szName Name to fit on the button. Max size TAPIMAXCALLEDPARTYSIZE
  2892. *
  2893. * Return :
  2894. * None
  2895. *
  2896. * Comments :
  2897. * Function first checks to see if the button text specified fits in the
  2898. * button. If it does not it truncates it appropriately and adds trailing
  2899. * ellipses.
  2900. */
  2901. VOID FitTextToButton ( HWND hDlg, INT nButtonID, LPTSTR szName )
  2902. {
  2903. HDC hDC;
  2904. HFONT hFont, hOldFont;
  2905. HWND hWnd;
  2906. do
  2907. {
  2908. // calculate number of chars. that can fit on
  2909. // the button
  2910. int nLen;
  2911. RECT rect;
  2912. SIZE size;
  2913. POINT pt;
  2914. TCHAR buf [TAPIMAXCALLEDPARTYSIZE + 1];
  2915. // get button dimensions
  2916. hWnd = GetDlgItem( hDlg, nButtonID );
  2917. if ( hWnd == NULL )
  2918. break;
  2919. if ( !GetClientRect( hWnd, &rect ) )
  2920. break;
  2921. // get character dimensions
  2922. hDC = GetDC( hWnd );
  2923. if ( hDC == NULL )
  2924. break;
  2925. hFont = (HFONT) SendMessage( hWnd, WM_GETFONT, 0, 0 );
  2926. if ( hFont == NULL )
  2927. hOldFont = SelectObject( hDC, GetStockObject( SYSTEM_FONT ) );
  2928. else
  2929. hOldFont = SelectObject( hDC, hFont );
  2930. // add an extra char at the end to compensate for
  2931. // leading space,
  2932. lstrcpy ( buf, szName );
  2933. nLen = lstrlen( buf );
  2934. buf [ nLen ] = TEXT('X');
  2935. buf [ nLen + 1 ] = TEXT('\0');
  2936. if ( !GetTextExtentPoint32( hDC, buf, nLen + 1, &size ) )
  2937. break;
  2938. pt.x = size.cx;
  2939. if ( !LPtoDP( hDC, &pt, 1 ) )
  2940. break;
  2941. // check if name fits on button
  2942. if ( pt.x > rect.right )
  2943. {
  2944. // find how much of the name fits
  2945. int i = 0;
  2946. nLen = lstrlen( szName );
  2947. for ( i = 0; i < nLen; i++ )
  2948. {
  2949. buf[ i ] = szName[ i ];
  2950. // an extra char is stuffed to compensate for the
  2951. // leading space left by the left alignment
  2952. buf [ i + 1 ] = TEXT('X');
  2953. buf [ i + 2 ] = TEXT('\0');
  2954. // break out in cases of error condition
  2955. if ( !GetTextExtentPoint32( hDC, buf, i + 2, &size ) )
  2956. {
  2957. i = nLen;
  2958. break;
  2959. }
  2960. pt.x = size.cx;
  2961. if ( !LPtoDP( hDC, &pt, 1 ) )
  2962. {
  2963. i = nLen;
  2964. break;
  2965. }
  2966. if ( pt.x > rect.right )
  2967. break;
  2968. }
  2969. // error
  2970. if ( i >= nLen )
  2971. break;
  2972. // name is too long. truncate and add ellipses
  2973. szName [i - 3] = TEXT('\0');
  2974. lstrcat( szName, TEXT("...") );
  2975. }
  2976. } while( FALSE );
  2977. if ( hDC )
  2978. {
  2979. SelectObject( hDC, hOldFont );
  2980. ReleaseDC( hWnd, hDC );
  2981. }
  2982. return;
  2983. }
  2984. /*
  2985. * Name :
  2986. * Is911
  2987. *
  2988. * Arguements :
  2989. * lpTransOut - Translated address contained the dialable string
  2990. *
  2991. * Returns
  2992. * TRUE - If number to be dialed (in the US) is prefixed by 911
  2993. * FALSE - Otherwise
  2994. *
  2995. * Comments
  2996. *
  2997. */
  2998. BOOL Is911 ( LPLINETRANSLATEOUTPUT lpTransOut )
  2999. {
  3000. DWORD i = 0, j = 0;
  3001. LPTSTR lpDialDigits = (LPTSTR)((char*)lpTransOut + lpTransOut-> dwDialableStringOffset);
  3002. TCHAR sz3Pref [ 4 ] = TEXT("");
  3003. // if this is not the US
  3004. if ( lpTransOut-> dwCurrentCountry != 1 )
  3005. return FALSE;
  3006. // skip non digit characters and extract
  3007. // the first 3 digits in the dialable number
  3008. for ( i = 0, j = 0; i < lpTransOut-> dwDialableStringSize ; i++ )
  3009. {
  3010. if ( ISDIGIT( lpDialDigits[i] ) )
  3011. {
  3012. sz3Pref[ j++ ] = lpDialDigits [ i ];
  3013. sz3Pref[ j ] = TEXT('\0');
  3014. if ( j == 3 )
  3015. break;
  3016. }
  3017. }
  3018. if ( !lstrcmp( sz3Pref, TEXT("911") ) )
  3019. {
  3020. return TRUE;
  3021. }
  3022. return FALSE;
  3023. }
  3024. /*
  3025. * Name :
  3026. * MakeCanonicalNumber
  3027. *
  3028. * Arguements :
  3029. * szNumber Number to convert into canonical form. Max size TAPIMAXDESTADDRESSSIZE
  3030. * szCanNumber Canonical representation of number specified in szNumber
  3031. *
  3032. * Return :
  3033. * TRUE If the conversion was successful.
  3034. * FALSE otherwise
  3035. *
  3036. * Comments :
  3037. * Function first checks if given number is already in canonical form.
  3038. * If it is, it returns. If it is not, then it performs the conversion.
  3039. */
  3040. BOOL MakeCanonicalNumber ( LPCTSTR szNumber, LPTSTR szCanNumber )
  3041. {
  3042. TCHAR szDigits [ TAPIMAXDESTADDRESSSIZE ];
  3043. TCHAR szPref [ TAPIMAXDESTADDRESSSIZE ];
  3044. BOOL bRes = FALSE;
  3045. BOOL bTryAgain = TRUE;
  3046. INT errCode = -1;
  3047. INT nLenPref, nLenDigits, cPos, i;
  3048. DWORD dwSize = 0;
  3049. DWORD dwInd = 0;
  3050. LPLINETRANSLATEOUTPUT lpTransOut = NULL;
  3051. LPLINETRANSLATECAPS lpTransCaps = NULL;
  3052. dwSize = sizeof ( LINETRANSLATEOUTPUT );
  3053. do
  3054. {
  3055. lpTransOut = ( LPLINETRANSLATEOUTPUT ) DialerAlloc ( dwSize );
  3056. if ( !lpTransOut )
  3057. {
  3058. errString( ghWndMain, LINEERR_NOMEM, MB_ICONSTOP | MB_OK );
  3059. goto error;
  3060. }
  3061. while (TRUE)
  3062. {
  3063. lpTransOut-> dwTotalSize = dwSize;
  3064. errCode = lineTranslateAddress (
  3065. ghLineApp,
  3066. giCurrentLine,
  3067. gCurrentLineInfo.dwAPIVersion,
  3068. szNumber,
  3069. 0,
  3070. 0,
  3071. lpTransOut
  3072. );
  3073. if ( (LINEERR_INIFILECORRUPT != errCode) ||
  3074. (FALSE == bTryAgain) )
  3075. {
  3076. break;
  3077. }
  3078. bTryAgain = FALSE;
  3079. errCode = lineTranslateDialog (
  3080. ghLineApp,
  3081. giCurrentLine,
  3082. TAPI_VERSION_1_4,
  3083. NULL,
  3084. szNumber
  3085. );
  3086. if (NO_ERROR != errCode)
  3087. {
  3088. break;
  3089. }
  3090. }
  3091. if (errCode)
  3092. {
  3093. goto error;
  3094. }
  3095. if ( lpTransOut-> dwNeededSize <= lpTransOut-> dwTotalSize )
  3096. break;
  3097. dwSize = lpTransOut-> dwNeededSize;
  3098. DialerFree( lpTransOut );
  3099. } while (TRUE);
  3100. // check if input number is already in
  3101. // canonical form.
  3102. if ( lpTransOut-> dwTranslateResults & LINETRANSLATERESULT_CANONICAL )
  3103. goto error;
  3104. // ensure country is the USA.
  3105. if ( lpTransOut-> dwCurrentCountry != 1 )
  3106. goto error;
  3107. // Extract the digits from given string
  3108. // allowed formatting characters that are ignored are
  3109. // space, (, ), -, .
  3110. // presence of other characters will render the string invalid.
  3111. // find the prefix of the address upto the | mark.
  3112. // the rest of the string can be ignored
  3113. nLenPref = _tcscspn ( szNumber, TEXT("|") );
  3114. lstrcpyn( szPref, szNumber, nLenPref+1 );
  3115. szPref[ nLenPref ] = TEXT('\0');
  3116. // if string is not composed entirely of digits
  3117. // and allowable formating characters, quit conversion
  3118. if ( _tcsspn( szPref, TEXT(" 0123456789()-.") ) != (size_t) nLenPref )
  3119. goto error;
  3120. // collect digits ignoring formating characters.
  3121. szDigits[ 0 ] = TEXT('\0');
  3122. for ( i = 0, nLenDigits = 0; i < nLenPref; i++ )
  3123. {
  3124. if ( ISDIGIT( szNumber[ i ] ) )
  3125. {
  3126. szDigits[ nLenDigits++ ] = szNumber[ i ];
  3127. }
  3128. }
  3129. szDigits[ nLenDigits ] = TEXT('\0');
  3130. // if "internal" number
  3131. if ( nLenDigits < LOCAL_NUMBER )
  3132. goto error;
  3133. switch ( nLenDigits )
  3134. {
  3135. // Local number ( 7 digits) preceeded by a 0/1
  3136. // Strip leading 0/1 and treat as a local number
  3137. case EXTENDED_LOCAL_NUMBER:
  3138. if ( szDigits[ 0 ] == TEXT('0') || szDigits[ 0 ] == TEXT('1') )
  3139. {
  3140. nLenDigits--;
  3141. memmove( szDigits, &(szDigits[1]), nLenDigits*sizeof(TCHAR) );
  3142. szDigits[ nLenDigits ] = TEXT('\0');
  3143. cPos = _tcscspn( szPref, TEXT("01") );
  3144. nLenPref--;
  3145. memmove( &(szPref[ cPos ]), &(szPref[ cPos + 1 ]), (nLenPref - cPos)*sizeof(TCHAR) );
  3146. szPref[ nLenPref ] = TEXT('\0');
  3147. }
  3148. else
  3149. {
  3150. goto error;
  3151. }
  3152. case LOCAL_NUMBER :
  3153. {
  3154. LPLINELOCATIONENTRY lpLocLst;
  3155. // if leading digit is 0 or 1, it is
  3156. // illegal in the US
  3157. if ( szDigits[ 0 ] == TEXT('0') || szDigits[ 0 ] == TEXT('1') )
  3158. {
  3159. goto error;
  3160. }
  3161. // get area code nformation for local number
  3162. dwSize = sizeof( LINETRANSLATECAPS );
  3163. do
  3164. {
  3165. lpTransCaps = (LPLINETRANSLATECAPS) DialerAlloc( dwSize );
  3166. if ( !lpTransCaps )
  3167. {
  3168. errString( ghWndMain, LINEERR_NOMEM, MB_ICONSTOP | MB_OK );
  3169. goto error;
  3170. }
  3171. lpTransCaps-> dwTotalSize = dwSize;
  3172. errCode = lineGetTranslateCaps (
  3173. ghLineApp,
  3174. gCurrentLineInfo.dwAPIVersion,
  3175. lpTransCaps
  3176. );
  3177. if ( errCode )
  3178. {
  3179. errString( ghWndMain, errCode, MB_ICONSTOP | MB_OK );
  3180. goto error;
  3181. }
  3182. if ( lpTransCaps-> dwNeededSize <= lpTransCaps-> dwTotalSize )
  3183. {
  3184. break;
  3185. }
  3186. dwSize = lpTransCaps-> dwNeededSize;
  3187. DialerFree( lpTransCaps );
  3188. } while ( TRUE );
  3189. // skip entries till you locate information for current location
  3190. dwSize = sizeof( LINELOCATIONENTRY );
  3191. lpLocLst = (LPLINELOCATIONENTRY) ( (LPTSTR) ((char*)lpTransCaps +
  3192. lpTransCaps-> dwLocationListOffset) );
  3193. for ( dwInd = 0; dwInd < lpTransCaps-> dwNumLocations ; dwInd++ )
  3194. {
  3195. if ( lpLocLst[ dwInd ].dwPermanentLocationID == lpTransCaps-> dwCurrentLocationID )
  3196. break;
  3197. }
  3198. // current location no found ?????
  3199. // login error
  3200. if ( dwInd == lpTransCaps-> dwNumLocations )
  3201. {
  3202. goto error;
  3203. }
  3204. // construct canonical form as
  3205. szCanNumber[ 0 ]= TEXT('\0');
  3206. lstrcat( szCanNumber, TEXT("+1 (") );
  3207. lstrcat( szCanNumber, (LPTSTR) ((char*)lpTransCaps + lpLocLst[ dwInd ].dwCityCodeOffset) );
  3208. lstrcat( szCanNumber, TEXT(") ") );
  3209. lstrcat( szCanNumber, szDigits );
  3210. cPos = _tcscspn( szNumber, TEXT("|") );
  3211. if ( cPos != lstrlen( szNumber ) )
  3212. {
  3213. lstrcat( szCanNumber, &(szNumber[ cPos ]) );
  3214. }
  3215. bRes = TRUE;
  3216. break;
  3217. }
  3218. case EXTENDED_LONG_DISTANCE_NUMBER:
  3219. {
  3220. // Long distance number ( 10 digits) preceeded by a 0/1
  3221. // Strip leading 0/1 and treat as a long distance number
  3222. if ( szDigits[ 0 ] == TEXT('0') || szDigits[ 0 ] == TEXT('1') )
  3223. {
  3224. nLenDigits--;
  3225. memmove( szDigits, &(szDigits[1]), nLenDigits*sizeof(TCHAR) );
  3226. szDigits[ nLenDigits ] = TEXT('\0');
  3227. cPos = _tcscspn( szPref, TEXT("01") );
  3228. nLenPref--;
  3229. memmove( &(szPref[ cPos ]), &(szPref[ cPos + 1 ]), (nLenPref - cPos)*sizeof(TCHAR) );
  3230. szPref[ nLenPref ] = TEXT('\0');
  3231. }
  3232. else
  3233. {
  3234. goto error;
  3235. }
  3236. }
  3237. case LONG_DISTANCE_NUMBER:
  3238. {
  3239. // if first or fourth digit is 0/1, illegal number
  3240. if ( szDigits[ 0 ] == TEXT('0') || szDigits[ 0 ] == TEXT('1') ||
  3241. szDigits[ 3 ] == TEXT('0') || szDigits[ 3 ] == TEXT('1') )
  3242. {
  3243. goto error;
  3244. }
  3245. szCanNumber[ 0 ] = TEXT('\0');
  3246. lstrcat( szCanNumber, TEXT("+1 (") );
  3247. _tcsncat( szCanNumber, szDigits, 3 );
  3248. lstrcat( szCanNumber, TEXT(") ") );
  3249. lstrcat( szCanNumber, &(szDigits[ 3 ]) );
  3250. bRes = TRUE;
  3251. }
  3252. break;
  3253. default :
  3254. goto error;
  3255. }
  3256. error:
  3257. if ( lpTransOut )
  3258. DialerFree( lpTransOut );
  3259. if ( lpTransCaps )
  3260. DialerFree( lpTransCaps );
  3261. return bRes;
  3262. }
  3263. /*
  3264. * Name :
  3265. * AmpersandCompensate
  3266. *
  3267. * Arguements :
  3268. * lpszSrc : Src string containing &s
  3269. * lpszDst : Dest string
  3270. *
  3271. * Return :
  3272. *
  3273. * Comments :
  3274. * Copies string pointed to by lpszSrc to lpszDst character by
  3275. * character. If an & is encountered in this process in lpszSrc
  3276. * it is copied as && into lpszDst.
  3277. * Assumes lpszDst and lpszSrc are of size TAPIMAXCALLEDPARTYSIZE
  3278. */
  3279. VOID AmpersandCompensate ( LPCTSTR lpszSrc, LPTSTR lpszDst )
  3280. {
  3281. // check if the name has an & in it. If so replace
  3282. // it with &&.
  3283. INT cCnt, cInd;
  3284. for ( cCnt = 0, cInd = 0;
  3285. cInd < TAPIMAXCALLEDPARTYSIZE;
  3286. cInd++, cCnt++ )
  3287. {
  3288. if ( lpszSrc[ cCnt ] == TEXT('&') )
  3289. {
  3290. lpszDst[ cInd++ ] = TEXT('&');
  3291. }
  3292. lpszDst[ cInd ] = lpszSrc[ cCnt ];
  3293. if ( lpszSrc[ cCnt ] == TEXT('\0') )
  3294. break;
  3295. }
  3296. // make sure string is null terminated.
  3297. lpszDst[ TAPIMAXCALLEDPARTYSIZE - 1 ] = TEXT('\0');
  3298. return;
  3299. }
  3300. /*
  3301. * Name :
  3302. * AmpersandDeCompensate
  3303. *
  3304. * Arguements :
  3305. * lpszSrc : Src string containing &s
  3306. * lpszDst : Dest string
  3307. *
  3308. * Return :
  3309. *
  3310. * Comments :
  3311. * Copies string pointed to by lpszSrc to lpszDst character by
  3312. * character. If an && is encountered in this process in lpszSrc
  3313. * it is copied as & into lpszDst.
  3314. * Assumes lpszDst and lpszSrc are of size TAPIMAXCALLEDPARTYSIZE
  3315. */
  3316. VOID AmpersandDeCompensate ( LPCTSTR lpszSrc, LPTSTR lpszDst )
  3317. {
  3318. // check if the name has an & in it. If so replace
  3319. // it with &&.
  3320. INT cCnt, cInd;
  3321. for ( cCnt = 0, cInd = 0;
  3322. cInd < TAPIMAXCALLEDPARTYSIZE;
  3323. cInd++, cCnt++ )
  3324. {
  3325. if ( ( lpszSrc[ cInd ] == TEXT('&') ) &&
  3326. ( lpszSrc[ cInd + 1 ] == TEXT('&') ) )
  3327. {
  3328. cInd++;
  3329. }
  3330. lpszDst[ cCnt ] = lpszSrc[ cInd ] ;
  3331. if ( lpszSrc [ cInd ] == TEXT('\0') )
  3332. {
  3333. break;
  3334. }
  3335. }
  3336. lpszDst[ TAPIMAXCALLEDPARTYSIZE - 1 ] = TEXT('\0');
  3337. return;
  3338. }