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.

1513 lines
40 KiB

  1. //+-------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1997.
  5. //
  6. // File: Choice.cpp
  7. //
  8. // Contents: Implements the choice dialog
  9. //
  10. // Classes: CChoiceDlg
  11. //
  12. // Notes:
  13. //
  14. // History: 05-Nov-97 rogerg Created.
  15. //
  16. //--------------------------------------------------------------------------
  17. #include "precomp.h"
  18. const DlgResizeList g_ChoiceResizeList[] = {
  19. IDC_CHOICERESIZESCROLLBAR,DLGRESIZEFLAG_PINRIGHT | DLGRESIZEFLAG_PINBOTTOM,
  20. IDC_START,DLGRESIZEFLAG_PINRIGHT | DLGRESIZEFLAG_PINBOTTOM | DLGRESIZEFLAG_NOCOPYBITS,
  21. IDC_OPTIONS,DLGRESIZEFLAG_PINRIGHT | DLGRESIZEFLAG_PINBOTTOM | DLGRESIZEFLAG_NOCOPYBITS,
  22. IDC_CLOSE,DLGRESIZEFLAG_PINRIGHT | DLGRESIZEFLAG_PINBOTTOM | DLGRESIZEFLAG_NOCOPYBITS,
  23. IDC_CHOICELISTVIEW,DLGRESIZEFLAG_PINRIGHT | DLGRESIZEFLAG_PINBOTTOM | DLGRESIZEFLAG_PINTOP | DLGRESIZEFLAG_PINLEFT,
  24. IDC_PROPERTY,DLGRESIZEFLAG_PINRIGHT | DLGRESIZEFLAG_PINBOTTOM | DLGRESIZEFLAG_NOCOPYBITS,
  25. };
  26. TCHAR g_szSyncMgrHelp[] = TEXT("mobsync.hlp");
  27. ULONG g_aContextHelpIds[] =
  28. {
  29. IDC_STATIC1, ((DWORD) -1),
  30. IDC_STATIC2, ((DWORD) -1),
  31. IDC_STATIC3, ((DWORD) -1),
  32. IDC_STATIC4, ((DWORD) -1),
  33. IDC_STATIC5, ((DWORD) -1),
  34. IDC_UPDATEAVI, ((DWORD) -1),
  35. IDC_RESULTTEXT, ((DWORD) -1),
  36. IDC_STATIC_SKIP_TEXT, ((DWORD) -1),
  37. IDC_CHOICELISTVIEW, HIDC_CHOICELISTVIEW,
  38. IDC_CLOSE, HIDC_CLOSE,
  39. IDC_DETAILS, HIDC_DETAILS,
  40. IDC_LISTBOXERROR, HIDC_LISTBOXERROR,
  41. IDC_OPTIONS, HIDC_OPTIONS,
  42. IDC_PROGRESSBAR, HIDC_PROGRESSBAR,
  43. IDC_PROGRESS_OPTIONS_BUTTON_MAIN, HIDC_PROGRESS_OPTIONS_BUTTON_MAIN,
  44. IDC_PROPERTY, HIDC_PROPERTY,
  45. IDC_SKIP_BUTTON_MAIN, HIDC_SKIP_BUTTON_MAIN,
  46. IDC_START, HIDC_START,
  47. IDC_UPDATE_LIST, HIDC_UPDATE_LIST,
  48. IDC_PROGRESS_TABS, HIDC_PROGRESS_TABS,
  49. IDC_TOOLBAR, HIDC_PUSHPIN,
  50. IDSTOP, HIDSTOP,
  51. 0, 0
  52. };
  53. extern HINSTANCE g_hInst; // current instance
  54. extern OSVERSIONINFOA g_OSVersionInfo; // osVersionInfo, setup by WinMain.
  55. extern LANGID g_LangIdSystem; // langID of system we are running on.
  56. //--------------------------------------------------------------------------------
  57. //
  58. // FUNCTION: CChoiceDlg::CChoiceDlg()
  59. //
  60. // PURPOSE: Constructor
  61. //
  62. // COMMENTS: Constructor for choice dialog
  63. //
  64. //
  65. //--------------------------------------------------------------------------------
  66. CChoiceDlg::CChoiceDlg(REFCLSID rclsid)
  67. {
  68. m_fDead = FALSE;
  69. m_hwnd = NULL;
  70. m_nCmdShow = SW_SHOWNORMAL;
  71. m_pHndlrQueue = NULL;
  72. m_clsid = rclsid;
  73. m_dwThreadID = 0;
  74. m_fInternalAddref = FALSE;
  75. m_dwShowPropertiesCount = 0;
  76. m_fForceClose = FALSE;
  77. m_pItemListView = NULL;
  78. m_ulNumDlgResizeItem = 0;
  79. m_ptMinimizeDlgSize.x = 0;
  80. m_ptMinimizeDlgSize.y = 0;
  81. m_fHwndRightToLeft = FALSE;
  82. }
  83. //--------------------------------------------------------------------------------
  84. //
  85. // FUNCTION: CChoiceDlg::Initialize
  86. //
  87. // PURPOSE: Must be called before any other methods.
  88. //
  89. //
  90. //--------------------------------------------------------------------------------
  91. BOOL CChoiceDlg::Initialize(DWORD dwThreadID,int nCmdShow)
  92. {
  93. m_nCmdShow = nCmdShow;
  94. Assert(NULL == m_hwnd);
  95. if (NULL == m_hwnd)
  96. {
  97. m_dwThreadID = dwThreadID;
  98. m_hwnd = CreateDialogParam(g_hInst,(LPWSTR) MAKEINTRESOURCE(IDD_CHOICE),NULL, (DLGPROC) CChoiceDlgProc,
  99. (LPARAM) this);
  100. }
  101. Assert(m_hwnd);
  102. return m_hwnd ? TRUE : FALSE;
  103. }
  104. //--------------------------------------------------------------------------------
  105. //
  106. // FUNCTION: CChoiceDlg::SetQueueData()
  107. //
  108. // PURPOSE: Sets the Choice dialog queue
  109. //
  110. // COMMENTS: Does a SendMessage to get on the same thread as the dialog
  111. //
  112. //
  113. //--------------------------------------------------------------------------------
  114. BOOL CChoiceDlg::SetQueueData(REFCLSID rclsid,CHndlrQueue * pHndlrQueue)
  115. {
  116. SetQueueDataInfo dataInfo;
  117. BOOL fSet = FALSE;
  118. dataInfo.rclsid = &rclsid;
  119. dataInfo.pHndlrQueue = pHndlrQueue;
  120. SendMessage(m_hwnd,WM_CHOICE_SETQUEUEDATA,
  121. (WPARAM) &fSet,(LPARAM) &dataInfo);
  122. return fSet;
  123. }
  124. //--------------------------------------------------------------------------------
  125. //
  126. // FUNCTION: CChoiceDlg::PrivSetQueueData()
  127. //
  128. // PURPOSE: Sets the QueueData
  129. //
  130. // COMMENTS: Can be called multiple times if the dialg is invoked twice.
  131. //
  132. //
  133. //--------------------------------------------------------------------------------
  134. BOOL CChoiceDlg::PrivSetQueueData(REFCLSID rclsid,CHndlrQueue * pHndlrQueue)
  135. {
  136. if (NULL == pHndlrQueue)
  137. return FALSE;
  138. // if already have a queue then transfer the given queue items, else just
  139. // set the items.
  140. // reivew, special case UpdateAll dialog to just bring it to front
  141. // instead of adding all the items again.
  142. // if a request comes in to add after we have removed our addref or
  143. // haven't set it yet then stick an addref on the dialog
  144. if (FALSE == m_fInternalAddref)
  145. {
  146. m_fInternalAddref = TRUE;
  147. SetChoiceReleaseDlgCmdId(rclsid,this,RELEASEDLGCMDID_CANCEL);
  148. AddRefChoiceDialog(rclsid,this); // first time addref to keep alive.
  149. }
  150. if (NULL == m_pHndlrQueue)
  151. {
  152. m_pHndlrQueue = pHndlrQueue;
  153. m_pHndlrQueue->SetQueueHwnd(this);
  154. m_clsid = rclsid;
  155. }
  156. else
  157. {
  158. Assert(m_clsid == rclsid); // better have found the same choice dialog.
  159. Assert(NULL != m_pHndlrQueue);
  160. // !! warninng if you return an error it is up to the caller to free the queue.
  161. if (m_pHndlrQueue)
  162. {
  163. m_pHndlrQueue->TransferQueueData(pHndlrQueue); // review, what should do on error.
  164. // ALL QUEUE DATA SHOULD BE TRANSFERED.
  165. pHndlrQueue->FreeAllHandlers();
  166. pHndlrQueue->Release();
  167. }
  168. }
  169. AddNewItemsToListView(); // add the items to the ListView.
  170. // go ahead and show the choice dialog now that there are
  171. // items to display
  172. ShowChoiceDialog();
  173. return TRUE;
  174. }
  175. //--------------------------------------------------------------------------------
  176. //
  177. // FUNCTION: CChoiceDlg::SetButtonState
  178. //
  179. // PURPOSE:
  180. //
  181. //
  182. //
  183. //
  184. //--------------------------------------------------------------------------------
  185. BOOL CChoiceDlg::SetButtonState(int nIDDlgItem,BOOL fEnabled)
  186. {
  187. BOOL fResult = FALSE;
  188. HWND hwndCtrl = GetDlgItem(m_hwnd,nIDDlgItem);
  189. HWND hwndFocus = NULL;
  190. if (hwndCtrl)
  191. {
  192. // if state is current state then don't do anything
  193. // !! in case IsWindowEnable bool doesn't == our bool
  194. if ( (!!IsWindowEnabled(hwndCtrl)) == (!!fEnabled) )
  195. {
  196. return fEnabled;
  197. }
  198. if (!fEnabled) // don't bother getting focus if not disabling.
  199. {
  200. hwndFocus = GetFocus();
  201. }
  202. fResult = EnableWindow(GetDlgItem(m_hwnd,nIDDlgItem),fEnabled);
  203. // if control had the focus. and now it doesn't then tab to the
  204. // next control
  205. if (hwndFocus == hwndCtrl
  206. && !fEnabled)
  207. {
  208. SetFocus(GetDlgItem(m_hwnd,IDC_CLOSE)); // close is always enabled.
  209. }
  210. }
  211. return fResult;
  212. }
  213. //+---------------------------------------------------------------------------
  214. //
  215. // Member: CChoiceDlg::AddQueueItemsToListView, private
  216. //
  217. // Synopsis: Adds the items in the Queue to the ListView.
  218. //
  219. // Arguments:
  220. //
  221. // Returns:
  222. //
  223. // Modifies:
  224. //
  225. // History: 30-Jul-98 rogerg Created.
  226. //
  227. //----------------------------------------------------------------------------
  228. BOOL CChoiceDlg::AddNewItemsToListView()
  229. {
  230. DWORD dwExtStyle = LVS_EX_CHECKBOXES | LVS_EX_FULLROWSELECT | LVS_EX_INFOTIP;
  231. LVHANDLERITEMBLOB lvEmptyItemBlob;
  232. // set up the list view
  233. if (!m_pItemListView)
  234. {
  235. Assert(m_pItemListView);
  236. return FALSE;
  237. }
  238. // if emptyItem is in list View delete it.
  239. lvEmptyItemBlob.cbSize = sizeof(LVHANDLERITEMBLOB);
  240. lvEmptyItemBlob.clsidServer = GUID_NULL;
  241. lvEmptyItemBlob.ItemID = GUID_NULL;
  242. if (-1 != m_pItemListView->FindItemFromBlob((LPLVBLOB) &lvEmptyItemBlob))
  243. {
  244. int ListViewWidth = CalcListViewWidth(GetDlgItem(m_hwnd,IDC_CHOICELISTVIEW));
  245. m_pItemListView->DeleteAllItems();
  246. // adjust the column widths back
  247. m_pItemListView->SetColumnWidth(0,(ListViewWidth * 2)/3);
  248. m_pItemListView->SetColumnWidth(1,ListViewWidth/3);
  249. }
  250. AddItemsFromQueueToListView(m_pItemListView,m_pHndlrQueue,dwExtStyle,0,
  251. CHOICELIST_LASTUPDATECOLUMN,/* iDateColumn */ -1 /*status column */,TRUE /* fUseHandlerAsParent */
  252. ,FALSE /* fAddOnlyCheckedItems */);
  253. // Set StartButton State in case don't have any checks would
  254. // m_iCheckCount set by listview notification.
  255. SetButtonState(IDC_START,m_pItemListView->GetCheckedItemsCount());
  256. // if no items are in the ListView then done, put in the NoItems to Sync Info.
  257. if (0 == m_pItemListView->GetItemCount())
  258. {
  259. TCHAR szBuf[MAX_STRING_RES];
  260. RECT rcClientRect;
  261. HIMAGELIST himageSmallIcon = m_pItemListView->GetImageList(LVSIL_SMALL );
  262. //disable the check box list view style
  263. m_pItemListView->SetExtendedListViewStyle(LVS_EX_FULLROWSELECT | LVS_EX_INFOTIP );
  264. // adjust the column widths
  265. if (GetClientRect(GetDlgItem(m_hwnd,IDC_CHOICELISTVIEW),&rcClientRect))
  266. {
  267. m_pItemListView->SetColumnWidth(1,0);
  268. m_pItemListView->SetColumnWidth(0,rcClientRect.right -2);
  269. }
  270. LoadString(g_hInst,IDS_NOITEMS, szBuf, ARRAY_SIZE(szBuf));
  271. LVITEMEX lvitem;
  272. lvitem.mask = LVIF_TEXT | LVIF_IMAGE ;
  273. lvitem.iItem = 0;
  274. lvitem.iSubItem = 0;
  275. lvitem.pszText = szBuf;
  276. lvitem.iImage = -1;
  277. if (himageSmallIcon)
  278. {
  279. lvitem.iImage = ImageList_AddIcon(himageSmallIcon,LoadIcon(NULL, IDI_INFORMATION));
  280. }
  281. lvitem.maskEx = LVIFEX_BLOB;
  282. lvitem.pBlob = (LPLVBLOB) &lvEmptyItemBlob;
  283. m_pItemListView->InsertItem(&lvitem);
  284. m_pItemListView->SetItemState(0,
  285. LVIS_SELECTED | LVIS_FOCUSED, LVIS_SELECTED | LVIS_FOCUSED );
  286. // Reset the current default push button to a regular button.
  287. SendDlgItemMessage(m_hwnd, IDC_START, BM_SETSTYLE, BS_PUSHBUTTON, (LPARAM)TRUE);
  288. // Update the default push button's control ID.
  289. SendMessage(m_hwnd, DM_SETDEFID, IDC_CLOSE, 0L);
  290. // Set the new style.
  291. SendDlgItemMessage(m_hwnd, IDC_CLOSE,BM_SETSTYLE, BS_DEFPUSHBUTTON, (LPARAM)TRUE);
  292. }
  293. m_pItemListView->SetItemState(0,
  294. LVIS_SELECTED | LVIS_FOCUSED, LVIS_SELECTED | LVIS_FOCUSED );
  295. return TRUE;
  296. }
  297. //--------------------------------------------------------------------------------
  298. //
  299. // FUNCTION: CChoiceDlg::ShowChoiceDialog()
  300. //
  301. // PURPOSE: Initialize and display the Choice Dialog
  302. //
  303. // COMMENTS: Implemented on main thread.
  304. //
  305. //
  306. //--------------------------------------------------------------------------------
  307. BOOL CChoiceDlg::ShowChoiceDialog()
  308. {
  309. // Review, this needs to get cleanedup
  310. if (!m_hwnd)
  311. {
  312. Assert(m_hwnd);
  313. return FALSE;
  314. }
  315. return TRUE;
  316. }
  317. //--------------------------------------------------------------------------------
  318. //
  319. // FUNCTION: CChoiceDlg::ShowProperties(int iItem)
  320. //
  321. // PURPOSE: Show the app specific properties Dialog
  322. //
  323. // COMMENTS: Implemented on main thread.
  324. //
  325. //--------------------------------------------------------------------------------
  326. HRESULT CChoiceDlg::ShowProperties(int iItem)
  327. {
  328. HRESULT hr = E_UNEXPECTED;
  329. Assert(iItem >= 0);
  330. // only call showProperties if still have our own addref.
  331. // and not already in a ShowProperties out call.
  332. if ( (iItem >= 0) &&
  333. m_pItemListView &&
  334. m_pHndlrQueue &&
  335. m_fInternalAddref && (0 == m_dwShowPropertiesCount) )
  336. {
  337. LVHANDLERITEMBLOB lvHandlerItemBlob;
  338. lvHandlerItemBlob.cbSize = sizeof(LVHANDLERITEMBLOB);
  339. if (m_pItemListView->GetItemBlob(iItem,(LPLVBLOB) &lvHandlerItemBlob,lvHandlerItemBlob.cbSize))
  340. {
  341. if (NOERROR == m_pHndlrQueue->ItemHasProperties(lvHandlerItemBlob.clsidServer,
  342. lvHandlerItemBlob.ItemID))
  343. {
  344. // Put two refs on the Properties one
  345. // for completion routine to reset and one for this
  346. // call so cancel can't happen until both return from
  347. // call and completion is called.
  348. m_dwShowPropertiesCount += 2;
  349. ObjMgr_AddRefHandlerPropertiesLockCount(2);
  350. hr = m_pHndlrQueue->ShowProperties(lvHandlerItemBlob.clsidServer,lvHandlerItemBlob.ItemID,m_hwnd);
  351. --m_dwShowPropertiesCount; // out of call
  352. ObjMgr_ReleaseHandlerPropertiesLockCount(1);
  353. Assert( ((LONG) m_dwShowPropertiesCount) >= 0);
  354. if ( ((LONG) m_dwShowPropertiesCount) <0)
  355. m_dwShowPropertiesCount = 0;
  356. // if hr wasn't a success code then up to us to call the callback
  357. if (FAILED(hr))
  358. {
  359. PostMessage(m_hwnd,WM_BASEDLG_COMPLETIONROUTINE,
  360. ThreadMsg_ShowProperties,0);
  361. }
  362. }
  363. }
  364. }
  365. return hr;
  366. }
  367. //--------------------------------------------------------------------------------
  368. //
  369. // FUNCTION: CChoiceDlg::ReleaseDlg
  370. //
  371. // PURPOSE: Called by objmgr when we need to release
  372. // post message to the dialog thread.
  373. //
  374. // COMMENTS:
  375. //
  376. //--------------------------------------------------------------------------------
  377. void CChoiceDlg::ReleaseDlg(WORD wCommandID)
  378. {
  379. PostMessage(m_hwnd,WM_CHOICE_RELEASEDLGCMD,wCommandID,0);
  380. }
  381. //--------------------------------------------------------------------------------
  382. //
  383. // FUNCTION: CChoiceDlg::PrivReleaseDlg
  384. //
  385. // PURPOSE: frees the dialog
  386. //
  387. // COMMENTS:
  388. //
  389. //--------------------------------------------------------------------------------
  390. void CChoiceDlg::PrivReleaseDlg(WORD wCommandID)
  391. {
  392. BOOL fCloseConnections = TRUE;
  393. Assert(m_dwThreadID == GetCurrentThreadId());
  394. Assert(m_fInternalAddref == FALSE);
  395. if (m_hwnd)
  396. {
  397. // ShowWindow(m_hwnd,SW_HIDE);
  398. }
  399. // if don't have a listView then change command to a cancel
  400. if (NULL == m_pItemListView)
  401. {
  402. wCommandID = RELEASEDLGCMDID_CANCEL;
  403. }
  404. switch(wCommandID)
  405. {
  406. case RELEASEDLGCMDID_CANCEL:
  407. // done with our queue
  408. Assert(m_pHndlrQueue);
  409. case RELEASEDLGCMDID_DESTROY:
  410. // this CommandID is sent if dialog was created but it couldn't be added
  411. // to the object mgr list.
  412. if (m_pHndlrQueue)
  413. {
  414. m_pHndlrQueue->FreeAllHandlers(); // done with our queue.
  415. m_pHndlrQueue->Release();
  416. m_pHndlrQueue = NULL;
  417. }
  418. break;
  419. case RELEASEDLGCMDID_OK:
  420. {
  421. Assert(m_pHndlrQueue);
  422. Assert(m_pItemListView);
  423. if (m_pHndlrQueue && m_pItemListView)
  424. {
  425. CProgressDlg *pProgressDlg;
  426. short i = 0;
  427. int sCheckState;
  428. LVHANDLERITEMBLOB lvHandlerItemBlob;
  429. lvHandlerItemBlob.cbSize = sizeof(LVHANDLERITEMBLOB);
  430. // loop through getting and setting the selected items.
  431. // 1 checked, 0 unchecked, -1 last item
  432. while (-1 != (sCheckState = m_pItemListView->GetCheckState(i)))
  433. {
  434. if (m_pItemListView->GetItemBlob(i,(LPLVBLOB) &lvHandlerItemBlob,lvHandlerItemBlob.cbSize))
  435. {
  436. if (GUID_NULL != lvHandlerItemBlob.ItemID)
  437. {
  438. m_pHndlrQueue->SetItemState(lvHandlerItemBlob.clsidServer,
  439. lvHandlerItemBlob.ItemID,
  440. sCheckState == LVITEMEXSTATE_CHECKED ?
  441. SYNCMGRITEMSTATE_CHECKED : SYNCMGRITEMSTATE_UNCHECKED);
  442. }
  443. }
  444. i++;
  445. } while (-1 != sCheckState);
  446. m_pHndlrQueue->PersistChoices();
  447. // on a manual create the progress dialog as displayed.
  448. if (NOERROR == FindProgressDialog(GUID_NULL,TRUE,SW_SHOWNORMAL,&pProgressDlg))
  449. {
  450. if (NOERROR == pProgressDlg->TransferQueueData(m_pHndlrQueue))
  451. {
  452. fCloseConnections = FALSE;
  453. }
  454. ReleaseProgressDialog(GUID_NULL,pProgressDlg,FALSE);
  455. }
  456. m_pHndlrQueue->FreeAllHandlers(); // done with our queue.
  457. m_pHndlrQueue->Release();
  458. m_pHndlrQueue = NULL;
  459. }
  460. }
  461. break;
  462. case RELEASEDLGCMDID_DEFAULT:
  463. if (m_pHndlrQueue)
  464. {
  465. m_pHndlrQueue->FreeAllHandlers(); // done with our queue.
  466. m_pHndlrQueue->Release();
  467. m_pHndlrQueue = NULL;
  468. }
  469. break;
  470. default:
  471. Assert(0); // unknown command or we never set one.
  472. break;
  473. }
  474. // see if there is a progress queue when we get done and we havne't
  475. // created one ourselves. If there isn't then
  476. // call CloseConnection to make sure any Events or open Connections
  477. // get hungUp.
  478. CProgressDlg *pProgressDlg = NULL;
  479. if (fCloseConnections)
  480. {
  481. if (NOERROR == FindProgressDialog(GUID_NULL,FALSE,SW_MINIMIZE,&pProgressDlg))
  482. {
  483. ReleaseProgressDialog(GUID_NULL,pProgressDlg,FALSE);
  484. }
  485. else
  486. {
  487. ConnectObj_CloseConnections();
  488. }
  489. }
  490. m_fDead = TRUE;
  491. if (m_pItemListView)
  492. {
  493. delete m_pItemListView;
  494. m_pItemListView = NULL;
  495. }
  496. if (m_hwnd)
  497. {
  498. DestroyWindow(m_hwnd);
  499. m_hwnd = NULL;
  500. }
  501. delete this;
  502. return;
  503. }
  504. //--------------------------------------------------------------------------------
  505. //
  506. // FUNCTION: CChoiceDlg::UpdateWndPosition
  507. //
  508. // PURPOSE: updates window Z-Order and min/max state.
  509. //
  510. // COMMENTS:
  511. //
  512. //--------------------------------------------------------------------------------
  513. void CChoiceDlg::UpdateWndPosition(int nCmdShow,BOOL fForce)
  514. {
  515. // always just pull choice to the front since can't minimize;
  516. ShowWindow(m_hwnd,nCmdShow);
  517. SetForegroundWindow(m_hwnd);
  518. UpdateWindow(m_hwnd);
  519. }
  520. //--------------------------------------------------------------------------------
  521. //
  522. // FUNCTION: CChoiceDlg::HandleLogError(int iItem)
  523. //
  524. // PURPOSE: handles virtual function for base class.
  525. //
  526. //
  527. //--------------------------------------------------------------------------------
  528. void CChoiceDlg::HandleLogError(HWND hwnd, HANDLERINFO *pHandlerID,MSGLogErrors *lpmsgLogErrors)
  529. {
  530. AssertSz(0,"Choice dialogs HandleLogError Called");
  531. }
  532. //+---------------------------------------------------------------------------
  533. //
  534. // Member: CChoiceDlg::CallCompletionRoutine, private
  535. //
  536. // Synopsis: method called when a call has been completed.
  537. //
  538. // Arguments:
  539. //
  540. // Returns:
  541. //
  542. // Modifies:
  543. //
  544. // History: 02-Jun-98 rogerg Created.
  545. //
  546. //----------------------------------------------------------------------------
  547. void CChoiceDlg::CallCompletionRoutine(DWORD dwThreadMsg,LPCALLCOMPLETIONMSGLPARAM lpCallCompletelParam)
  548. {
  549. // only completion routine choice
  550. // dialog should get is for show properties
  551. switch(dwThreadMsg)
  552. {
  553. case ThreadMsg_ShowProperties:
  554. ObjMgr_ReleaseHandlerPropertiesLockCount(1);
  555. // If have a success code we need to handle do it
  556. // before releasing our lock.
  557. if (lpCallCompletelParam)
  558. {
  559. switch(lpCallCompletelParam->hCallResult)
  560. {
  561. case S_SYNCMGR_ITEMDELETED:
  562. // if item is deleted just set the itemState to unchecked and remove from the
  563. // ui
  564. if (m_pHndlrQueue && m_pItemListView)
  565. {
  566. LVHANDLERITEMBLOB lvItemBlob;
  567. int lvItemID;
  568. m_pHndlrQueue->SetItemState(lpCallCompletelParam->clsidHandler,
  569. lpCallCompletelParam->itemID,SYNCMGRITEMSTATE_UNCHECKED);
  570. lvItemBlob.cbSize = sizeof(LVHANDLERITEMBLOB);
  571. lvItemBlob.clsidServer = lpCallCompletelParam->clsidHandler;
  572. lvItemBlob.ItemID = lpCallCompletelParam->itemID;
  573. if (-1 != (lvItemID = m_pItemListView->FindItemFromBlob((LPLVBLOB) &lvItemBlob)))
  574. {
  575. // if toplevel item, first delete the children
  576. if (GUID_NULL == lpCallCompletelParam->itemID)
  577. {
  578. m_pItemListView->DeleteChildren(lvItemID);
  579. }
  580. m_pItemListView->DeleteItem(lvItemID);
  581. }
  582. Assert(-1 != lvItemID);
  583. }
  584. break;
  585. case S_SYNCMGR_ENUMITEMS:
  586. if (m_pHndlrQueue && m_pItemListView)
  587. {
  588. LVHANDLERITEMBLOB lvItemBlob;
  589. int lvItemID;
  590. // delete all items from the ListView.
  591. lvItemBlob.cbSize = sizeof(LVHANDLERITEMBLOB);
  592. lvItemBlob.clsidServer = lpCallCompletelParam->clsidHandler;
  593. lvItemBlob.ItemID = GUID_NULL;
  594. if (-1 != (lvItemID = m_pItemListView->FindItemFromBlob((LPLVBLOB) &lvItemBlob)))
  595. {
  596. if (m_pItemListView->DeleteChildren(lvItemID))
  597. {
  598. m_pHndlrQueue->ReEnumHandlerItems(lpCallCompletelParam->clsidHandler,
  599. lpCallCompletelParam->itemID);
  600. AddNewItemsToListView();
  601. }
  602. }
  603. Assert(-1 != lvItemID);
  604. }
  605. break;
  606. default:
  607. break;
  608. }
  609. }
  610. --m_dwShowPropertiesCount;
  611. Assert( ((LONG) m_dwShowPropertiesCount) >= 0);
  612. // fix up the count if gone negative.
  613. if ( ((LONG) m_dwShowPropertiesCount) < 0)
  614. m_dwShowPropertiesCount = 0;
  615. break;
  616. default:
  617. AssertSz(0,"Uknown Completion Routine");
  618. break;
  619. }
  620. // if have an lparam free it now
  621. if (lpCallCompletelParam)
  622. {
  623. FREE(lpCallCompletelParam);
  624. }
  625. }
  626. //+---------------------------------------------------------------------------
  627. //
  628. // Member: CChoiceDlg::QueryCanSystemShutdown, private
  629. //
  630. // Synopsis: called by object manager to determine if can shutdown.
  631. //
  632. // !!!Warning - can be called on any thread. make sure this is
  633. // readonly.
  634. //
  635. // !!!Warning - Do not yield in the function;
  636. //
  637. //
  638. // Arguments:
  639. //
  640. // Returns: S_OK - if can shutdown
  641. // S_FALSE - system should not shutdown, must fill in out params.
  642. //
  643. // Modifies:
  644. //
  645. // History: 17-Jun-98 rogerg Created.
  646. //
  647. //----------------------------------------------------------------------------
  648. HRESULT CChoiceDlg::QueryCanSystemShutdown(/* [out] */ HWND *phwnd, /* [out] */ UINT *puMessageId,
  649. /* [out] */ BOOL *pfLetUserDecide)
  650. {
  651. HRESULT hr = S_OK;
  652. // dialog locked open if in ShowProperties
  653. if (m_dwShowPropertiesCount > 0)
  654. {
  655. *puMessageId = IDS_HANDLERPROPERTIESQUERYENDSESSION;
  656. *phwnd = NULL; // since properties can overvlay us don't give parent
  657. *pfLetUserDecide = FALSE; // user doesn't get a choice.
  658. hr = S_FALSE;
  659. }
  660. return hr;
  661. }
  662. //+---------------------------------------------------------------------------
  663. //
  664. // Member: CChoiceDlg::CalcListViewWidth, private
  665. //
  666. // Synopsis:
  667. //
  668. // Arguments:
  669. //
  670. // Returns:
  671. //
  672. // Modifies:
  673. //
  674. // History: 12-Aug-98 rogerg Created.
  675. //
  676. //----------------------------------------------------------------------------
  677. int CChoiceDlg::CalcListViewWidth(HWND hwndList)
  678. {
  679. NONCLIENTMETRICSA metrics;
  680. RECT rcClientRect;
  681. metrics.cbSize = sizeof(metrics);
  682. // explicitly ask for ANSI version of SystemParametersInfo since we just
  683. // care about the ScrollWidth and don't want to conver the LOGFONT info.
  684. if (GetClientRect(hwndList,&rcClientRect)
  685. && SystemParametersInfoA(SPI_GETNONCLIENTMETRICS,sizeof(metrics),(PVOID) &metrics,0))
  686. {
  687. // subtract off scroll bar distance + 1/2 another to give a little space to
  688. // read right justified text.
  689. rcClientRect.right -= (metrics.iScrollWidth * 3)/2;
  690. }
  691. else
  692. {
  693. rcClientRect.right = 320; // if fail, just makeup a number
  694. }
  695. return rcClientRect.right;
  696. }
  697. //+---------------------------------------------------------------------------
  698. //
  699. // Member: CChoiceDlg::OnInitialize, private
  700. //
  701. // Synopsis:
  702. //
  703. // Arguments:
  704. //
  705. // Returns:
  706. //
  707. // Modifies:
  708. //
  709. // History: 17-Jun-98 rogerg Created.
  710. //
  711. //----------------------------------------------------------------------------
  712. BOOL CChoiceDlg::OnInitialize(HWND hwnd,UINT uMsg,WPARAM wParam,LPARAM lParam)
  713. {
  714. HIMAGELIST himage;
  715. WCHAR wszColumnName[MAX_PATH];
  716. INT iItem = -1;
  717. HWND hwndList = GetDlgItem(hwnd,IDC_CHOICELISTVIEW);
  718. LPNETAPI pNetApi;
  719. // if sens is not installed hide the settings button.
  720. // and move the synchronize over.
  721. if (pNetApi = gSingleNetApiObj.GetNetApiObj())
  722. {
  723. if (!(pNetApi->IsSensInstalled()))
  724. {
  725. RECT rect;
  726. HWND hwndSettings = GetDlgItem(hwnd,IDC_OPTIONS);
  727. if (hwndSettings)
  728. {
  729. BOOL fGetWindowRect;
  730. HWND hwndStart;
  731. RECT rectStart;
  732. ShowWindow(hwndSettings,SW_HIDE);
  733. EnableWindow(hwndSettings,FALSE); // disable for alt
  734. fGetWindowRect = GetWindowRect(hwndSettings,&rect);
  735. hwndStart = GetDlgItem(hwnd,IDC_START);
  736. if (fGetWindowRect && hwndStart
  737. && GetClientRect(hwndStart,&rectStart)
  738. && MapWindowPoints(NULL,hwnd,(LPPOINT) &rect,2)
  739. )
  740. {
  741. SetWindowPos(hwndStart, 0,
  742. rect.right - WIDTH(rectStart),rect.top,0,0,SWP_NOZORDER | SWP_NOACTIVATE | SWP_NOSIZE );
  743. }
  744. }
  745. }
  746. pNetApi->Release();
  747. }
  748. m_hwnd = hwnd; // setup the hwnd.
  749. m_fHwndRightToLeft = IsHwndRightToLeft(m_hwnd);
  750. // IF THE HWND IS RIGHT TO LEFT HIDE
  751. // SIZE CONTROL UNTIL RESIZE WORKS.
  752. if (m_fHwndRightToLeft)
  753. {
  754. ShowWindow(GetDlgItem(m_hwnd,IDC_CHOICERESIZESCROLLBAR),SW_HIDE);
  755. }
  756. if (hwndList)
  757. {
  758. // setup the list view
  759. m_pItemListView = new CListView(hwndList,hwnd,IDC_CHOICELISTVIEW,WM_BASEDLG_NOTIFYLISTVIEWEX);
  760. if (m_pItemListView)
  761. {
  762. int iClientRect = CalcListViewWidth(hwndList);
  763. UINT ImageListflags;
  764. m_pItemListView->SetExtendedListViewStyle(LVS_EX_CHECKBOXES
  765. | LVS_EX_FULLROWSELECT | LVS_EX_INFOTIP );
  766. // create an imagelist, if fail continue, list view just won't have an
  767. // imaglist
  768. ImageListflags = ILC_COLOR | ILC_MASK;
  769. if (IsHwndRightToLeft(m_hwnd))
  770. {
  771. ImageListflags |= ILC_MIRROR;
  772. }
  773. himage = ImageList_Create( GetSystemMetrics(SM_CXSMICON),
  774. GetSystemMetrics(SM_CYSMICON),ImageListflags,5,20);
  775. if (himage)
  776. {
  777. m_pItemListView->SetImageList(himage,LVSIL_SMALL);
  778. }
  779. // Calc cx 2/3 for name 1/3 for
  780. if (!LoadString(g_hInst,IDS_CHOICEHANDLERCOLUMN, wszColumnName, ARRAY_SIZE(wszColumnName)))
  781. {
  782. *wszColumnName = NULL;
  783. }
  784. InsertListViewColumn(m_pItemListView,CHOICELIST_NAMECOLUMN,wszColumnName,LVCFMT_LEFT,(iClientRect*2)/3);
  785. if (!LoadString(g_hInst,IDS_CHOICELASTUPDATECOLUMN, wszColumnName, ARRAY_SIZE(wszColumnName)))
  786. {
  787. *wszColumnName = NULL;
  788. }
  789. InsertListViewColumn(m_pItemListView,CHOICELIST_LASTUPDATECOLUMN,wszColumnName,LVCFMT_RIGHT,(iClientRect)/3);
  790. }
  791. }
  792. RECT rectParent;
  793. m_ulNumDlgResizeItem = 0; // if fail then we don't resize anything.
  794. if (GetClientRect(hwnd,&rectParent))
  795. {
  796. ULONG itemCount;
  797. DlgResizeList *pResizeList;
  798. // loop through resize list
  799. Assert(NUM_DLGRESIZEINFOCHOICE == (sizeof(g_ChoiceResizeList)/sizeof(DlgResizeList)) );
  800. pResizeList = (DlgResizeList *) &g_ChoiceResizeList;
  801. for (itemCount = 0; itemCount < NUM_DLGRESIZEINFOCHOICE; ++itemCount)
  802. {
  803. if(InitResizeItem(pResizeList->iCtrlId,
  804. pResizeList->dwDlgResizeFlags,hwnd,&rectParent,&(m_dlgResizeInfo[m_ulNumDlgResizeItem])))
  805. {
  806. ++m_ulNumDlgResizeItem;
  807. }
  808. ++pResizeList;
  809. }
  810. }
  811. // store the current width and height as the
  812. // the min
  813. if (GetWindowRect(hwnd,&rectParent))
  814. {
  815. m_ptMinimizeDlgSize.x = rectParent.right - rectParent.left;
  816. m_ptMinimizeDlgSize.y = rectParent.bottom - rectParent.top;
  817. }
  818. return TRUE;
  819. }
  820. //+---------------------------------------------------------------------------
  821. //
  822. // Member: CChoiceDlg::OnClose, private
  823. //
  824. // Synopsis:
  825. //
  826. // Arguments:
  827. //
  828. // Returns:
  829. //
  830. // Modifies:
  831. //
  832. // History: 17-Jun-98 rogerg Created.
  833. //
  834. //----------------------------------------------------------------------------
  835. void CChoiceDlg::OnClose(UINT uMsg,WPARAM wParam,LPARAM lParam)
  836. {
  837. if ( (0 == m_dwShowPropertiesCount) && (m_fInternalAddref) )
  838. {
  839. m_fInternalAddref = FALSE; // set released member so know we have removed addref on ourself.
  840. SetChoiceReleaseDlgCmdId(m_clsid,this,RELEASEDLGCMDID_CANCEL);
  841. ReleaseChoiceDialog(m_clsid,this);
  842. }
  843. }
  844. //+---------------------------------------------------------------------------
  845. //
  846. // Member: CChoiceDlg::OnSetQueueData, private
  847. //
  848. // Synopsis:
  849. //
  850. // Arguments:
  851. //
  852. // Returns:
  853. //
  854. // Modifies:
  855. //
  856. // History: 17-Jun-98 rogerg Created.
  857. //
  858. //----------------------------------------------------------------------------
  859. void CChoiceDlg::OnSetQueueData(UINT uMsg,WPARAM wParam,LPARAM lParam)
  860. {
  861. SetQueueDataInfo *pdataInfo;
  862. BOOL fSet;
  863. BOOL *pfSet = (BOOL *) wParam;
  864. pdataInfo = (SetQueueDataInfo *) lParam;
  865. fSet = PrivSetQueueData(*pdataInfo->rclsid, pdataInfo->pHndlrQueue );
  866. if (pfSet)
  867. {
  868. *pfSet = fSet;
  869. }
  870. }
  871. //+---------------------------------------------------------------------------
  872. //
  873. // Member: CChoiceDlg::OnContextMenu, private
  874. //
  875. // Synopsis:
  876. //
  877. // Arguments:
  878. //
  879. // Returns:
  880. //
  881. // Modifies:
  882. //
  883. // History: 17-Jun-98 rogerg Created.
  884. //
  885. //----------------------------------------------------------------------------
  886. void CChoiceDlg::OnContextMenu(UINT uMsg,WPARAM wParam,LPARAM lParam)
  887. {
  888. WinHelp ((HWND)wParam,g_szSyncMgrHelp,HELP_CONTEXTMENU,
  889. (ULONG_PTR) g_aContextHelpIds);
  890. }
  891. //+---------------------------------------------------------------------------
  892. //
  893. // Member: CChoiceDlg::OnHelp, private
  894. //
  895. // Synopsis:
  896. //
  897. // Arguments:
  898. //
  899. // Returns:
  900. //
  901. // Modifies:
  902. //
  903. // History: 17-Jun-98 rogerg Created.
  904. //
  905. //----------------------------------------------------------------------------
  906. void CChoiceDlg::OnHelp(UINT uMsg,WPARAM wParam,LPARAM lParam)
  907. {
  908. LPHELPINFO lphi = (LPHELPINFO)lParam;
  909. if (lphi->iContextType == HELPINFO_WINDOW)
  910. {
  911. WinHelp ( (HWND) lphi->hItemHandle,
  912. g_szSyncMgrHelp,HELP_WM_HELP,
  913. (ULONG_PTR) g_aContextHelpIds);
  914. }
  915. }
  916. //+---------------------------------------------------------------------------
  917. //
  918. // Member: CChoiceDlg::OnStartCommand, private
  919. //
  920. // Synopsis:
  921. //
  922. // Arguments:
  923. //
  924. // Returns:
  925. //
  926. // Modifies:
  927. //
  928. // History: 17-Jun-98 rogerg Created.
  929. //
  930. //----------------------------------------------------------------------------
  931. void CChoiceDlg::OnStartCommand(UINT uMsg,WPARAM wParam,LPARAM lParam)
  932. {
  933. if ((0 == m_dwShowPropertiesCount) && (m_fInternalAddref))
  934. {
  935. m_fInternalAddref = FALSE;
  936. SetChoiceReleaseDlgCmdId(m_clsid,this,RELEASEDLGCMDID_OK);
  937. ReleaseChoiceDialog(m_clsid,this);
  938. }
  939. }
  940. //+---------------------------------------------------------------------------
  941. //
  942. // Member: CChoiceDlg::OnPropertyCommand, private
  943. //
  944. // Synopsis:
  945. //
  946. // Arguments:
  947. //
  948. // Returns:
  949. //
  950. // Modifies:
  951. //
  952. // History: 17-Jun-98 rogerg Created.
  953. //
  954. //----------------------------------------------------------------------------
  955. void CChoiceDlg::OnPropertyCommand(UINT uMsg,WPARAM wParam,LPARAM lParam)
  956. {
  957. // only bring up properties if still have addref on self.
  958. if (m_fInternalAddref && m_pItemListView)
  959. {
  960. int i = m_pItemListView->GetSelectionMark();
  961. if (i >= 0)
  962. {
  963. ShowProperties(i);
  964. }
  965. }
  966. }
  967. //+---------------------------------------------------------------------------
  968. //
  969. // Member: CChoiceDlg::OnCommand, private
  970. //
  971. // Synopsis:
  972. //
  973. // Arguments:
  974. //
  975. // Returns:
  976. //
  977. // Modifies:
  978. //
  979. // History: 17-Jun-98 rogerg Created.
  980. //
  981. //----------------------------------------------------------------------------
  982. void CChoiceDlg::OnCommand(UINT uMsg,WPARAM wParam,LPARAM lParam)
  983. {
  984. WORD wID = LOWORD(wParam);
  985. WORD wNotifyCode = HIWORD(wParam);
  986. switch (wID)
  987. {
  988. case IDC_START:
  989. if (BN_CLICKED == wNotifyCode)
  990. {
  991. OnStartCommand(uMsg,wParam,lParam);
  992. }
  993. break;
  994. case IDCANCEL:
  995. case IDC_CLOSE:
  996. OnClose(uMsg,wParam,lParam);
  997. break;
  998. case IDC_PROPERTY:
  999. OnPropertyCommand(uMsg,wParam,lParam);
  1000. break;
  1001. case IDC_OPTIONS:
  1002. ShowOptionsDialog(m_hwnd);
  1003. break;
  1004. default:
  1005. break;
  1006. }
  1007. }
  1008. //+---------------------------------------------------------------------------
  1009. //
  1010. // Member: CChoiceDlg::OnGetMinMaxInfo, private
  1011. //
  1012. // Synopsis: Called by WM_GETMINMAXINFO
  1013. //
  1014. // Arguments:
  1015. //
  1016. // Returns:
  1017. //
  1018. // Modifies:
  1019. //
  1020. // History: 17-Jun-98 rogerg Created.
  1021. //
  1022. //----------------------------------------------------------------------------
  1023. void CChoiceDlg::OnGetMinMaxInfo(UINT uMsg,WPARAM wParam,LPARAM lParam)
  1024. {
  1025. MINMAXINFO *pMinMax = (MINMAXINFO *) lParam ;
  1026. pMinMax->ptMinTrackSize.x = m_ptMinimizeDlgSize.x;
  1027. pMinMax->ptMinTrackSize.y = m_ptMinimizeDlgSize.y ;
  1028. }
  1029. //+---------------------------------------------------------------------------
  1030. //
  1031. // Member: CChoiceDlg::OnSize, private
  1032. //
  1033. // Synopsis: Called by WM_SIZE
  1034. //
  1035. // Arguments:
  1036. //
  1037. // Returns:
  1038. //
  1039. // Modifies:
  1040. //
  1041. // History: 17-Jun-98 rogerg Created.
  1042. //
  1043. //----------------------------------------------------------------------------
  1044. void CChoiceDlg::OnSize(UINT uMsg,WPARAM wParam,LPARAM lParam)
  1045. {
  1046. ResizeItems(m_ulNumDlgResizeItem,m_dlgResizeInfo);
  1047. }
  1048. //+---------------------------------------------------------------------------
  1049. //
  1050. // Member: CChoiceDlg::OnNotify, private
  1051. //
  1052. // Synopsis:
  1053. //
  1054. // Arguments:
  1055. //
  1056. // Returns:
  1057. //
  1058. // Modifies:
  1059. //
  1060. // History: 17-Jun-98 rogerg Created.
  1061. //
  1062. //----------------------------------------------------------------------------
  1063. LRESULT CChoiceDlg::OnNotify(UINT uMsg,WPARAM wParam,LPARAM lParam)
  1064. {
  1065. int idCtrl = (int) wParam;
  1066. LPNMHDR pnmh = (LPNMHDR) lParam;
  1067. if ((IDC_CHOICELISTVIEW == idCtrl) && m_pItemListView)
  1068. {
  1069. return m_pItemListView->OnNotify(pnmh);
  1070. }
  1071. return 0;
  1072. }
  1073. //+---------------------------------------------------------------------------
  1074. //
  1075. // Member: CChoiceDlg::OnNotifyListViewEx, private
  1076. //
  1077. // Synopsis:
  1078. //
  1079. // Arguments:
  1080. //
  1081. // Returns:
  1082. //
  1083. // Modifies:
  1084. //
  1085. // History: 17-Jun-98 rogerg Created.
  1086. //
  1087. //----------------------------------------------------------------------------
  1088. LRESULT CChoiceDlg::OnNotifyListViewEx(UINT uMsg,WPARAM wParam,LPARAM lParam)
  1089. {
  1090. int idCtrl = (int) wParam;
  1091. LPNMHDR pnmh = (LPNMHDR) lParam;
  1092. LVHANDLERITEMBLOB lvHandlerItemBlob;
  1093. if ( (IDC_CHOICELISTVIEW != idCtrl) || (NULL == m_pItemListView))
  1094. {
  1095. Assert(IDC_CHOICELISTVIEW == idCtrl);
  1096. Assert(m_pItemListView);
  1097. return 0;
  1098. }
  1099. lvHandlerItemBlob.cbSize = sizeof(LVHANDLERITEMBLOB);
  1100. switch (pnmh->code)
  1101. {
  1102. case LVNEX_ITEMCHECKCOUNT:
  1103. {
  1104. LPNMLISTVIEWEXITEMCHECKCOUNT plviCheckCount = (LPNMLISTVIEWEXITEMCHECKCOUNT) lParam;
  1105. // update start button based on how many items are selected.
  1106. SetButtonState(IDC_START,plviCheckCount->iCheckCount);
  1107. break;
  1108. }
  1109. case LVNEX_ITEMCHANGED:
  1110. {
  1111. LPNMLISTVIEWEX pnmvEx = (LPNMLISTVIEWEX) lParam;
  1112. LPNMLISTVIEW pnmv= &(pnmvEx->nmListView);
  1113. if (pnmv->uChanged == LVIF_STATE)
  1114. {
  1115. int iItem = pnmv->iItem;
  1116. BOOL fItemHasProperties = FALSE;;
  1117. if (pnmv->uNewState & LVIS_SELECTED)
  1118. {
  1119. Assert(iItem >= 0);
  1120. if ((iItem >= 0) &&
  1121. m_pItemListView->GetItemBlob(iItem,(LPLVBLOB) &lvHandlerItemBlob,lvHandlerItemBlob.cbSize))
  1122. {
  1123. if (NOERROR == m_pHndlrQueue->ItemHasProperties(lvHandlerItemBlob.clsidServer,
  1124. lvHandlerItemBlob.ItemID))
  1125. {
  1126. fItemHasProperties = TRUE;
  1127. }
  1128. }
  1129. }
  1130. SetButtonState(IDC_PROPERTY,fItemHasProperties);
  1131. }
  1132. break;
  1133. }
  1134. case LVNEX_DBLCLK:
  1135. {
  1136. LPNMLISTVIEW lpnmlv = (LPNMLISTVIEW) lParam;
  1137. ShowProperties(lpnmlv->iItem);
  1138. break;
  1139. }
  1140. default:
  1141. break;
  1142. }
  1143. return 0;
  1144. }
  1145. //--------------------------------------------------------------------------------
  1146. //
  1147. // FUNCTION: CChoiceDlgProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
  1148. //
  1149. // PURPOSE: Callback for Choice Dialog
  1150. //
  1151. // COMMENTS: Implemented on main thread.
  1152. //
  1153. //
  1154. //------------------------------------------------------------------------------
  1155. BOOL CALLBACK CChoiceDlgProc(HWND hwnd, UINT uMsg, WPARAM wParam,
  1156. LPARAM lParam)
  1157. {
  1158. CChoiceDlg *pThis = (CChoiceDlg *) GetWindowLongPtr(hwnd, DWLP_USER);
  1159. // spcial case destroy and init.
  1160. switch (uMsg)
  1161. {
  1162. case WM_DESTROY:
  1163. PostQuitMessage(0); // done with this thread.
  1164. break;
  1165. case WM_INITDIALOG:
  1166. {
  1167. // Stash the this pointer so we can use it later
  1168. SetWindowLongPtr(hwnd, DWLP_USER, (LONG_PTR)lParam);
  1169. pThis = (CChoiceDlg *) lParam;
  1170. if (pThis)
  1171. {
  1172. return pThis->OnInitialize(hwnd,uMsg,wParam,lParam);
  1173. }
  1174. return FALSE;
  1175. break;
  1176. }
  1177. default:
  1178. {
  1179. if (pThis)
  1180. {
  1181. switch (uMsg)
  1182. {
  1183. case WM_CLOSE:
  1184. pThis->OnClose(uMsg,wParam,lParam);
  1185. break;
  1186. case WM_BASEDLG_HANDLESYSSHUTDOWN:
  1187. PostMessage(hwnd,WM_CLOSE,0,0); // post a close message to get on our thread.
  1188. break;
  1189. case WM_GETMINMAXINFO:
  1190. pThis->OnGetMinMaxInfo(uMsg,wParam,lParam);
  1191. break;
  1192. case WM_SIZE:
  1193. pThis->OnSize(uMsg,wParam,lParam);
  1194. break;
  1195. case WM_COMMAND:
  1196. pThis->OnCommand(uMsg,wParam,lParam);
  1197. break;
  1198. case WM_NOTIFY:
  1199. {
  1200. LRESULT lretOnNotify;
  1201. lretOnNotify = pThis->OnNotify(uMsg,wParam,lParam);
  1202. SetWindowLongPtr(hwnd,DWLP_MSGRESULT,lretOnNotify);
  1203. return TRUE;
  1204. }
  1205. break;
  1206. case WM_HELP:
  1207. pThis->OnHelp(uMsg,wParam,lParam);
  1208. return TRUE;
  1209. break;
  1210. case WM_CONTEXTMENU:
  1211. pThis->OnContextMenu(uMsg,wParam,lParam);
  1212. break;
  1213. case WM_BASEDLG_SHOWWINDOW:
  1214. pThis->UpdateWndPosition((int)wParam /*nCmd */,FALSE /* force */);
  1215. break;
  1216. case WM_BASEDLG_COMPLETIONROUTINE:
  1217. pThis->CallCompletionRoutine((DWORD)wParam /* dwThreadMsg*/,(LPCALLCOMPLETIONMSGLPARAM) lParam);
  1218. break;
  1219. case WM_BASEDLG_NOTIFYLISTVIEWEX:
  1220. pThis->OnNotifyListViewEx(uMsg,wParam,lParam);
  1221. break;
  1222. case WM_CHOICE_SETQUEUEDATA:
  1223. pThis->OnSetQueueData(uMsg,wParam,lParam);
  1224. return TRUE;
  1225. break;
  1226. case WM_CHOICE_RELEASEDLGCMD:
  1227. pThis->PrivReleaseDlg((WORD)wParam /* wCommandID */);
  1228. break;
  1229. default:
  1230. break;
  1231. }
  1232. }
  1233. }
  1234. break;
  1235. }
  1236. return FALSE;
  1237. }