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.

1088 lines
22 KiB

  1. //+-------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. //
  5. // Copyright (C) Microsoft Corporation, 1999 - 1999
  6. //
  7. // File: statdlg.cpp
  8. //
  9. //--------------------------------------------------------------------------
  10. // StatDlg.cpp : implementation file
  11. //
  12. #include "stdafx.h"
  13. #include "ScAlert.h"
  14. #include "miscdef.h"
  15. #include "statmon.h"
  16. #include "StatDlg.h"
  17. #ifdef _DEBUG
  18. #define new DEBUG_NEW
  19. #undef THIS_FILE
  20. static char THIS_FILE[] = __FILE__;
  21. #endif
  22. ////////////////////////////////////////////////////////////////////////////
  23. #ifdef __cplusplus
  24. extern "C" { // Assume C declarations for C++
  25. #endif // __cplusplus
  26. #ifdef __cplusplus
  27. }
  28. #endif /* __cplusplus */
  29. /////////////////////////////////////////////////////////////////////////////////////
  30. //
  31. // CSCStatusDlgThrd
  32. //
  33. IMPLEMENT_DYNCREATE(CSCStatusDlgThrd, CWinThread)
  34. /*++
  35. InitInstance
  36. Must override init instance to perform UI thread initialization
  37. Arguments:
  38. Return Value:
  39. TRUE on build start message loop. FALSE otherwise
  40. Author:
  41. Chris Dudley 2/27/1997
  42. --*/
  43. BOOL CSCStatusDlgThrd::InitInstance( void )
  44. {
  45. INT_PTR nResult = -1; // error creating dialog
  46. LONG lReturn = SCARD_S_SUCCESS;
  47. SCARDCONTEXT hSCardContext = NULL;
  48. // Acquire context with resource manager
  49. lReturn = SCardEstablishContext( SCARD_SCOPE_USER,
  50. NULL,
  51. NULL,
  52. &hSCardContext);
  53. if (lReturn != SCARD_S_SUCCESS)
  54. {
  55. nResult = IDCANCEL;
  56. }
  57. else
  58. {
  59. #ifdef ISOLATION_AWARE_ENABLED
  60. CThemeContextActivator activator;
  61. #endif
  62. m_StatusDlg.SetContext(hSCardContext);
  63. // Run the dialog as Modal
  64. m_fStatusDlgUp = TRUE;
  65. nResult = m_StatusDlg.DoModal();// if the dialog is shut down by a
  66. // cancellation of the SCARDCONTEXT,
  67. // it will return IDCANCEL
  68. m_fStatusDlgUp = FALSE;
  69. }
  70. // Release context
  71. if (NULL != hSCardContext)
  72. {
  73. SCardReleaseContext(hSCardContext);
  74. }
  75. // Post message that the thread is exiting, based on return...
  76. if (NULL != m_hCallbackWnd)
  77. {
  78. ::PostMessage( m_hCallbackWnd,
  79. WM_SCARD_STATUS_DLG_EXITED, // CANCELLATION (0), or ERROR (1)
  80. 0, 0);
  81. }
  82. AfxEndThread(0);
  83. return TRUE; // to make compiler happy
  84. }
  85. /*++
  86. void ShowDialog:
  87. Brings dialog to front if already open
  88. Arguments:
  89. None.
  90. Return Value:
  91. None.
  92. Author:
  93. Chris Dudley 7/30/1997
  94. Note:
  95. --*/
  96. void CSCStatusDlgThrd::ShowDialog( int nCmdShow, CStringArray* paIdleList )
  97. {
  98. if (m_fStatusDlgUp)
  99. {
  100. m_StatusDlg.ShowWindow(nCmdShow);
  101. m_StatusDlg.SetIdleList(paIdleList);
  102. }
  103. }
  104. /*++
  105. void UpdateStatus:
  106. If the dialog is up, updates idle list and status text
  107. Arguments:
  108. None.
  109. Return Value:
  110. None.
  111. Author:
  112. Chris Dudley 7/30/1997
  113. Note:
  114. --*/
  115. void CSCStatusDlgThrd::UpdateStatus( CStringArray* paIdleList )
  116. {
  117. if (m_fStatusDlgUp)
  118. {
  119. m_StatusDlg.UpdateLogonLockInfo();
  120. m_StatusDlg.SetIdleList(paIdleList);
  121. m_StatusDlg.UpdateStatusText();
  122. }
  123. }
  124. /*++
  125. void UpdateStatusText:
  126. If the dialog is up, updates Status Text and
  127. Arguments:
  128. None.
  129. Return Value:
  130. None.
  131. Author:
  132. Chris Dudley 7/30/1997
  133. Note:
  134. --*/
  135. void CSCStatusDlgThrd::UpdateStatusText( void )
  136. {
  137. if (m_fStatusDlgUp)
  138. {
  139. m_StatusDlg.UpdateStatusText();
  140. }
  141. }
  142. /*++
  143. void Close:
  144. Closes modal dialog if already open
  145. Arguments:
  146. None.
  147. Return Value:
  148. None.
  149. Author:
  150. Chris Dudley 7/30/1997
  151. Note:
  152. --*/
  153. void CSCStatusDlgThrd::Close( void )
  154. {
  155. // Setup for close
  156. if (m_fStatusDlgUp)
  157. {
  158. m_StatusDlg.EndDialog(IDOK);
  159. }
  160. m_fStatusDlgUp = FALSE;
  161. }
  162. /*++
  163. void Update:
  164. This routine updates the UI.
  165. Arguments:
  166. None.
  167. Return Value:
  168. None.
  169. Author:
  170. Chris Dudley 7/30/1997
  171. Note:
  172. --*/
  173. void CSCStatusDlgThrd::Update( void )
  174. {
  175. // Tell the dialog to update its statmonitor, if it's up.
  176. if (m_fStatusDlgUp)
  177. {
  178. m_StatusDlg.RestartMonitor();
  179. }
  180. // Do other updating
  181. UpdateStatusText();
  182. }
  183. /////////////////////////////////////////////////////////////////////////////
  184. //
  185. // CSCStatusDlg dialog
  186. //
  187. CSCStatusDlg::CSCStatusDlg(CWnd* pParent /*=NULL*/)
  188. : CDialog(CSCStatusDlg::IDD, pParent)
  189. {
  190. //{{AFX_DATA_INIT(CSCStatusDlg)
  191. // NOTE: the ClassWizard will add member initialization here
  192. //}}AFX_DATA_INIT
  193. // Note that LoadIcon does not require a subsequent DestroyIcon in Win32
  194. m_hIcon = AfxGetApp()->LoadIcon(IDI_SC_READERLOADED_V2);
  195. // Other initialization
  196. m_fEventsGood = FALSE;
  197. m_hSCardContext = NULL;
  198. m_aIdleList.RemoveAll();
  199. UpdateLogonLockInfo();
  200. }
  201. void CSCStatusDlg::UpdateLogonLockInfo(void)
  202. {
  203. m_pstrLogonReader = &(((CSCStatusApp*)AfxGetApp())->m_strLogonReader);
  204. m_pstrRemovalText = &(((CSCStatusApp*)AfxGetApp())->m_strRemovalText);
  205. m_fLogonLock = (!(m_pstrLogonReader->IsEmpty()));
  206. }
  207. void CSCStatusDlg::DoDataExchange(CDataExchange* pDX)
  208. {
  209. CDialog::DoDataExchange(pDX);
  210. //{{AFX_DATA_MAP(CSCStatusDlg)
  211. DDX_Control(pDX, IDC_SCARD_LIST, m_SCardList);
  212. DDX_Control(pDX, IDC_ALERT, m_btnAlert);
  213. DDX_Control(pDX, IDC_INFO, m_ediInfo);
  214. //}}AFX_DATA_MAP
  215. }
  216. BEGIN_MESSAGE_MAP(CSCStatusDlg, CDialog)
  217. //{{AFX_MSG_MAP(CSCStatusDlg)
  218. ON_WM_PAINT()
  219. ON_WM_QUERYDRAGICON()
  220. ON_WM_CLOSE()
  221. ON_MESSAGE( WM_READERSTATUSCHANGE, OnReaderStatusChange )
  222. ON_WM_DESTROY()
  223. ON_BN_CLICKED(IDC_ALERT, OnAlertOptions)
  224. //}}AFX_MSG_MAP
  225. END_MESSAGE_MAP()
  226. /////////////////////////////////////////////////////////////////////////////
  227. //
  228. // CSCStatusDlg Implementation
  229. /*++
  230. BOOL SetContext:
  231. Sets the Context with the resource manager
  232. Arguments:
  233. SCardContext - the context
  234. Return Value:
  235. None.
  236. Author:
  237. Chris Dudley 3/6/1997
  238. Revision History:
  239. Chris Dudley 5/13/1997
  240. --*/
  241. void CSCStatusDlg::SetContext(SCARDCONTEXT hSCardContext)
  242. {
  243. m_hSCardContext = hSCardContext;
  244. }
  245. /*++
  246. void CleanUp:
  247. Routine cleans up for exit
  248. Arguments:
  249. None.
  250. Return Value:
  251. None.
  252. Author:
  253. Chris Dudley 3/11/1997
  254. Revision History:
  255. Chris Dudley 5/13/1997
  256. --*/
  257. void CSCStatusDlg::CleanUp ( void )
  258. {
  259. m_monitor.Stop();
  260. m_SCardList.DeleteAllItems();
  261. }
  262. /*++
  263. void SetIdleList:
  264. Make a local copy of the app's list of readers with idle cards.
  265. Notes:
  266. --*/
  267. void CSCStatusDlg::SetIdleList(CStringArray* paIdleList)
  268. {
  269. m_aIdleList.Copy(*paIdleList);
  270. long lResult = UpdateSCardListCtrl();
  271. }
  272. /*++
  273. void UpdateStatusText:
  274. Reflect card usage status in text. (alert message, howto, etc.)
  275. Notes:
  276. Not localization friendly. Move strings to resources.
  277. --*/
  278. void CSCStatusDlg::UpdateStatusText( void )
  279. {
  280. CString str;
  281. if (k_State_CardIdle == ((CSCStatusApp*)AfxGetApp())->m_dwState)
  282. {
  283. str = _T("A smart card has been left idle. You may safely remove it now.");
  284. }
  285. else
  286. {
  287. str = _T("Click the button on the left to change your alert options.");
  288. }
  289. m_ediInfo.SetWindowText(str);
  290. }
  291. /*++
  292. void InitSCardListCtrl:
  293. This routine sets up the CListCtrl properly for display
  294. Arguments:
  295. None.
  296. Return Value:
  297. None.
  298. Author:
  299. Chris Dudley 3/6/1997
  300. Revision History:
  301. Chris Dudley 5/13/1997
  302. --*/
  303. void CSCStatusDlg::InitSCardListCtrl( void )
  304. {
  305. CString strHeader;
  306. CImageList imageList;
  307. HICON hicon;
  308. // Create columns in list control
  309. strHeader.LoadString(IDS_SC_READER);
  310. m_SCardList.InsertColumn(READER_COLUMN,
  311. strHeader,
  312. LVCFMT_LEFT,
  313. 100,
  314. -1);
  315. strHeader.LoadString(IDS_SC_CARDSTATUS);
  316. m_SCardList.InsertColumn(STATUS_COLUMN,
  317. strHeader,
  318. LVCFMT_LEFT,
  319. 600,
  320. -1);
  321. strHeader.LoadString(IDS_SC_CARD);
  322. m_SCardList.InsertColumn(CARD_COLUMN,
  323. strHeader,
  324. LVCFMT_LEFT,
  325. 100,
  326. -1);
  327. // Create the image list & give it to the list control
  328. imageList.Create ( IMAGE_WIDTH,
  329. IMAGE_HEIGHT,
  330. TRUE, // list does not include masks
  331. NUMBER_IMAGES,
  332. 0); // list won't grow
  333. // Build the list
  334. for (int ix = 0; ix < NUMBER_IMAGES; ix++ )
  335. {
  336. // Load icon and add it to image list
  337. hicon = ::LoadIcon(AfxGetInstanceHandle(),
  338. MAKEINTRESOURCE(IMAGE_LIST_IDS[ix]) );
  339. imageList.Add(hicon);
  340. }
  341. // Be sure that all the small icons were added.
  342. _ASSERTE(imageList.GetImageCount() == NUMBER_IMAGES);
  343. m_SCardList.SetImageList(&imageList, (int) LVSIL_SMALL);
  344. imageList.Detach(); // leave the images intact when we go out of scope
  345. }
  346. /*++
  347. LONG UpdateSCardListCtrl:
  348. This routine updates the list box display.
  349. Arguments:
  350. None.
  351. Return Value:
  352. A LONG value indicating the status of the requested action. Please
  353. see the Smartcard header files for additional information.
  354. Author:
  355. Chris Dudley 3/7/1997
  356. Revision History:
  357. Chris Dudley 5/13/1997
  358. Notes:
  359. 1. Strings need to be converted from type stored in the smartcard
  360. thread help classes to this dialog's build type (i.e. UNICODE/ANSI)!!!!
  361. --*/
  362. LONG CSCStatusDlg::UpdateSCardListCtrl( void )
  363. {
  364. LONG lReturn = SCARD_S_SUCCESS;
  365. LONG lMoreReaders = SCARD_S_SUCCESS;
  366. CSCardReaderState* pReader;
  367. int nImage = 0;
  368. LV_ITEM lv_item;
  369. CString strCardStatus, strCardName;
  370. //
  371. // If the status monitor is not running,
  372. // Don't bother to update SCardListCtrl
  373. // If there used to be readers, display an error and shut down dialog
  374. //
  375. if (CScStatusMonitor::running != m_monitor.GetStatus())
  376. {
  377. m_SCardList.EnableWindow(FALSE);
  378. DoErrorMessage();
  379. return lReturn;
  380. }
  381. // Setup LV_ITEM struct
  382. lv_item.mask = LVIF_TEXT | LVIF_IMAGE | LVIF_PARAM | LVIF_STATE;
  383. // Remove old items from list if required
  384. m_SCardList.DeleteAllItems();
  385. //
  386. // Update the reader information
  387. //
  388. m_monitor.GetReaderStatus(m_aReaderState);
  389. //
  390. // Recreate the items in the reader list (UI)
  391. //
  392. int nNumReaders = (int)m_aReaderState.GetSize();
  393. for(int nIndex = 0; nIndex < nNumReaders; nIndex++)
  394. {
  395. // Setup struct for system reader list
  396. pReader = m_aReaderState[nIndex];
  397. lv_item.state = 0;
  398. lv_item.stateMask = 0;
  399. lv_item.iItem = nIndex;
  400. lv_item.iSubItem = 0;
  401. lv_item.pszText = _T("");
  402. lv_item.cchTextMax = MAX_ITEMLEN;
  403. lv_item.iImage = (int)READEREMPTY;
  404. if (NULL != pReader)
  405. {
  406. lv_item.pszText = (LPTSTR)(LPCTSTR)((m_aReaderState[nIndex])->strReader);
  407. // Get the card status: image
  408. DWORD dwState = (m_aReaderState[nIndex])->dwState;
  409. if (dwState == SC_STATUS_NO_CARD)
  410. {
  411. lv_item.iImage = (int)READEREMPTY;
  412. }
  413. else if (dwState == SC_STATUS_ERROR)
  414. {
  415. lv_item.iImage = (int)READERERROR;
  416. }
  417. else
  418. {
  419. // normally, this would be a "card loaded"...
  420. lv_item.iImage = (int)READERLOADED;
  421. // ...unless the card is the logon/locked card or idle
  422. if (m_fLogonLock &&
  423. (0 == m_pstrLogonReader->Compare((m_aReaderState[nIndex])->strReader)))
  424. {
  425. lv_item.iImage = (int)READERLOCK;
  426. }
  427. else
  428. {
  429. for (int n1=(int)m_aIdleList.GetUpperBound(); n1>=0; n1--)
  430. {
  431. if (m_aIdleList[n1] == (m_aReaderState[nIndex])->strReader)
  432. {
  433. lv_item.iImage = (int)READERINFO;
  434. break;
  435. }
  436. }
  437. }
  438. }
  439. // Add Reader Item
  440. m_SCardList.InsertItem(&lv_item);
  441. // Add Card Name sub item
  442. if (dwState != SC_STATUS_NO_CARD && dwState != SC_STATUS_ERROR)
  443. {
  444. // Set card name if not available
  445. strCardName = (LPCTSTR)(m_aReaderState[nIndex])->strCard;
  446. if (strCardName.IsEmpty())
  447. {
  448. strCardName.LoadString(IDS_SC_NAME_UNKNOWN);
  449. }
  450. m_SCardList.SetItemText(nIndex,
  451. CARD_COLUMN,
  452. strCardName);
  453. }
  454. // Add Card Status sub item
  455. ASSERT(dwState >= SC_STATUS_FIRST && dwState <= SC_STATUS_LAST);
  456. strCardStatus.LoadString(CARD_STATUS_IDS[dwState]);
  457. if (m_fLogonLock &&
  458. (0 == m_pstrLogonReader->Compare((m_aReaderState[nIndex])->strReader)))
  459. {
  460. CString strTemp = *m_pstrRemovalText + strCardStatus;
  461. strCardStatus = strTemp;
  462. }
  463. m_SCardList.SetItemText(nIndex,
  464. STATUS_COLUMN,
  465. strCardStatus);
  466. strCardStatus.Empty();
  467. strCardName.Empty();
  468. }
  469. }
  470. // If we got this far, things are OK. Make sure the window is enabled.
  471. m_SCardList.EnableWindow(TRUE);
  472. return lReturn;
  473. }
  474. /*++
  475. void RestartMonitor:
  476. This routine forces the monitor to refresh its list of readers.
  477. Arguments:
  478. None.
  479. Return Value:
  480. None.
  481. Author:
  482. Amanda Matlosz 11/04/1998
  483. Notes:
  484. --*/
  485. void CSCStatusDlg::RestartMonitor( void )
  486. {
  487. m_monitor.Start(m_hWnd, WM_READERSTATUSCHANGE);
  488. }
  489. /////////////////////////////////////////////////////////////////////////////
  490. //
  491. // CSCStatusDlg message handlers
  492. //
  493. /*++
  494. void OnInitDialog:
  495. Performs dialog initialization.
  496. Arguments:
  497. None.
  498. Return Value:
  499. TRUE if successful and dialog should be displayed. FALSE otherwise.
  500. Author:
  501. Chris Dudley 7/30/1997
  502. Note:
  503. --*/
  504. BOOL CSCStatusDlg::OnInitDialog()
  505. {
  506. LONG lReturn = SCARD_S_SUCCESS;
  507. CDialog::OnInitDialog();
  508. //
  509. // Initialize the CScStatusMonitor
  510. //
  511. m_monitor.Start(m_hWnd, WM_READERSTATUSCHANGE);
  512. //
  513. // Initialize the list control -- whether or not the monitor has started!
  514. //
  515. InitSCardListCtrl();
  516. lReturn = UpdateSCardListCtrl();
  517. //
  518. // Show the dialog IFF the above succeeded
  519. //
  520. if (SCARD_S_SUCCESS == lReturn)
  521. {
  522. // Set the status text
  523. UpdateStatusText();
  524. // Set the icon for this dialog. The framework does this automatically
  525. // when the application's main window is not a dialog
  526. SetIcon(m_hIcon, TRUE); // Set big icon
  527. SetIcon(m_hIcon, FALSE); // Set small icon
  528. // set icon for Alerts button
  529. HICON hIcon = AfxGetApp()->LoadIcon(IDI_SC_INFO);
  530. SendDlgItemMessage(IDC_ALERT, BM_SETIMAGE, IMAGE_ICON, (LPARAM)hIcon);
  531. // Center the dialog and bring it to top
  532. CenterWindow();
  533. SetWindowPos( &wndTop,
  534. 0,0,0,0,
  535. SWP_NOMOVE | SWP_NOSIZE);
  536. SetActiveWindow();
  537. // Set Parent to desktop
  538. SetParent(NULL);
  539. }
  540. else
  541. {
  542. //
  543. // If any of the initialization depending on the resource manager failed,
  544. // give up and report a death-due-to-some-error to the caller
  545. //
  546. PostMessage(WM_CLOSE, 0, 0); // need to CANCEL, instead of close...
  547. TRACE_CATCH_UNKNOWN(_T("OnInitDialog"));
  548. }
  549. return TRUE; // return TRUE unless you set the focus to a control
  550. }
  551. /*++
  552. void OnPaint:
  553. Used to paint dialog. In this case, used to draw the icon for the dialog
  554. while minimized/maximized.
  555. Arguments:
  556. None.
  557. Return Value:
  558. None.
  559. Author:
  560. Chris Dudley 7/30/1997
  561. Note:
  562. --*/
  563. void CSCStatusDlg::OnPaint()
  564. {
  565. if (IsIconic())
  566. {
  567. CPaintDC dc(this); // device context for painting
  568. SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);
  569. // Center icon in client rectangle
  570. int cxIcon = GetSystemMetrics(SM_CXICON);
  571. int cyIcon = GetSystemMetrics(SM_CYICON);
  572. CRect rect;
  573. GetClientRect(&rect);
  574. int x = (rect.Width() - cxIcon + 1) / 2;
  575. int y = (rect.Height() - cyIcon + 1) / 2;
  576. // Draw the icon
  577. dc.DrawIcon(x, y, m_hIcon);
  578. }
  579. else
  580. {
  581. CDialog::OnPaint();
  582. }
  583. }
  584. /*++
  585. void OnQueryDragIcon:
  586. The system calls this to obtain the cursor to display while the user drags
  587. the minimized window.
  588. Arguments:
  589. None.
  590. Return Value:
  591. HCURSOR handle to cursor to display
  592. Author:
  593. Chris Dudley 7/30/1997
  594. Note:
  595. --*/
  596. HCURSOR CSCStatusDlg::OnQueryDragIcon()
  597. {
  598. return (HCURSOR) m_hIcon;
  599. }
  600. /*++
  601. void DestroyWindow:
  602. This is called by MFC whenever the dialog is closed, whether that is
  603. through WM_CLOSE (sysmenu "X") or EndDialog(IDOK/IDCANCEL)...
  604. Arguments:
  605. None.
  606. Return Value:
  607. Base class version of DestroyWindow.
  608. Author:
  609. Amanda Matlosz 4/29/98
  610. Note:
  611. --*/
  612. BOOL CSCStatusDlg::DestroyWindow()
  613. {
  614. CleanUp();
  615. return CDialog::DestroyWindow();
  616. }
  617. /*++
  618. void OnReaderStatusChange:
  619. This message handler is called by the status thread when smartcard status
  620. has changed.
  621. Arguments:
  622. None.
  623. Return Value:
  624. None
  625. Author:
  626. Chris Dudley 3/9/1997
  627. Revision History:
  628. Chris Dudley 5/13/1997
  629. Note:
  630. 1. No formal parameters are declared. These are not used and
  631. will stop compiler warnings from being generated.
  632. --*/
  633. LONG CSCStatusDlg::OnReaderStatusChange( UINT , LONG )
  634. {
  635. // Update the display
  636. UpdateSCardListCtrl();
  637. return 0;
  638. }
  639. /*++
  640. allow user to set alert options (sound, pop-up, neither)
  641. --*/
  642. void CSCStatusDlg::OnAlertOptions()
  643. {
  644. COptionsDlg dlg;
  645. #ifdef ISOLATION_AWARE_ENABLED
  646. CThemeContextActivator activator;
  647. #endif
  648. dlg.DoModal();
  649. }
  650. /*++
  651. void DoErrorMessage:
  652. This is a helper routine to keep the UI stuff in one place and make sure
  653. the same error messages are handled consistently throughout.
  654. Arguments:
  655. None.
  656. Return Value:
  657. None
  658. Author:
  659. Amanda Matlosz 5/21/98
  660. Revision History:
  661. Note:
  662. 1. Consider taking an error code as well as m_monitor.GetStatus()
  663. --*/
  664. void CSCStatusDlg::DoErrorMessage( void )
  665. {
  666. CString strMsg;
  667. BOOL fShutDownDlg = FALSE;
  668. switch(m_monitor.GetStatus())
  669. {
  670. case CScStatusMonitor::no_service:
  671. fShutDownDlg = TRUE;
  672. strMsg.LoadString(IDS_NO_SYSTEM_STATUS);
  673. break;
  674. case CScStatusMonitor::no_readers:
  675. // for now, do nothing!
  676. break;
  677. case CScStatusMonitor::stopped:
  678. // do nothing! This is a clean stop on the way to shutting down.
  679. break;
  680. case CScStatusMonitor::uninitialized:
  681. case CScStatusMonitor::unknown:
  682. case CScStatusMonitor::running:
  683. fShutDownDlg = TRUE;
  684. strMsg.LoadString(IDS_UNKNOWN_ERROR);
  685. }
  686. if (!strMsg.IsEmpty())
  687. {
  688. CString strTitle;
  689. strTitle.LoadString(IDS_TITLE_ERROR);
  690. MessageBox(strMsg, strTitle, MB_OK | MB_ICONINFORMATION);
  691. }
  692. if (fShutDownDlg)
  693. {
  694. PostMessage(WM_CLOSE, 0, 0);
  695. }
  696. }
  697. /////////////////////////////////////////////////////////////////////////////
  698. // COptionsDlg dialog
  699. COptionsDlg::COptionsDlg(CWnd* pParent /*=NULL*/)
  700. : CDialog(COptionsDlg::IDD, pParent)
  701. {
  702. BOOL fSound = FALSE;
  703. BOOL fDlg = FALSE;
  704. switch(((CSCStatusApp*)AfxGetApp())->m_dwAlertOption)
  705. {
  706. case k_AlertOption_IconSound:
  707. fSound = TRUE;
  708. break;
  709. case k_AlertOption_IconSoundMsg:
  710. fSound = TRUE;
  711. case k_AlertOption_IconMsg:
  712. fDlg = TRUE;
  713. break;
  714. }
  715. //{{AFX_DATA_INIT(COptionsDlg)
  716. m_fDlg = fDlg;
  717. m_fSound = fSound;
  718. //}}AFX_DATA_INIT
  719. }
  720. void COptionsDlg::DoDataExchange(CDataExchange* pDX)
  721. {
  722. CDialog::DoDataExchange(pDX);
  723. //{{AFX_DATA_MAP(COptionsDlg)
  724. DDX_Check(pDX, IDC_DIALOG, m_fDlg);
  725. DDX_Check(pDX, IDC_SOUND, m_fSound);
  726. //}}AFX_DATA_MAP
  727. }
  728. BEGIN_MESSAGE_MAP(COptionsDlg, CDialog)
  729. //{{AFX_MSG_MAP(COptionsDlg)
  730. //}}AFX_MSG_MAP
  731. END_MESSAGE_MAP()
  732. /////////////////////////////////////////////////////////////////////////////
  733. // COptionsDlg message handlers
  734. void COptionsDlg::OnOK()
  735. {
  736. // use status of check boxes to set alert options state for app
  737. UpdateData(TRUE);
  738. if (TRUE == m_fSound)
  739. {
  740. if (TRUE == m_fDlg)
  741. {
  742. ((CSCStatusApp*)AfxGetApp())->m_dwAlertOption = k_AlertOption_IconSoundMsg;
  743. }
  744. else
  745. {
  746. ((CSCStatusApp*)AfxGetApp())->m_dwAlertOption = k_AlertOption_IconSound;
  747. }
  748. }
  749. else if (TRUE == m_fDlg)
  750. {
  751. ((CSCStatusApp*)AfxGetApp())->m_dwAlertOption = k_AlertOption_IconMsg;
  752. }
  753. else
  754. {
  755. ((CSCStatusApp*)AfxGetApp())->m_dwAlertOption = k_AlertOption_IconOnly;
  756. }
  757. CDialog::OnOK();
  758. }