Source code of Windows XP (NT5)
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.

1258 lines
42 KiB

  1. #include "nc.h"
  2. #pragma hdrstop
  3. typedef struct _NCACCTINFO NCACCTINFO, *LPNCACCTINFO;
  4. typedef BOOL (CALLBACK* NCDLGPROC)(HWND, UINT, WPARAM, LPARAM, LPNCACCTINFO);
  5. typedef HPROPSHEETPAGE *LPHPROPSHEETPAGE;
  6. typedef struct _NCACCTINFO {
  7. CNcConnectionInfo connInfo;
  8. CNcAccountInfo accountInfo;
  9. CNcUser accountOwner;
  10. CNcUser billingOwner;
  11. const AccountInfoServer *pServer;
  12. const AccountInfoPlan *pPlan;
  13. CHAR ServerName[LT_SERVER_NAME+1];
  14. CHAR FirstName[LT_FIRST_NAME+1];
  15. CHAR LastName[LT_LAST_NAME+1];
  16. CHAR Email[LT_EMAIL+1];
  17. CHAR PhoneNumber[LT_PHONE_NUMBER+1];
  18. CHAR AreaCode[LT_AREA_CODE+1];
  19. CHAR Address[LT_ADDRESS+1];
  20. CHAR City[LT_CITY+1];
  21. CHAR State[LT_STATE+1];
  22. CHAR Zip[LT_ZIP+1];
  23. CHAR AccountName[LT_ACCOUNT_NAME+1];
  24. CHAR Password[LT_PASSWORD+1];
  25. CHAR CreditCard[LT_CREDIT_CARD+1];
  26. CHAR ExpiryMM[LT_EXPIRY_MM+1];
  27. CHAR ExpiryYY[LT_EXPIRY_YY+1];
  28. CHAR CCName[LT_CC_NAME+1];
  29. CHAR CCType[32];
  30. } NCACCTINFO, *LPNCACCTINFO;
  31. typedef struct _WIZPAGE {
  32. UINT ButtonState;
  33. UINT HelpContextId;
  34. LPTSTR Title;
  35. DWORD PageId;
  36. NCDLGPROC DlgProc;
  37. PROPSHEETPAGE Page;
  38. LPNCACCTINFO NcAcctInfo;
  39. } WIZPAGE, *PWIZPAGE;
  40. typedef enum {
  41. WizPageServerName,
  42. WizPageIsp,
  43. WizPagePlans,
  44. WizPageInfo,
  45. WizPageInfo2,
  46. WizPageAccount,
  47. WizPageBilling,
  48. WizPageFinish,
  49. WizPageCreate,
  50. WizPageMaximum
  51. } WizPage;
  52. BOOL CALLBACK
  53. CommonDlgProc(
  54. HWND hwnd,
  55. UINT message,
  56. WPARAM wParam,
  57. LPARAM lParam
  58. );
  59. BOOL CALLBACK
  60. ServerNameDlgProc(
  61. HWND hwnd,
  62. UINT message,
  63. WPARAM wParam,
  64. LPARAM lParam,
  65. LPNCACCTINFO NcAcctInfo
  66. );
  67. BOOL CALLBACK
  68. Info2DlgProc(
  69. HWND hwnd,
  70. UINT message,
  71. WPARAM wParam,
  72. LPARAM lParam,
  73. LPNCACCTINFO NcAcctInfo
  74. );
  75. BOOL CALLBACK
  76. InfoDlgProc(
  77. HWND hwnd,
  78. UINT message,
  79. WPARAM wParam,
  80. LPARAM lParam,
  81. LPNCACCTINFO NcAcctInfo
  82. );
  83. BOOL CALLBACK
  84. AccountDlgProc(
  85. HWND hwnd,
  86. UINT message,
  87. WPARAM wParam,
  88. LPARAM lParam,
  89. LPNCACCTINFO NcAcctInfo
  90. );
  91. BOOL CALLBACK
  92. BillingDlgProc(
  93. HWND hwnd,
  94. UINT message,
  95. WPARAM wParam,
  96. LPARAM lParam,
  97. LPNCACCTINFO NcAcctInfo
  98. );
  99. BOOL CALLBACK
  100. IspDlgProc(
  101. HWND hwnd,
  102. UINT message,
  103. WPARAM wParam,
  104. LPARAM lParam,
  105. LPNCACCTINFO NcAcctInfo
  106. );
  107. BOOL CALLBACK
  108. PlansDlgProc(
  109. HWND hwnd,
  110. UINT message,
  111. WPARAM wParam,
  112. LPARAM lParam,
  113. LPNCACCTINFO NcAcctInfo
  114. );
  115. BOOL CALLBACK
  116. CreateDlgProc(
  117. HWND hwnd,
  118. UINT message,
  119. WPARAM wParam,
  120. LPARAM lParam,
  121. LPNCACCTINFO NcAcctInfo
  122. );
  123. BOOL CALLBACK
  124. FinishDlgProc(
  125. HWND hwnd,
  126. UINT message,
  127. WPARAM wParam,
  128. LPARAM lParam,
  129. LPNCACCTINFO NcAcctInfo
  130. );
  131. WIZPAGE WizardPages[WizPageMaximum] =
  132. {
  133. //
  134. // server name page
  135. //
  136. {
  137. PSWIZB_NEXT, // valid buttons
  138. 0, // help id
  139. NULL, // title
  140. WizPageServerName, // page id
  141. ServerNameDlgProc, // dlg proc
  142. { sizeof(PROPSHEETPAGE), // size of struct
  143. 0, // flags
  144. NULL, // hinst (filled in at run time)
  145. MAKEINTRESOURCE(IDD_SERVER_NAME_PAGE), // dlg template
  146. NULL, // icon
  147. NULL, // title
  148. (DLGPROC)CommonDlgProc, // dlg proc
  149. 0, // lparam
  150. NULL, // callback
  151. NULL // ref count
  152. }},
  153. //
  154. // isp page
  155. //
  156. {
  157. PSWIZB_NEXT | PSWIZB_BACK, // valid buttons
  158. 0, // help id
  159. NULL, // title
  160. WizPageIsp, // page id
  161. IspDlgProc, // dlg proc
  162. { sizeof(PROPSHEETPAGE), // size of struct
  163. 0, // flags
  164. NULL, // hinst (filled in at run time)
  165. MAKEINTRESOURCE(IDD_ISP_PAGE), // dlg template
  166. NULL, // icon
  167. NULL, // title
  168. (DLGPROC)CommonDlgProc, // dlg proc
  169. 0, // lparam
  170. NULL, // callback
  171. NULL // ref count
  172. }},
  173. //
  174. // plans page
  175. //
  176. {
  177. PSWIZB_NEXT | PSWIZB_BACK, // valid buttons
  178. 0, // help id
  179. NULL, // title
  180. WizPagePlans, // page id
  181. PlansDlgProc, // dlg proc
  182. { sizeof(PROPSHEETPAGE), // size of struct
  183. 0, // flags
  184. NULL, // hinst (filled in at run time)
  185. MAKEINTRESOURCE(IDD_PLANS_PAGE), // dlg template
  186. NULL, // icon
  187. NULL, // title
  188. (DLGPROC)CommonDlgProc, // dlg proc
  189. 0, // lparam
  190. NULL, // callback
  191. NULL // ref count
  192. }},
  193. //
  194. // info page
  195. //
  196. {
  197. PSWIZB_NEXT | PSWIZB_BACK, // valid buttons
  198. 0, // help id
  199. NULL, // title
  200. WizPageInfo, // page id
  201. InfoDlgProc, // dlg proc
  202. { sizeof(PROPSHEETPAGE), // size of struct
  203. 0, // flags
  204. NULL, // hinst (filled in at run time)
  205. MAKEINTRESOURCE(IDD_INFO_PAGE), // dlg template
  206. NULL, // icon
  207. NULL, // title
  208. (DLGPROC)CommonDlgProc, // dlg proc
  209. 0, // lparam
  210. NULL, // callback
  211. NULL // ref count
  212. }},
  213. //
  214. // info2 page
  215. //
  216. {
  217. PSWIZB_NEXT | PSWIZB_BACK, // valid buttons
  218. 0, // help id
  219. NULL, // title
  220. WizPageInfo2, // page id
  221. Info2DlgProc, // dlg proc
  222. { sizeof(PROPSHEETPAGE), // size of struct
  223. 0, // flags
  224. NULL, // hinst (filled in at run time)
  225. MAKEINTRESOURCE(IDD_INFO2_PAGE), // dlg template
  226. NULL, // icon
  227. NULL, // title
  228. (DLGPROC)CommonDlgProc, // dlg proc
  229. 0, // lparam
  230. NULL, // callback
  231. NULL // ref count
  232. }},
  233. //
  234. // account page
  235. //
  236. {
  237. PSWIZB_NEXT | PSWIZB_BACK, // valid buttons
  238. 0, // help id
  239. NULL, // title
  240. WizPageAccount, // page id
  241. AccountDlgProc, // dlg proc
  242. { sizeof(PROPSHEETPAGE), // size of struct
  243. 0, // flags
  244. NULL, // hinst (filled in at run time)
  245. MAKEINTRESOURCE(IDD_ACCT_PAGE), // dlg template
  246. NULL, // icon
  247. NULL, // title
  248. (DLGPROC)CommonDlgProc, // dlg proc
  249. 0, // lparam
  250. NULL, // callback
  251. NULL // ref count
  252. }},
  253. //
  254. // billing page
  255. //
  256. {
  257. PSWIZB_NEXT | PSWIZB_BACK, // valid buttons
  258. 0, // help id
  259. NULL, // title
  260. WizPageBilling, // page id
  261. BillingDlgProc, // dlg proc
  262. { sizeof(PROPSHEETPAGE), // size of struct
  263. 0, // flags
  264. NULL, // hinst (filled in at run time)
  265. MAKEINTRESOURCE(IDD_BILLING_PAGE), // dlg template
  266. NULL, // icon
  267. NULL, // title
  268. (DLGPROC)CommonDlgProc, // dlg proc
  269. 0, // lparam
  270. NULL, // callback
  271. NULL // ref count
  272. }},
  273. //
  274. // account creation page
  275. //
  276. {
  277. PSWIZB_NEXT | PSWIZB_BACK, // valid buttons
  278. 0, // help id
  279. NULL, // title
  280. WizPageCreate, // page id
  281. CreateDlgProc, // dlg proc
  282. { sizeof(PROPSHEETPAGE), // size of struct
  283. 0, // flags
  284. NULL, // hinst (filled in at run time)
  285. MAKEINTRESOURCE(IDD_CREATE_PAGE), // dlg template
  286. NULL, // icon
  287. NULL, // title
  288. (DLGPROC)CommonDlgProc, // dlg proc
  289. 0, // lparam
  290. NULL, // callback
  291. NULL // ref count
  292. }},
  293. //
  294. // finish page
  295. //
  296. {
  297. PSWIZB_FINISH | PSWIZB_BACK, // valid buttons
  298. 0, // help id
  299. NULL, // title
  300. WizPageFinish, // page id
  301. FinishDlgProc, // dlg proc
  302. { sizeof(PROPSHEETPAGE), // size of struct
  303. 0, // flags
  304. NULL, // hinst (filled in at run time)
  305. MAKEINTRESOURCE(IDD_FINISH_PAGE), // dlg template
  306. NULL, // icon
  307. NULL, // title
  308. (DLGPROC)CommonDlgProc, // dlg proc
  309. 0, // lparam
  310. NULL, // callback
  311. NULL // ref count
  312. }}
  313. };
  314. LPHPROPSHEETPAGE
  315. CreateWizardPages(
  316. LPNCACCTINFO NcAcctInfo
  317. )
  318. {
  319. LPHPROPSHEETPAGE WizardPageHandles;
  320. DWORD i;
  321. //
  322. // allocate the page handle array
  323. //
  324. WizardPageHandles = (HPROPSHEETPAGE*) MemAlloc(
  325. sizeof(HPROPSHEETPAGE) * WizPageMaximum
  326. );
  327. if (!WizardPageHandles) {
  328. return NULL;
  329. }
  330. //
  331. // Create each page.
  332. //
  333. for(i=0; i<WizPageMaximum; i++) {
  334. WizardPages[i].Page.hInstance = MyhInstance;
  335. WizardPages[i].Page.dwFlags |= PSP_USETITLE;
  336. WizardPages[i].NcAcctInfo = NcAcctInfo;
  337. WizardPages[i].Page.lParam = (LPARAM) &WizardPages[i];
  338. WizardPageHandles[i] = CreatePropertySheetPage( &WizardPages[i].Page );
  339. if (!WizardPageHandles[i]) {
  340. MemFree( WizardPageHandles );
  341. return NULL;
  342. }
  343. }
  344. return WizardPageHandles;
  345. }
  346. int
  347. CALLBACK
  348. WizardCallback(
  349. IN HWND hdlg,
  350. IN UINT code,
  351. IN LPARAM lParam
  352. )
  353. {
  354. DLGTEMPLATE *DlgTemplate;
  355. //
  356. // Get rid of context sensitive help control on title bar
  357. //
  358. if(code == PSCB_PRECREATE) {
  359. DlgTemplate = (DLGTEMPLATE *)lParam;
  360. DlgTemplate->style &= ~DS_CONTEXTHELP;
  361. }
  362. return 0;
  363. }
  364. BOOL
  365. CreateNewAccount(
  366. HWND hDlg
  367. )
  368. {
  369. PROPSHEETHEADER psh;
  370. LPHPROPSHEETPAGE WizPages;
  371. NCACCTINFO NcAcctInfo;
  372. WizPages = CreateWizardPages( &NcAcctInfo );
  373. if (!WizPages) {
  374. return FALSE;
  375. }
  376. //
  377. // create the property sheet
  378. //
  379. psh.dwSize = sizeof(PROPSHEETHEADER);
  380. psh.dwFlags = PSH_WIZARD | PSH_USECALLBACK;
  381. psh.hwndParent = hDlg;
  382. psh.hInstance = MyhInstance;
  383. psh.pszIcon = NULL;
  384. psh.pszCaption = TEXT("NetCentric Internet Fax Account Wizard");
  385. psh.nPages = WizPageMaximum;
  386. psh.nStartPage = 0;
  387. psh.phpage = WizPages;
  388. psh.pfnCallback = WizardCallback;
  389. if (PropertySheet( &psh ) == -1) {
  390. return FALSE;
  391. }
  392. return TRUE;
  393. }
  394. BOOL CALLBACK
  395. CommonDlgProc(
  396. HWND hwnd,
  397. UINT msg,
  398. WPARAM wParam,
  399. LPARAM lParam
  400. )
  401. {
  402. PWIZPAGE WizPage;
  403. WizPage = (PWIZPAGE) GetWindowLong( hwnd, DWL_USER );
  404. switch( msg ) {
  405. case WM_INITDIALOG:
  406. SetWindowLong( hwnd, DWL_USER, (LONG) ((LPPROPSHEETPAGE) lParam)->lParam );
  407. WizPage = (PWIZPAGE) ((LPPROPSHEETPAGE) lParam)->lParam;
  408. SetWindowText( GetParent( hwnd ), TEXT("NetCentric Internet Fax Account Wizard") );
  409. break;
  410. case WM_NOTIFY:
  411. switch( ((LPNMHDR)lParam)->code ) {
  412. case PSN_SETACTIVE:
  413. PropSheet_SetWizButtons(
  414. GetParent(hwnd),
  415. WizPage->ButtonState
  416. );
  417. SetWindowLong( hwnd, DWL_MSGRESULT, 0 );
  418. break;
  419. }
  420. break;
  421. }
  422. if (WizPage && WizPage->DlgProc) {
  423. return WizPage->DlgProc( hwnd, msg, wParam, lParam, WizPage->NcAcctInfo );
  424. }
  425. return FALSE;
  426. }
  427. BOOL CALLBACK
  428. ServerNameDlgProc(
  429. HWND hDlg,
  430. UINT message,
  431. WPARAM wParam,
  432. LPARAM lParam,
  433. LPNCACCTINFO NcAcctInfo
  434. )
  435. {
  436. HCURSOR Hourglass;
  437. HCURSOR OldCursor;
  438. switch( message ) {
  439. case WM_INITDIALOG:
  440. SendDlgItemMessage( hDlg, IDC_SERVER_NAME, EM_SETLIMITTEXT, LT_SERVER_NAME, 0 );
  441. break;
  442. case WM_NOTIFY:
  443. switch( ((LPNMHDR)lParam)->code ) {
  444. case PSN_SETACTIVE:
  445. break;
  446. case PSN_WIZNEXT:
  447. if (!GetDlgItemTextA( hDlg, IDC_SERVER_NAME, NcAcctInfo->ServerName, LT_SERVER_NAME )) {
  448. SetWindowLong( hDlg, DWL_MSGRESULT, -1 );
  449. return TRUE;
  450. }
  451. //
  452. // Get the POPserver name from the user (e.g., spop.server.net). This
  453. // will be used as the "initial" server for obtaining the list
  454. // of Service Providers who offer the faxing service.
  455. //
  456. if (!NcAcctInfo->connInfo.SetHostName(NcAcctInfo->ServerName)) {
  457. PopUpMsg( hDlg, IDS_BAD_SERVER, TRUE, 0 );
  458. SetWindowLong( hDlg, DWL_MSGRESULT, -1 );
  459. return TRUE;
  460. }
  461. NcAcctInfo->connInfo.SetPortNumber( 80, FALSE );
  462. //
  463. // Tell the accountInfo about the connection object. This
  464. // CNcConnectionInfo object contains hostname/port/proxy/account
  465. // information.
  466. //
  467. if (!NcAcctInfo->accountInfo.SetConnectionInfo(&NcAcctInfo->connInfo)) {
  468. PopUpMsg( hDlg, IDS_BAD_SERVER, TRUE, 0 );
  469. SetWindowLong( hDlg, DWL_MSGRESULT, -1 );
  470. return TRUE;
  471. }
  472. //
  473. // get the isp list
  474. //
  475. Hourglass = LoadCursor( NULL, IDC_WAIT );
  476. OldCursor = SetCursor( Hourglass );
  477. if (!NcAcctInfo->accountInfo.GetAccountServers()) {
  478. SetCursor( OldCursor );
  479. PopUpMsg( hDlg, IDS_BAD_SERVER, TRUE, 0 );
  480. SetWindowLong( hDlg, DWL_MSGRESULT, -1 );
  481. return TRUE;
  482. }
  483. SetCursor( OldCursor );
  484. break;
  485. }
  486. break;
  487. }
  488. return FALSE;
  489. }
  490. BOOL CALLBACK
  491. IspDlgProc(
  492. HWND hDlg,
  493. UINT message,
  494. WPARAM wParam,
  495. LPARAM lParam,
  496. LPNCACCTINFO NcAcctInfo
  497. )
  498. {
  499. static HWND hwndList;
  500. static int SelectedIsp;
  501. const AccountInfoServer *pServer;
  502. AccountServerIndex serverLoopIndex;
  503. HIMAGELIST himlState;
  504. LV_ITEMA lvi;
  505. LV_COLUMN lvc = {0};
  506. int index;
  507. HCURSOR Hourglass;
  508. HCURSOR OldCursor;
  509. switch( message ) {
  510. case WM_INITDIALOG:
  511. hwndList = GetDlgItem( hDlg, IDC_ISP_LIST );
  512. SelectedIsp = 0;
  513. //
  514. // set/initialize the image list(s)
  515. //
  516. himlState = ImageList_Create( 16, 16, TRUE, 2, 0 );
  517. ImageList_AddMasked(
  518. himlState,
  519. LoadBitmap( MyhInstance, MAKEINTRESOURCE(IDB_CHECKSTATES) ),
  520. RGB (255,0,0)
  521. );
  522. ListView_SetImageList( hwndList, himlState, LVSIL_STATE );
  523. //
  524. // set/initialize the columns
  525. //
  526. lvc.mask = LVCF_FMT | LVCF_WIDTH | LVCF_TEXT | LVCF_SUBITEM;
  527. lvc.fmt = LVCFMT_LEFT;
  528. lvc.cx = 250;
  529. lvc.pszText = L"Service Provider";
  530. lvc.iSubItem = 0;
  531. ListView_InsertColumn( hwndList, lvc.iSubItem, &lvc );
  532. break;
  533. case WM_NOTIFY:
  534. switch( ((LPNMHDR)lParam)->code ) {
  535. case PSN_SETACTIVE:
  536. ListView_DeleteAllItems( hwndList );
  537. serverLoopIndex = 0;
  538. ZeroMemory( &lvi, sizeof(lvi) );
  539. pServer = NcAcctInfo->accountInfo.GetFirstAccountServer(&serverLoopIndex);
  540. while (pServer) {
  541. lvi.pszText = pServer->description;
  542. lvi.iItem += 1;
  543. lvi.iSubItem = 0;
  544. lvi.iImage = 0;
  545. lvi.mask = LVIF_TEXT | LVIF_IMAGE | LVIF_PARAM | LVIF_STATE;
  546. lvi.state = lvi.iItem-1 == SelectedIsp ? LVIS_GCCHECK : LVIS_GCNOCHECK;
  547. lvi.stateMask = LVIS_STATEIMAGEMASK;
  548. SendMessageA( hwndList, LVM_INSERTITEMA, 0, (LPARAM) &lvi );
  549. pServer = NcAcctInfo->accountInfo.GetNextAccountServer(&serverLoopIndex);
  550. }
  551. break;
  552. case PSN_WIZNEXT:
  553. serverLoopIndex = 0;
  554. index = 0;
  555. pServer = NcAcctInfo->accountInfo.GetFirstAccountServer(&serverLoopIndex);
  556. while (pServer && index != SelectedIsp) {
  557. pServer = NcAcctInfo->accountInfo.GetNextAccountServer(&serverLoopIndex);
  558. index += 1;
  559. }
  560. if (!pServer) {
  561. PopUpMsg( hDlg, IDS_BAD_SERVER, TRUE, 0 );
  562. SetWindowLong( hDlg, DWL_MSGRESULT, -1 );
  563. return TRUE;
  564. }
  565. NcAcctInfo->pServer = pServer;
  566. //
  567. // Now use the selected server for our connectionInfo object. This
  568. // will be the server we use to create the actual account, for the
  569. // selected ISP. Once set in the CNcConnectionInfo object, set that
  570. // connInfo object in the accountInfo.
  571. //
  572. if (!NcAcctInfo->connInfo.SetHostName( pServer->name )) {
  573. PopUpMsg( hDlg, IDS_BAD_ISP, TRUE, 0 );
  574. SetWindowLong( hDlg, DWL_MSGRESULT, -1 );
  575. return TRUE;
  576. }
  577. if (!NcAcctInfo->accountInfo.SetConnectionInfo(&NcAcctInfo->connInfo)) {
  578. PopUpMsg( hDlg, IDS_BAD_ISP, TRUE, 0 );
  579. SetWindowLong( hDlg, DWL_MSGRESULT, -1 );
  580. return TRUE;
  581. }
  582. //
  583. // get the plan list
  584. //
  585. Hourglass = LoadCursor( NULL, IDC_WAIT );
  586. OldCursor = SetCursor( Hourglass );
  587. if (!NcAcctInfo->accountInfo.GetPlanInformation()) {
  588. SetCursor( OldCursor );
  589. PopUpMsg( hDlg, IDS_BAD_ISP, TRUE, 0 );
  590. SetWindowLong( hDlg, DWL_MSGRESULT, -1 );
  591. return TRUE;
  592. }
  593. SetCursor( OldCursor );
  594. break;
  595. case NM_CLICK:
  596. {
  597. DWORD dwpos;
  598. LV_HITTESTINFO lvhti;
  599. int iItemClicked;
  600. UINT state;
  601. //
  602. // Find out where the cursor was
  603. //
  604. dwpos = GetMessagePos();
  605. lvhti.pt.x = LOWORD(dwpos);
  606. lvhti.pt.y = HIWORD(dwpos);
  607. MapWindowPoints( HWND_DESKTOP, hwndList, &lvhti.pt, 1 );
  608. //
  609. // Now do a hittest with this point.
  610. //
  611. iItemClicked = ListView_HitTest( hwndList, &lvhti );
  612. if (lvhti.flags & LVHT_ONITEMSTATEICON) {
  613. //
  614. // Now lets get the state from the item and toggle it.
  615. //
  616. state = ListView_GetItemState(
  617. hwndList,
  618. iItemClicked,
  619. LVIS_STATEIMAGEMASK
  620. );
  621. if (state == LVIS_GCCHECK) {
  622. MessageBeep(0);
  623. break;
  624. }
  625. state = (state == LVIS_GCNOCHECK) ? LVIS_GCCHECK : LVIS_GCNOCHECK;
  626. ListView_SetItemState(
  627. hwndList,
  628. SelectedIsp,
  629. LVIS_GCNOCHECK,
  630. LVIS_STATEIMAGEMASK
  631. );
  632. ListView_SetItemState(
  633. hwndList,
  634. iItemClicked,
  635. state,
  636. LVIS_STATEIMAGEMASK
  637. );
  638. SelectedIsp = iItemClicked;
  639. }
  640. }
  641. }
  642. break;
  643. }
  644. return FALSE;
  645. }
  646. BOOL CALLBACK
  647. PlansDlgProc(
  648. HWND hDlg,
  649. UINT message,
  650. WPARAM wParam,
  651. LPARAM lParam,
  652. LPNCACCTINFO NcAcctInfo
  653. )
  654. {
  655. static HWND hwndList;
  656. static int SelectedPlan;
  657. const AccountInfoPlan *pPlan;
  658. AccountPlanIndex planLoopIndex;
  659. HIMAGELIST himlState;
  660. LV_ITEMA lvi;
  661. LV_COLUMN lvc = {0};
  662. int index;
  663. switch( message ) {
  664. case WM_INITDIALOG:
  665. hwndList = GetDlgItem( hDlg, IDC_PLAN_LIST );
  666. SelectedPlan = 0;
  667. //
  668. // set/initialize the image list(s)
  669. //
  670. himlState = ImageList_Create( 16, 16, TRUE, 2, 0 );
  671. ImageList_AddMasked(
  672. himlState,
  673. LoadBitmap( MyhInstance, MAKEINTRESOURCE(IDB_CHECKSTATES) ),
  674. RGB (255,0,0)
  675. );
  676. ListView_SetImageList( hwndList, himlState, LVSIL_STATE );
  677. //
  678. // set/initialize the columns
  679. //
  680. lvc.mask = LVCF_FMT | LVCF_WIDTH | LVCF_TEXT | LVCF_SUBITEM;
  681. lvc.fmt = LVCFMT_LEFT;
  682. lvc.cx = 250;
  683. lvc.pszText = L"Plans";
  684. lvc.iSubItem = 0;
  685. ListView_InsertColumn( hwndList, lvc.iSubItem, &lvc );
  686. break;
  687. case WM_NOTIFY:
  688. switch( ((LPNMHDR)lParam)->code ) {
  689. case PSN_SETACTIVE:
  690. ListView_DeleteAllItems( hwndList );
  691. planLoopIndex = 0;
  692. ZeroMemory( &lvi, sizeof(lvi) );
  693. pPlan = NcAcctInfo->accountInfo.GetFirstPlan(&planLoopIndex);
  694. while (pPlan) {
  695. lvi.pszText = pPlan->planDescription;
  696. lvi.iItem += 1;
  697. lvi.iSubItem = 0;
  698. lvi.iImage = 0;
  699. lvi.mask = LVIF_TEXT | LVIF_IMAGE | LVIF_PARAM | LVIF_STATE;
  700. lvi.state = lvi.iItem-1 == SelectedPlan ? LVIS_GCCHECK : LVIS_GCNOCHECK;
  701. lvi.stateMask = LVIS_STATEIMAGEMASK;
  702. SendMessageA( hwndList, LVM_INSERTITEMA, 0, (LPARAM) &lvi );
  703. pPlan = NcAcctInfo->accountInfo.GetNextPlan(&planLoopIndex);
  704. }
  705. break;
  706. case PSN_WIZNEXT:
  707. planLoopIndex = 0;
  708. index = 0;
  709. pPlan = NcAcctInfo->accountInfo.GetFirstPlan(&planLoopIndex);
  710. while (pPlan && index != SelectedPlan) {
  711. pPlan = NcAcctInfo->accountInfo.GetNextPlan(&planLoopIndex);
  712. index += 1;
  713. }
  714. if (!pPlan) {
  715. PopUpMsg( hDlg, IDS_BAD_SERVER, TRUE, 0 );
  716. SetWindowLong( hDlg, DWL_MSGRESULT, -1 );
  717. return TRUE;
  718. }
  719. NcAcctInfo->pPlan = pPlan;
  720. break;
  721. case NM_CLICK:
  722. {
  723. DWORD dwpos;
  724. LV_HITTESTINFO lvhti;
  725. int iItemClicked;
  726. UINT state;
  727. //
  728. // Find out where the cursor was
  729. //
  730. dwpos = GetMessagePos();
  731. lvhti.pt.x = LOWORD(dwpos);
  732. lvhti.pt.y = HIWORD(dwpos);
  733. MapWindowPoints( HWND_DESKTOP, hwndList, &lvhti.pt, 1 );
  734. //
  735. // Now do a hittest with this point.
  736. //
  737. iItemClicked = ListView_HitTest( hwndList, &lvhti );
  738. if (lvhti.flags & LVHT_ONITEMSTATEICON) {
  739. //
  740. // Now lets get the state from the item and toggle it.
  741. //
  742. state = ListView_GetItemState(
  743. hwndList,
  744. iItemClicked,
  745. LVIS_STATEIMAGEMASK
  746. );
  747. if (state == LVIS_GCCHECK) {
  748. MessageBeep(0);
  749. break;
  750. }
  751. state = (state == LVIS_GCNOCHECK) ? LVIS_GCCHECK : LVIS_GCNOCHECK;
  752. ListView_SetItemState(
  753. hwndList,
  754. SelectedPlan,
  755. LVIS_GCNOCHECK,
  756. LVIS_STATEIMAGEMASK
  757. );
  758. ListView_SetItemState(
  759. hwndList,
  760. iItemClicked,
  761. state,
  762. LVIS_STATEIMAGEMASK
  763. );
  764. SelectedPlan = iItemClicked;
  765. }
  766. }
  767. }
  768. break;
  769. }
  770. return FALSE;
  771. }
  772. BOOL CALLBACK
  773. InfoDlgProc(
  774. HWND hDlg,
  775. UINT message,
  776. WPARAM wParam,
  777. LPARAM lParam,
  778. LPNCACCTINFO NcAcctInfo
  779. )
  780. {
  781. switch( message ) {
  782. case WM_INITDIALOG:
  783. SendDlgItemMessage( hDlg, IDC_FIRST_NAME, EM_SETLIMITTEXT, LT_FIRST_NAME, 0 );
  784. SendDlgItemMessage( hDlg, IDC_LAST_NAME, EM_SETLIMITTEXT, LT_LAST_NAME, 0 );
  785. SendDlgItemMessage( hDlg, IDC_ADDRESS, EM_SETLIMITTEXT, LT_ADDRESS, 0 );
  786. SendDlgItemMessage( hDlg, IDC_CITY, EM_SETLIMITTEXT, LT_CITY, 0 );
  787. SendDlgItemMessage( hDlg, IDC_STATE, EM_SETLIMITTEXT, LT_STATE, 0 );
  788. SendDlgItemMessage( hDlg, IDC_ZIP, EM_SETLIMITTEXT, LT_ZIP, 0 );
  789. break;
  790. case WM_NOTIFY:
  791. switch( ((LPNMHDR)lParam)->code ) {
  792. case PSN_SETACTIVE:
  793. break;
  794. case PSN_WIZNEXT:
  795. GetDlgItemTextA( hDlg, IDC_FIRST_NAME, NcAcctInfo->FirstName, LT_FIRST_NAME );
  796. GetDlgItemTextA( hDlg, IDC_LAST_NAME, NcAcctInfo->LastName, LT_LAST_NAME );
  797. GetDlgItemTextA( hDlg, IDC_ADDRESS, NcAcctInfo->Address, LT_ADDRESS );
  798. GetDlgItemTextA( hDlg, IDC_CITY, NcAcctInfo->City, LT_CITY );
  799. GetDlgItemTextA( hDlg, IDC_STATE, NcAcctInfo->State, LT_STATE );
  800. GetDlgItemTextA( hDlg, IDC_ZIP, NcAcctInfo->Zip, LT_ZIP );
  801. if (NcAcctInfo->FirstName[0] == 0 ||
  802. NcAcctInfo->LastName[0] == 0 ||
  803. NcAcctInfo->Address[0] == 0 ||
  804. NcAcctInfo->City[0] == 0 ||
  805. NcAcctInfo->State[0] == 0 ||
  806. NcAcctInfo->Zip[0] == 0)
  807. {
  808. //
  809. // all fields are required
  810. // if we get here then the user forgot to
  811. // enter data into one of the fields
  812. //
  813. PopUpMsg( hDlg, IDS_MISSING_INFO, TRUE, 0 );
  814. SetWindowLong( hDlg, DWL_MSGRESULT, -1 );
  815. return TRUE;
  816. }
  817. }
  818. break;
  819. }
  820. return FALSE;
  821. }
  822. BOOL CALLBACK
  823. Info2DlgProc(
  824. HWND hDlg,
  825. UINT message,
  826. WPARAM wParam,
  827. LPARAM lParam,
  828. LPNCACCTINFO NcAcctInfo
  829. )
  830. {
  831. switch( message ) {
  832. case WM_INITDIALOG:
  833. SendDlgItemMessage( hDlg, IDC_EMAIL, EM_SETLIMITTEXT, LT_EMAIL, 0 );
  834. SendDlgItemMessage( hDlg, IDC_PHONE_NUMBER, EM_SETLIMITTEXT, LT_PHONE_NUMBER, 0 );
  835. SendDlgItemMessage( hDlg, IDC_AREA_CODE, EM_SETLIMITTEXT, LT_AREA_CODE, 0 );
  836. break;
  837. case WM_NOTIFY:
  838. switch( ((LPNMHDR)lParam)->code ) {
  839. case PSN_SETACTIVE:
  840. break;
  841. case PSN_WIZNEXT:
  842. GetDlgItemTextA( hDlg, IDC_EMAIL, NcAcctInfo->Email, LT_EMAIL );
  843. GetDlgItemTextA( hDlg, IDC_PHONE_NUMBER, NcAcctInfo->PhoneNumber, LT_PHONE_NUMBER );
  844. GetDlgItemTextA( hDlg, IDC_AREA_CODE, NcAcctInfo->AreaCode, LT_AREA_CODE );
  845. if (NcAcctInfo->Email[0] == 0 ||
  846. NcAcctInfo->PhoneNumber[0] == 0 ||
  847. NcAcctInfo->AreaCode[0] == 0)
  848. {
  849. //
  850. // all fields are required
  851. // if we get here then the user forgot to
  852. // enter data into one of the fields
  853. //
  854. PopUpMsg( hDlg, IDS_MISSING_INFO, TRUE, 0 );
  855. SetWindowLong( hDlg, DWL_MSGRESULT, -1 );
  856. return TRUE;
  857. }
  858. if (!NcAcctInfo->accountOwner.SetFirstName( NcAcctInfo->FirstName ) ||
  859. !NcAcctInfo->accountOwner.SetLastName( NcAcctInfo->LastName ) ||
  860. !NcAcctInfo->accountOwner.SetEmail( NcAcctInfo->Email ) ||
  861. !NcAcctInfo->accountOwner.SetFirstAddress( NcAcctInfo->Address ) ||
  862. !NcAcctInfo->accountOwner.SetAddressZipcode( NcAcctInfo->Zip ) ||
  863. !NcAcctInfo->accountOwner.SetPhoneNumber( "1", NcAcctInfo->AreaCode, NcAcctInfo->PhoneNumber, NULL ))
  864. {
  865. PopUpMsg( hDlg, IDS_MISSING_INFO, TRUE, 0 );
  866. SetWindowLong( hDlg, DWL_MSGRESULT, -1 );
  867. return TRUE;
  868. }
  869. break;
  870. }
  871. break;
  872. }
  873. return FALSE;
  874. }
  875. BOOL CALLBACK
  876. AccountDlgProc(
  877. HWND hDlg,
  878. UINT message,
  879. WPARAM wParam,
  880. LPARAM lParam,
  881. LPNCACCTINFO NcAcctInfo
  882. )
  883. {
  884. switch( message ) {
  885. case WM_INITDIALOG:
  886. SendDlgItemMessage( hDlg, IDC_ACCOUNT_NAME, EM_SETLIMITTEXT, LT_ACCOUNT_NAME, 0 );
  887. SendDlgItemMessage( hDlg, IDC_PASSWORD, EM_SETLIMITTEXT, LT_PASSWORD, 0 );
  888. break;
  889. case WM_NOTIFY:
  890. switch( ((LPNMHDR)lParam)->code ) {
  891. case PSN_SETACTIVE:
  892. if (!NcAcctInfo->pPlan->passwordRequired) {
  893. EnableWindow( GetDlgItem( hDlg, IDC_PASSWORD ), FALSE );
  894. } else {
  895. EnableWindow( GetDlgItem( hDlg, IDC_PASSWORD ), TRUE );
  896. }
  897. break;
  898. case PSN_WIZNEXT:
  899. GetDlgItemTextA( hDlg, IDC_ACCOUNT_NAME, NcAcctInfo->AccountName, LT_ACCOUNT_NAME );
  900. GetDlgItemTextA( hDlg, IDC_PASSWORD, NcAcctInfo->Password, LT_PASSWORD );
  901. if (NcAcctInfo->AccountName[0] == 0 ||
  902. (NcAcctInfo->pPlan->passwordRequired && NcAcctInfo->Password[0] == 0))
  903. {
  904. PopUpMsg( hDlg, IDS_MISSING_ACCNT, TRUE, 0 );
  905. SetWindowLong( hDlg, DWL_MSGRESULT, -1 );
  906. return TRUE;
  907. }
  908. if (!NcAcctInfo->accountInfo.SetPassword( NcAcctInfo->Password )) {
  909. PopUpMsg( hDlg, IDS_MISSING_ACCNT, TRUE, 0 );
  910. SetWindowLong( hDlg, DWL_MSGRESULT, -1 );
  911. return TRUE;
  912. }
  913. break;
  914. }
  915. break;
  916. }
  917. return FALSE;
  918. }
  919. BOOL CALLBACK
  920. BillingDlgProc(
  921. HWND hDlg,
  922. UINT message,
  923. WPARAM wParam,
  924. LPARAM lParam,
  925. LPNCACCTINFO NcAcctInfo
  926. )
  927. {
  928. int i;
  929. switch( message ) {
  930. case WM_INITDIALOG:
  931. SendDlgItemMessage( hDlg, IDC_CREDIT_CARD, EM_SETLIMITTEXT, LT_CREDIT_CARD, 0 );
  932. SendDlgItemMessage( hDlg, IDC_EXPIRY_MM, EM_SETLIMITTEXT, LT_EXPIRY_MM, 0 );
  933. SendDlgItemMessage( hDlg, IDC_EXPIRY_YY, EM_SETLIMITTEXT, LT_EXPIRY_YY, 0 );
  934. SendDlgItemMessage( hDlg, IDC_CC_NAME, EM_SETLIMITTEXT, LT_CC_NAME, 0 );
  935. for (i=IDS_CC_FIRST; i<IDS_CC_LAST; i++) {
  936. SendDlgItemMessage( hDlg, IDC_CC_LIST, CB_ADDSTRING, 0, (LPARAM) GetString( i ) );
  937. if (i == IDS_CC_VISA) {
  938. SendDlgItemMessage( hDlg, IDC_CC_LIST, CB_SETCURSEL, i-IDS_CC_FIRST, 0 );
  939. }
  940. }
  941. break;
  942. case WM_NOTIFY:
  943. switch( ((LPNMHDR)lParam)->code ) {
  944. case PSN_SETACTIVE:
  945. if (!NcAcctInfo->pPlan->paymentRequired) {
  946. SetWindowLong( hDlg, DWL_MSGRESULT, -1 );
  947. return TRUE;
  948. }
  949. break;
  950. case PSN_WIZNEXT:
  951. GetDlgItemTextA( hDlg, IDC_CREDIT_CARD, NcAcctInfo->CreditCard, LT_CREDIT_CARD );
  952. GetDlgItemTextA( hDlg, IDC_EXPIRY_MM, NcAcctInfo->ExpiryMM, LT_EXPIRY_MM );
  953. GetDlgItemTextA( hDlg, IDC_EXPIRY_YY, NcAcctInfo->ExpiryYY, LT_EXPIRY_YY );
  954. GetDlgItemTextA( hDlg, IDC_CC_NAME, NcAcctInfo->CCName, LT_CC_NAME );
  955. switch( SendDlgItemMessage( hDlg, IDC_CC_LIST, CB_GETCURSEL, 0, 0 )) {
  956. case 0:
  957. strcpy( NcAcctInfo->CCType, AMERICAN_EXPRESS );
  958. break;
  959. case 1:
  960. strcpy( NcAcctInfo->CCType, DINERS_CLUB );
  961. break;
  962. case 2:
  963. strcpy( NcAcctInfo->CCType, DISCOVER );
  964. break;
  965. case 3:
  966. strcpy( NcAcctInfo->CCType, MASTER_CARD );
  967. break;
  968. case 4:
  969. strcpy( NcAcctInfo->CCType, VISA );
  970. break;
  971. }
  972. if (NcAcctInfo->CreditCard[0] == 0 ||
  973. NcAcctInfo->ExpiryMM[0] == 0 ||
  974. NcAcctInfo->ExpiryYY[0] == 0 ||
  975. NcAcctInfo->CCName[0] == 0)
  976. {
  977. PopUpMsg( hDlg, IDS_MISSING_BILLING, TRUE, 0 );
  978. SetWindowLong( hDlg, DWL_MSGRESULT, -1 );
  979. return TRUE;
  980. }
  981. if (!NcAcctInfo->accountInfo.SetBillingUser(&NcAcctInfo->billingOwner) ||
  982. !NcAcctInfo->accountInfo.SetCreditCardType( NcAcctInfo->CCType ) ||
  983. !NcAcctInfo->accountInfo.SetCreditCardNumber( NcAcctInfo->CreditCard ) ||
  984. !NcAcctInfo->accountInfo.SetCreditCardExpirationMM( NcAcctInfo->ExpiryMM ) ||
  985. !NcAcctInfo->accountInfo.SetCreditCardExpirationYY( NcAcctInfo->ExpiryYY ) ||
  986. !NcAcctInfo->accountInfo.SetCreditCardOwner( NcAcctInfo->CCName ))
  987. {
  988. PopUpMsg( hDlg, IDS_MISSING_BILLING, TRUE, 0 );
  989. SetWindowLong( hDlg, DWL_MSGRESULT, -1 );
  990. return TRUE;
  991. }
  992. break;
  993. }
  994. break;
  995. }
  996. return FALSE;
  997. }
  998. BOOL CALLBACK
  999. CreateDlgProc(
  1000. HWND hDlg,
  1001. UINT message,
  1002. WPARAM wParam,
  1003. LPARAM lParam,
  1004. LPNCACCTINFO NcAcctInfo
  1005. )
  1006. {
  1007. HCURSOR Hourglass;
  1008. HCURSOR OldCursor;
  1009. switch( message ) {
  1010. case WM_INITDIALOG:
  1011. break;
  1012. case WM_NOTIFY:
  1013. switch( ((LPNMHDR)lParam)->code ) {
  1014. case PSN_SETACTIVE:
  1015. break;
  1016. case PSN_WIZNEXT:
  1017. Hourglass = LoadCursor( NULL, IDC_WAIT );
  1018. OldCursor = SetCursor( Hourglass );
  1019. if (!NcAcctInfo->accountInfo.SetOwner(&NcAcctInfo->accountOwner) ||
  1020. !NcAcctInfo->accountInfo.SetPlan(NcAcctInfo->pPlan) ||
  1021. !NcAcctInfo->accountInfo.SetAccountName( NcAcctInfo->AccountName ))
  1022. {
  1023. SetCursor( OldCursor );
  1024. PopUpMsg( hDlg, IDS_MISSING_BILLING, TRUE, 0 );
  1025. SetWindowLong( hDlg, DWL_MSGRESULT, -1 );
  1026. return TRUE;
  1027. }
  1028. //
  1029. // Submit the new account information to the server. If the server
  1030. // can create the account, the SubmitAccountInfo() function will
  1031. // return TRUE. If the server rejects the information, FALSE will
  1032. // be returned. The error printed out will describe what went
  1033. // wrong, from unable to communicate with server to invalid
  1034. // account information. For example, the server would tell
  1035. // the calling application that the accountName has already been
  1036. // taken.
  1037. //
  1038. if (!NcAcctInfo->accountInfo.SubmitAccountInfo()) {
  1039. CHAR buffer[256]; UINT size=sizeof(buffer);
  1040. SetCursor( OldCursor );
  1041. NcAcctInfo->accountInfo.GetLastErrorString(buffer, &size);
  1042. PopUpMsgString( hDlg, buffer, TRUE, 0 );
  1043. SetWindowLong( hDlg, DWL_MSGRESULT, -1 );
  1044. return TRUE;
  1045. }
  1046. SetCursor( OldCursor );
  1047. break;
  1048. }
  1049. break;
  1050. }
  1051. return FALSE;
  1052. }
  1053. BOOL CALLBACK
  1054. FinishDlgProc(
  1055. HWND hDlg,
  1056. UINT message,
  1057. WPARAM wParam,
  1058. LPARAM lParam,
  1059. LPNCACCTINFO NcAcctInfo
  1060. )
  1061. {
  1062. switch( message ) {
  1063. case WM_INITDIALOG:
  1064. break;
  1065. case WM_NOTIFY:
  1066. switch( ((LPNMHDR)lParam)->code ) {
  1067. case PSN_SETACTIVE:
  1068. break;
  1069. case PSN_WIZNEXT:
  1070. break;
  1071. }
  1072. break;
  1073. }
  1074. return FALSE;
  1075. }