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.

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