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.

710 lines
23 KiB

  1. #define COBJMACROS
  2. #include <_apipch.h>
  3. #include <wab.h>
  4. #define COBJMACROS
  5. #include "resource.h"
  6. #include "objbase.h"
  7. #include "ui_cflct.h"
  8. #include "commctrl.h"
  9. #include "winuser.h"
  10. typedef struct CONFLICTS_PARAM
  11. {
  12. LPHTTPCONFLICTINFO prgConflicts;
  13. DWORD cConflicts;
  14. DWORD dwCurrentContact;
  15. } CONFLICTS_PARAM, *LPCONFLICTS_PARAM;
  16. #define ListView_GetFirstSel(_hwndlist) ListView_GetNextItem(_hwndlist, -1, LVNI_SELECTED)
  17. extern LPIMAGELIST_DESTROY gpfnImageList_Destroy;
  18. // extern LPIMAGELIST_LOADIMAGE gpfnImageList_LoadImage;
  19. extern LPIMAGELIST_LOADIMAGE_A gpfnImageList_LoadImageA;
  20. extern LPIMAGELIST_LOADIMAGE_W gpfnImageList_LoadImageW;
  21. enum {
  22. LVINDEX_TITLE = 1,
  23. LVINDEX_ABVALUE = 2,
  24. LVINDEX_REPLACE = 0,
  25. LVINDEX_HMVALUE = 3,
  26. };
  27. static DWORD g_rgFieldNameIds[] =
  28. {
  29. 0,
  30. 0,
  31. 0,
  32. 0,
  33. idsDisplayName,
  34. idsGivenName,
  35. idsSurname,
  36. idsNickname,
  37. idsEmail,
  38. idsHomeStreet,
  39. idsHomeCity,
  40. idsHomeState,
  41. idsHomePostalCode,
  42. idsHomeCountry,
  43. idsCompany,
  44. idsWorkStreet,
  45. idsWorkCity,
  46. idsWorkState,
  47. idsWorkPostalCode,
  48. idsWorkCountry,
  49. idsHomePhone,
  50. idsHomeFax,
  51. idsWorkPhone,
  52. idsWorkFax,
  53. idsMobilePhone,
  54. idsOtherPhone,
  55. idsBirthday,
  56. idsPager
  57. };
  58. /*
  59. * CenterDialog
  60. *
  61. * Purpose:
  62. * This function centers a dialog with respect to its parent
  63. * dialog.
  64. *
  65. * Parameters:
  66. * hwndDlg hwnd of the dialog to center
  67. */
  68. VOID CenterDialog(HWND hwndDlg)
  69. {
  70. HWND hwndOwner;
  71. RECT rc;
  72. RECT rcDlg;
  73. RECT rcOwner;
  74. RECT rcWork;
  75. INT x;
  76. INT y;
  77. INT nAdjust;
  78. // Get the working area rectangle
  79. SystemParametersInfo(SPI_GETWORKAREA, 0, &rcWork, 0);
  80. // Get the owner window and dialog box rectangles.
  81. // The window rect of the destop window is in trouble on multimonitored
  82. // macs. GetWindow only gets the main screen.
  83. if (hwndOwner = GetParent(hwndDlg))
  84. GetWindowRect(hwndOwner, &rcOwner);
  85. else
  86. rcOwner = rcWork;
  87. GetWindowRect(hwndDlg, &rcDlg);
  88. rc = rcOwner;
  89. // Offset the owner and dialog box rectangles so that
  90. // right and bottom values represent the width and
  91. // height, and then offset the owner again to discard
  92. // space taken up by the dialog box.
  93. OffsetRect(&rcDlg, -rcDlg.left, -rcDlg.top);
  94. OffsetRect(&rc, -rc.left, -rc.top);
  95. OffsetRect(&rc, -rcDlg.right, -rcDlg.bottom);
  96. // The new position is the sum of half the remaining
  97. // space and the owner's original position.
  98. // But not less than Zero - jefbai
  99. x= rcOwner.left + (rc.right / 2);
  100. y= rcOwner.top + (rc.bottom / 2);
  101. // Make sure the dialog doesn't go off the right edge of the screen
  102. nAdjust = rcWork.right - (x + rcDlg.right);
  103. if (nAdjust < 0)
  104. x += nAdjust;
  105. //$ Raid 5128: Make sure the left edge is visible
  106. if (x < rcWork.left)
  107. x = rcWork.left;
  108. // Make sure the dialog doesn't go off the bottom edge of the screen
  109. nAdjust = rcWork.bottom - (y + rcDlg.bottom);
  110. if (nAdjust < 0)
  111. y += nAdjust;
  112. //$ Raid 5128: Make sure the top edge is visible
  113. if (y < rcWork.top)
  114. y = rcWork.top;
  115. SetWindowPos(hwndDlg, NULL, x, y, 0, 0, SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE);
  116. }
  117. static BOOL _ValidateEndConflictDialog(HWND hDlg)
  118. {
  119. return TRUE;
  120. }
  121. void _AddRow(HWND hwndList, DWORD dwIndex, DWORD dwResId, LPSTR pszServer, LPSTR pszClient, CONFLICT_DECISION cdCurrent)
  122. {
  123. LVITEM lvItem;
  124. TCHAR szRes[255];
  125. ZeroMemory(&lvItem, sizeof(lvItem));
  126. lvItem.mask = LVIF_TEXT | LVIF_PARAM | LVIF_IMAGE;
  127. LoadString(hinstMapiX, (cdCurrent == CONFLICT_IGNORE ? idsSyncSkip : idsSyncKeep), szRes, CharSizeOf(szRes));
  128. lvItem.iItem = ListView_GetItemCount(hwndList);
  129. lvItem.lParam = dwIndex;
  130. lvItem.pszText = szRes;
  131. lvItem.iImage = cdCurrent;
  132. ListView_InsertItem(hwndList, &lvItem);
  133. // [PaulHi] 1/22/99 Raid 67407 Convert single byte to double byte strings
  134. {
  135. LPWSTR lpwszServer = ConvertAtoW(pszServer);
  136. LPWSTR lpwszClient = ConvertAtoW(pszClient);
  137. ListView_SetItemText(hwndList,lvItem.iItem, LVINDEX_ABVALUE, (lpwszClient ? lpwszClient : TEXT("")));
  138. ListView_SetItemText(hwndList,lvItem.iItem, LVINDEX_HMVALUE, (lpwszServer ? lpwszServer : TEXT("")));
  139. LoadString(hinstMapiX, dwResId, szRes, CharSizeOf(szRes));
  140. ListView_SetItemText(hwndList,lvItem.iItem, LVINDEX_TITLE, szRes);
  141. LocalFreeAndNull(&lpwszServer);
  142. LocalFreeAndNull(&lpwszClient);
  143. }
  144. }
  145. void _RowSelected(HWND hDlg, LPCONFLICTS_PARAM pConflicts)
  146. {
  147. int iItem, cItems;
  148. HWND hwndList;
  149. LPHTTPCONFLICTINFO pCurrConflict = &(pConflicts->prgConflicts[pConflicts->dwCurrentContact]);
  150. hwndList = GetDlgItem(hDlg, IDC_SYNC_LIST);
  151. iItem = ListView_GetFirstSel(hwndList);
  152. cItems = ListView_GetSelectedCount(hwndList);
  153. if (iItem >= 0)
  154. {
  155. LVITEM lvItem;
  156. TCHAR szRes[256];
  157. ZeroMemory(&lvItem, sizeof(lvItem));
  158. lvItem.mask = LVIF_TEXT | LVIF_PARAM;
  159. lvItem.pszText = szRes;
  160. lvItem.cchTextMax = 255;
  161. lvItem.iItem = iItem;
  162. lvItem.iSubItem = LVINDEX_TITLE;
  163. if (ListView_GetItem(hwndList, &lvItem))
  164. {
  165. if (cItems > 1)
  166. LoadString(hinstMapiX, idsMultipleSelected, szRes, CharSizeOf(szRes));
  167. SetDlgItemText(hDlg, IDC_SYNC_FIELDNAME, szRes);
  168. CheckDlgButton(hDlg, IDC_SYNC_ADDRESSBOOK, FALSE);
  169. CheckDlgButton(hDlg, IDC_SYNC_HOTMAIL, FALSE);
  170. CheckDlgButton(hDlg, IDC_SYNC_IGNORE, FALSE);
  171. if (cItems == 1)
  172. {
  173. switch(pCurrConflict->rgcd[lvItem.lParam])
  174. {
  175. case CONFLICT_IGNORE:
  176. CheckDlgButton(hDlg, IDC_SYNC_IGNORE, TRUE);
  177. break;
  178. case CONFLICT_SERVER:
  179. CheckDlgButton(hDlg, IDC_SYNC_HOTMAIL, TRUE);
  180. break;
  181. case CONFLICT_CLIENT:
  182. CheckDlgButton(hDlg, IDC_SYNC_ADDRESSBOOK, TRUE);
  183. break;
  184. }
  185. }
  186. }
  187. }
  188. }
  189. BOOL _PageContainsSkip(HWND hDlg, LPCONFLICTS_PARAM pConflicts)
  190. {
  191. int iItem, cItems;
  192. LVITEM lvItem;
  193. LPHTTPCONFLICTINFO pCurrConflict = &(pConflicts->prgConflicts[pConflicts->dwCurrentContact]);
  194. HWND hwndList;
  195. hwndList = GetDlgItem(hDlg, IDC_SYNC_LIST);
  196. cItems = ListView_GetItemCount(hwndList);
  197. pCurrConflict->fContainsSkip = FALSE;
  198. for (iItem = 0; iItem < cItems; iItem++)
  199. {
  200. ZeroMemory(&lvItem, sizeof(lvItem));
  201. lvItem.mask = LVIF_PARAM;
  202. lvItem.cchTextMax = 0;
  203. lvItem.iItem = iItem;
  204. lvItem.iSubItem = LVINDEX_TITLE;
  205. if (ListView_GetItem(hwndList, &lvItem))
  206. {
  207. switch(pCurrConflict->rgcd[lvItem.lParam])
  208. {
  209. case CONFLICT_IGNORE:
  210. pCurrConflict->fContainsSkip = TRUE;
  211. break;
  212. case CONFLICT_SERVER:
  213. break;
  214. case CONFLICT_CLIENT:
  215. break;
  216. }
  217. }
  218. if (pCurrConflict->fContainsSkip)
  219. break;
  220. }
  221. return pCurrConflict->fContainsSkip;
  222. }
  223. static void _FillInPage(HWND hDlg, LPCONFLICTS_PARAM pConflicts)
  224. {
  225. HWND hwndList;
  226. LPHTTPCONFLICTINFO pCurrConflict = &(pConflicts->prgConflicts[pConflicts->dwCurrentContact]);
  227. TCHAR szName[255] = TEXT("");
  228. LPTSTR psz = szName;
  229. LPSTR *ppszServer = (LPSTR *)pCurrConflict->pciServer;
  230. LPSTR *ppszClient = (LPSTR *)pCurrConflict->pciClient;
  231. DWORD dwCount = ARRAYSIZE(g_rgFieldNameIds), dwIndex;
  232. if (pCurrConflict->pciClient->pszDisplayName)
  233. psz = ConvertAtoW(pCurrConflict->pciClient->pszDisplayName);
  234. else if (pCurrConflict->pciClient->pszGivenName && pCurrConflict->pciClient->pszSurname)
  235. {
  236. wnsprintf(szName, ARRAYSIZE(szName), TEXT("%s %s"), pCurrConflict->pciClient->pszGivenName, pCurrConflict->pciClient->pszSurname);
  237. psz = szName;
  238. }
  239. else if (pCurrConflict->pciServer->pszGivenName && pCurrConflict->pciServer->pszSurname)
  240. {
  241. wnsprintf(szName, ARRAYSIZE(szName), TEXT("%s %s"), pCurrConflict->pciServer->pszGivenName, pCurrConflict->pciServer->pszSurname);
  242. psz = szName;
  243. }
  244. else if (pCurrConflict->pciServer->pszNickname)
  245. {
  246. psz = ConvertAtoW(pCurrConflict->pciServer->pszNickname);
  247. }
  248. SetDlgItemText(hDlg, IDC_SYNC_CONTACTNAME, psz);
  249. hwndList = GetDlgItem(hDlg, IDC_SYNC_LIST);
  250. ListView_DeleteAllItems(hwndList);
  251. ListView_SetExtendedListViewStyle(hwndList, LVS_EX_FULLROWSELECT | LVS_EX_SUBITEMIMAGES);
  252. for (dwIndex = 5; dwIndex < dwCount; dwIndex++)
  253. {
  254. if (ppszServer[dwIndex] && ppszClient[dwIndex])
  255. {
  256. if (lstrcmpA(ppszServer[dwIndex], ppszClient[dwIndex]))
  257. _AddRow(hwndList, dwIndex, g_rgFieldNameIds[dwIndex], ppszServer[dwIndex], ppszClient[dwIndex], pCurrConflict->rgcd[dwIndex]);
  258. }
  259. else
  260. {
  261. if( ppszServer[dwIndex] || ppszClient[dwIndex])
  262. _AddRow(hwndList, dwIndex, g_rgFieldNameIds[dwIndex], ppszServer[dwIndex], ppszClient[dwIndex], pCurrConflict->rgcd[dwIndex]);
  263. }
  264. }
  265. EnableWindow(GetDlgItem(hDlg, IDC_SYNC_NEXT), (pConflicts->dwCurrentContact < pConflicts->cConflicts - 1));
  266. EnableWindow(GetDlgItem(hDlg, IDC_SYNC_BACK), pConflicts->dwCurrentContact > 0);
  267. CheckDlgButton(hDlg, IDC_SYNC_ADDRESSBOOK, FALSE);
  268. CheckDlgButton(hDlg, IDC_SYNC_HOTMAIL, FALSE);
  269. CheckDlgButton(hDlg, IDC_SYNC_IGNORE, FALSE);
  270. SetDlgItemText(hDlg, IDC_SYNC_FIELDNAME, TEXT(""));
  271. ListView_SetItemState(hwndList, 0, LVIS_SELECTED, LVIS_SELECTED);
  272. _RowSelected(hDlg, pConflicts);
  273. if(psz != szName)
  274. LocalFreeAndNull(&psz);
  275. }
  276. void _ChangeDecision(HWND hDlg, LPCONFLICTS_PARAM pConflicts, CONFLICT_DECISION cdNew)
  277. {
  278. int iItem, cItems, i;
  279. HWND hwndList;
  280. LPHTTPCONFLICTINFO pCurrConflict = &(pConflicts->prgConflicts[pConflicts->dwCurrentContact]);
  281. hwndList = GetDlgItem(hDlg, IDC_SYNC_LIST);
  282. iItem = -1;
  283. cItems = ListView_GetSelectedCount(hwndList);
  284. for (i = 0; i < cItems; i++)
  285. {
  286. iItem = ListView_GetNextItem(hwndList, iItem, LVNI_SELECTED);
  287. if (iItem >= 0)
  288. {
  289. LVITEM lvItem;
  290. TCHAR szRes[256];
  291. ZeroMemory(&lvItem, sizeof(lvItem));
  292. lvItem.mask = LVIF_TEXT | LVIF_PARAM;
  293. lvItem.pszText = szRes;
  294. lvItem.cchTextMax = 255;
  295. lvItem.iItem = iItem;
  296. if (ListView_GetItem(hwndList, &lvItem))
  297. {
  298. DWORD dwResId;
  299. pCurrConflict->rgcd[lvItem.lParam] = cdNew;
  300. dwResId = (cdNew == CONFLICT_IGNORE ? idsSyncSkip : idsSyncKeep);
  301. LoadString(hinstMapiX, dwResId, szRes, CharSizeOf(szRes));
  302. lvItem.pszText = szRes;
  303. lvItem.mask = LVIF_TEXT | LVIF_IMAGE;
  304. lvItem.iSubItem = 0;
  305. lvItem.iImage = cdNew;
  306. ListView_SetItem(hwndList, &lvItem);
  307. // ListView_SetItemText(hwndList,lvItem.iItem, 2, (cdNew == CONFLICT_IGNORE ? "X": (cdNew == CONFLICT_SERVER ? "-->": "<--")));
  308. }
  309. }
  310. }
  311. }
  312. static void _InitConflictList(HWND hwnd)
  313. {
  314. LVCOLUMN lvCol;
  315. int rgiColOrder[4] = {LVINDEX_TITLE, LVINDEX_ABVALUE, LVINDEX_REPLACE, LVINDEX_HMVALUE};
  316. RECT rcWnd;
  317. int iColWidth;
  318. HIMAGELIST hImageList;
  319. TCHAR szRes[255];
  320. if (hImageList = gpfnImageList_LoadImage(hinstMapiX,
  321. MAKEINTRESOURCE(IDB_SYNC_SYNCOP),
  322. //(LPCTSTR) ((DWORD) ((WORD) (IDB_SYNC_SYNCOP))),
  323. 16,
  324. 0,
  325. RGB(255, 0, 255),
  326. IMAGE_BITMAP,
  327. 0))
  328. ListView_SetImageList(hwnd, hImageList, LVSIL_SMALL);
  329. GetClientRect(hwnd, &rcWnd);
  330. iColWidth = ((rcWnd.right - rcWnd.left) - 180) / 2;
  331. LoadString(hinstMapiX, idsSyncReplace, szRes, CharSizeOf(szRes));
  332. lvCol.mask = LVCF_TEXT | LVCF_FMT;
  333. lvCol.pszText = szRes;
  334. lvCol.fmt = LVCFMT_LEFT;
  335. ListView_InsertColumn(hwnd, LVINDEX_REPLACE, &lvCol);
  336. LoadString(hinstMapiX, idsSyncField, szRes, CharSizeOf(szRes));
  337. ListView_InsertColumn(hwnd, LVINDEX_TITLE, &lvCol);
  338. LoadString(hinstMapiX, idsSyncABInfo, szRes, CharSizeOf(szRes));
  339. ListView_InsertColumn(hwnd, LVINDEX_ABVALUE, &lvCol);
  340. LoadString(hinstMapiX, idsSyncHMInfo, szRes, CharSizeOf(szRes));
  341. ListView_InsertColumn(hwnd, LVINDEX_HMVALUE, &lvCol);
  342. ListView_SetColumnWidth(hwnd,LVINDEX_TITLE,120);
  343. ListView_SetColumnWidth(hwnd,LVINDEX_ABVALUE,iColWidth);
  344. ListView_SetColumnWidth(hwnd,LVINDEX_REPLACE,65);
  345. ListView_SetColumnWidth(hwnd,LVINDEX_HMVALUE,iColWidth);
  346. ListView_SetColumnOrderArray(hwnd, 4, &rgiColOrder);
  347. }
  348. /*
  349. _ConflictDlgProc
  350. Description: Dialog proc for handling the contact conflict.
  351. */
  352. INT_PTR CALLBACK _ConflictDlgProc(HWND hDlg,
  353. UINT iMsg,
  354. WPARAM wParam,
  355. LPARAM lParam)
  356. {
  357. static char *sOldNewPassword;
  358. HWND hwndList;
  359. LPCONFLICTS_PARAM pConflicts = NULL;
  360. switch (iMsg)
  361. {
  362. case WM_INITDIALOG:
  363. pConflicts = (LPCONFLICTS_PARAM)lParam;
  364. CenterDialog(hDlg);
  365. hwndList = GetDlgItem(hDlg, IDC_SYNC_LIST);
  366. _InitConflictList(hwndList);
  367. pConflicts->dwCurrentContact = 0;
  368. SetWindowLongPtr(hDlg, GWLP_USERDATA, (LONG_PTR)pConflicts);
  369. _FillInPage(hDlg, pConflicts);
  370. return TRUE;
  371. case WM_DESTROY:
  372. // Free image lists
  373. hwndList = GetDlgItem(hDlg, IDC_SYNC_LIST);
  374. if (IsWindow(hwndList) && NULL != gpfnImageList_Destroy)
  375. {
  376. HIMAGELIST hImageList;
  377. hImageList = ListView_GetImageList(hwndList, LVSIL_SMALL);
  378. if (NULL != hImageList)
  379. gpfnImageList_Destroy(hImageList);
  380. }
  381. return TRUE;
  382. case WM_HELP:
  383. case WM_CONTEXTMENU:
  384. // return OnContextHelp(hDlg, iMsg, wParam, lParam, g_rgCtxMapMultiUserGeneral);
  385. return TRUE;
  386. case WM_SETFONT:
  387. return TRUE;
  388. case WM_COMMAND:
  389. pConflicts = (LPCONFLICTS_PARAM)GetWindowLongPtr(hDlg, GWLP_USERDATA);
  390. if (!pConflicts)
  391. break;
  392. switch(LOWORD(wParam))
  393. {
  394. case IDC_SYNC_NEXT:
  395. _PageContainsSkip(hDlg, pConflicts);
  396. pConflicts->dwCurrentContact++;
  397. _FillInPage(hDlg, pConflicts);
  398. return TRUE;
  399. case IDC_SYNC_BACK:
  400. _PageContainsSkip(hDlg, pConflicts);
  401. pConflicts->dwCurrentContact--;
  402. _FillInPage(hDlg, pConflicts);
  403. return TRUE;
  404. case IDC_SYNC_ADDRESSBOOK:
  405. _ChangeDecision(hDlg, pConflicts, CONFLICT_CLIENT);
  406. return TRUE;
  407. case IDC_SYNC_HOTMAIL:
  408. _ChangeDecision(hDlg, pConflicts, CONFLICT_SERVER);
  409. return TRUE;
  410. case IDC_SYNC_IGNORE:
  411. _ChangeDecision(hDlg, pConflicts, CONFLICT_IGNORE);
  412. return TRUE;
  413. case IDOK:
  414. _PageContainsSkip(hDlg, pConflicts);
  415. if (_ValidateEndConflictDialog(hDlg))
  416. EndDialog(hDlg, IDOK);
  417. return TRUE;
  418. case IDCANCEL:
  419. EndDialog(hDlg, IDCANCEL);
  420. return TRUE;
  421. }
  422. break;
  423. case WM_NOTIFY:
  424. // Branch depending on the specific notification message.
  425. switch (((LPNMHDR) lParam)->code) {
  426. // selection changed, update the contols
  427. case NM_CLICK:
  428. case NM_CUSTOMDRAW:
  429. case LVN_BEGINDRAG:
  430. case LVN_ODSTATECHANGED:
  431. pConflicts = (LPCONFLICTS_PARAM)GetWindowLongPtr(hDlg, GWLP_USERDATA);
  432. _RowSelected(hDlg, pConflicts);
  433. break;
  434. // Process LVN_ENDLABELEDIT to change item labels after
  435. // in-place editing.
  436. case LVN_ENDLABELEDITA:
  437. case LVN_ENDLABELEDITW:
  438. break;
  439. // Process LVN_COLUMNCLICK to sort items by column.
  440. case LVN_COLUMNCLICK:
  441. break;
  442. }
  443. break;
  444. }
  445. return FALSE;
  446. }
  447. /*
  448. ResolveConflicts
  449. */
  450. BOOL ResolveConflicts(HWND hwnd, LPHTTPCONFLICTINFO prgConflicts, DWORD cConflicts)
  451. {
  452. int bResult;
  453. DWORD dwErr;
  454. CONFLICTS_PARAM cParam = {0};
  455. Assert(hwnd);
  456. if (cConflicts == 0)
  457. return S_OK;
  458. cParam.cConflicts = cConflicts;
  459. cParam.prgConflicts = prgConflicts;
  460. bResult = (int) DialogBoxParam(hinstMapiX, MAKEINTRESOURCE(iddConflict), hwnd, _ConflictDlgProc, (LPARAM)&cParam);
  461. dwErr = GetLastError();
  462. return (bResult == IDOK);
  463. }
  464. typedef struct tagChooseServer
  465. {
  466. IImnEnumAccounts *pEnumAccts;
  467. LPSTR pszName;
  468. DWORD cchName;
  469. } CHOOSE_SERVER_PARAM;
  470. /*
  471. _ChooseServerDlgProc
  472. Description: Dialog proc for handling the choose server.
  473. */
  474. INT_PTR CALLBACK _ChooseServerDlgProc(HWND hDlg,
  475. UINT iMsg,
  476. WPARAM wParam,
  477. LPARAM lParam)
  478. {
  479. CHOOSE_SERVER_PARAM *pParams;
  480. HWND hwndList;
  481. DWORD i, dwCount;
  482. HRESULT hr;
  483. switch (iMsg)
  484. {
  485. case WM_INITDIALOG:
  486. pParams = (CHOOSE_SERVER_PARAM*)lParam;
  487. CenterDialog(hDlg);
  488. hwndList = GetDlgItem(hDlg, IDC_SERVER_LIST);
  489. SetWindowLongPtr(hDlg, GWLP_USERDATA, (LONG_PTR)pParams);
  490. SendMessage(hwndList, LB_RESETCONTENT, 0, 0);
  491. *pParams->pszName = 0;
  492. pParams->pEnumAccts->lpVtbl->Reset(pParams->pEnumAccts);
  493. pParams->pEnumAccts->lpVtbl->SortByAccountName(pParams->pEnumAccts);
  494. if (SUCCEEDED(hr = pParams->pEnumAccts->lpVtbl->GetCount(pParams->pEnumAccts, &dwCount)))
  495. {
  496. IImnAccount *pAccount = NULL;
  497. char szAcctName[CCHMAX_ACCOUNT_NAME+1];
  498. DWORD ccb;
  499. for (i = 0; i < dwCount; i++)
  500. {
  501. if (SUCCEEDED(hr = pParams->pEnumAccts->lpVtbl->GetNext(pParams->pEnumAccts, &pAccount)))
  502. {
  503. ccb = CharSizeOf(szAcctName);
  504. if (FAILED(hr = pAccount->lpVtbl->GetProp(pAccount, AP_ACCOUNT_NAME, szAcctName, &ccb)))
  505. continue;
  506. // [PaulHi] 1/19/99 Raid 66195
  507. // Must use wide character string
  508. {
  509. LPWSTR lpwszAcctName = ConvertAtoW(szAcctName);
  510. SendMessage(hwndList, LB_ADDSTRING, 0, (LPARAM)lpwszAcctName);
  511. LocalFreeAndNull(&lpwszAcctName);
  512. }
  513. pAccount->lpVtbl->Release(pAccount);
  514. }
  515. }
  516. }
  517. else
  518. return FALSE;
  519. return TRUE;
  520. case WM_HELP:
  521. case WM_CONTEXTMENU:
  522. // return OnContextHelp(hDlg, iMsg, wParam, lParam, g_rgCtxMapMultiUserGeneral);
  523. return TRUE;
  524. case WM_SETFONT:
  525. return TRUE;
  526. case WM_COMMAND:
  527. switch(HIWORD(wParam))
  528. {
  529. case LBN_DBLCLK:
  530. wParam = IDOK;
  531. break;
  532. case LBN_SELCHANGE:
  533. break;
  534. }
  535. pParams = (CHOOSE_SERVER_PARAM*)GetWindowLongPtr(hDlg, GWLP_USERDATA);
  536. if (!pParams)
  537. break;
  538. switch(LOWORD(wParam))
  539. {
  540. DWORD dwSelItem;
  541. case IDOK:
  542. dwSelItem = (DWORD) SendDlgItemMessage(hDlg, IDC_SERVER_LIST, LB_GETCURSEL, 0, 0);
  543. if (LB_ERR != dwSelItem)
  544. {
  545. // [PaulHi] 1/19/99 Raid 66195
  546. // Convert wide char back to MB
  547. TCHAR tszName[CCHMAX_ACCOUNT_NAME+1]=TEXT("");
  548. LPSTR lpstr = NULL;
  549. int nLen;
  550. nLen = (int)SendDlgItemMessage(hDlg, IDC_SERVER_LIST, LB_GETTEXTLEN, dwSelItem, 0);
  551. if (nLen < ARRAYSIZE(tszName))
  552. {
  553. nLen = (int) SendDlgItemMessage(hDlg, IDC_SERVER_LIST, LB_GETTEXT, dwSelItem, (LPARAM)tszName);
  554. }
  555. AssertSz((nLen <= CCHMAX_ACCOUNT_NAME), TEXT("ChooseHotmailServer: Returned account name too large for buffer"));
  556. lpstr = ConvertWtoA(tszName);
  557. StrCpyNA(pParams->pszName, lpstr, pParams->cchName);
  558. LocalFreeAndNull(&lpstr);
  559. EndDialog(hDlg, IDOK);
  560. }
  561. return TRUE;
  562. case IDCANCEL:
  563. EndDialog(hDlg, IDCANCEL);
  564. return TRUE;
  565. }
  566. break;
  567. }
  568. return FALSE;
  569. }
  570. /*
  571. ChooseHotmailServer
  572. */
  573. BOOL ChooseHotmailServer(HWND hwnd, IImnEnumAccounts *pEnumAccts, LPSTR pszAccountName, DWORD cchAccountName)
  574. {
  575. int bResult;
  576. DWORD dwErr;
  577. CHOOSE_SERVER_PARAM cParam = {0};
  578. Assert(hwnd);
  579. cParam.pEnumAccts = pEnumAccts;
  580. cParam.pszName = pszAccountName;
  581. cParam.cchName = cchAccountName;
  582. bResult = (int) DialogBoxParam(hinstMapiX, MAKEINTRESOURCE(iddChooseServer), hwnd, _ChooseServerDlgProc, (LPARAM)&cParam);
  583. return (bResult == IDOK);
  584. }