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.

1076 lines
25 KiB

  1. /*++
  2. Copyright (C) 1996-1999 Microsoft Corporation
  3. Module Name:
  4. smonprop.cpp
  5. Abstract:
  6. Sysmon property page base class.
  7. --*/
  8. #include "polyline.h"
  9. #include <strsafe.h>
  10. #include "smonprop.h"
  11. #include "genprop.h"
  12. #include "ctrprop.h"
  13. #include "grphprop.h"
  14. #include "srcprop.h"
  15. #include "appearprop.h"
  16. #include "unihelpr.h"
  17. #include "utils.h"
  18. #include "smonhelp.h"
  19. #include "globals.h"
  20. static ULONG
  21. aulControlIdToHelpIdMap[] =
  22. {
  23. IDC_CTRLIST, IDH_CTRLIST, // Data
  24. IDC_ADDCTR, IDH_ADDCTR,
  25. IDC_DELCTR, IDH_DELCTR,
  26. IDC_LINECOLOR, IDH_LINECOLOR,
  27. IDC_LINEWIDTH, IDH_LINEWIDTH,
  28. IDC_LINESTYLE, IDH_LINESTYLE,
  29. IDC_LINESCALE, IDH_LINESCALE,
  30. IDC_GALLERY_REPORT, IDH_GALLERY_REPORT, // General
  31. IDC_GALLERY_GRAPH, IDH_GALLERY_GRAPH,
  32. IDC_GALLERY_HISTOGRAM, IDH_GALLERY_HISTOGRAM,
  33. IDC_VALUEBAR, IDH_VALUEBAR,
  34. IDC_TOOLBAR, IDH_TOOLBAR,
  35. IDC_LEGEND, IDH_LEGEND,
  36. IDC_RPT_VALUE_DEFAULT, IDH_RPT_VALUE_DEFAULT,
  37. IDC_RPT_VALUE_MINIMUM, IDH_RPT_VALUE_MINIMUM,
  38. IDC_RPT_VALUE_MAXIMUM, IDH_RPT_VALUE_MAXIMUM,
  39. IDC_RPT_VALUE_AVERAGE, IDH_RPT_VALUE_AVERAGE,
  40. IDC_RPT_VALUE_CURRENT, IDH_RPT_VALUE_CURRENT,
  41. IDC_COMBOAPPEARANCE, IDH_COMBOAPPEARANCE,
  42. IDC_COMBOBORDERSTYLE, IDH_COMBOBORDERSTYLE,
  43. IDC_PERIODIC_UPDATE, IDH_PERIODIC_UPDATE,
  44. IDC_DISPLAY_INTERVAL, IDH_DISPLAY_INTERVAL,
  45. IDC_UPDATE_INTERVAL, IDH_UPDATE_INTERVAL,
  46. IDC_DUPLICATE_INSTANCE, IDH_DUPLICATE_INSTANCE,
  47. IDC_GRAPH_TITLE, IDH_GRAPH_TITLE, // Graph
  48. IDC_YAXIS_TITLE, IDH_YAXIS_TITLE,
  49. IDC_VERTICAL_GRID, IDH_VERTICAL_GRID,
  50. IDC_HORIZONTAL_GRID, IDH_HORIZONTAL_GRID,
  51. IDC_VERTICAL_LABELS, IDH_VERTICAL_LABELS,
  52. IDC_VERTICAL_MAX, IDH_VERTICAL_MAX,
  53. IDC_VERTICAL_MIN, IDH_VERTICAL_MIN,
  54. IDC_SRC_REALTIME, IDH_SRC_REALTIME, // Source
  55. IDC_SRC_LOGFILE, IDH_SRC_LOGFILE,
  56. IDC_SRC_SQL, IDH_SRC_SQL,
  57. IDC_LIST_LOGFILENAME, IDH_LIST_LOGFILENAME,
  58. IDC_ADDFILE, IDH_ADDFILE,
  59. IDC_REMOVEFILE, IDH_REMOVEFILE,
  60. IDC_LOGSET_COMBO, IDH_LOGSET_COMBO,
  61. IDC_DSN_COMBO, IDH_DSN_COMBO,
  62. IDC_TIMESELECTBTN, IDH_TIMESELECTBTN,
  63. IDC_TIMERANGE, IDH_TIMERANGE,
  64. IDC_COLOROBJECTS, IDH_COLOROBJECTS,
  65. IDC_FONTBUTTON, IDH_FONTBUTTON,
  66. IDC_COLORBUTTON, IDH_COLORBUTTON,
  67. IDC_COLORSAMPLE, IDH_COLORSAMPLE,
  68. IDC_FONTSAMPLE, IDH_FONTSAMPLE,
  69. 0,0
  70. };
  71. /*
  72. * CSysmonPropPageFactory::CSysmonPropPageFactory
  73. * CSysmonPropPageFactory::~CSysmonPropPageFactory
  74. * CSysmonPropPageFactory::QueryInterface
  75. * CSysmonPropPageFactory::AddRef
  76. * CSysmonPropPageFactory::Release
  77. */
  78. CSysmonPropPageFactory::CSysmonPropPageFactory(INT nPageID)
  79. {
  80. m_cRef=0L;
  81. m_nPageID = nPageID;
  82. return;
  83. }
  84. CSysmonPropPageFactory::~CSysmonPropPageFactory(void)
  85. {
  86. return;
  87. }
  88. STDMETHODIMP CSysmonPropPageFactory::QueryInterface(REFIID riid, PPVOID ppv)
  89. {
  90. HRESULT hr = S_OK;
  91. try {
  92. *ppv=NULL;
  93. if (IID_IUnknown==riid || IID_IClassFactory==riid) {
  94. *ppv=this;
  95. AddRef();
  96. }
  97. else {
  98. hr = E_NOINTERFACE;
  99. }
  100. } catch (...) {
  101. hr = E_POINTER;
  102. }
  103. return hr;
  104. }
  105. STDMETHODIMP_(ULONG) CSysmonPropPageFactory::AddRef(void)
  106. {
  107. return ++m_cRef;
  108. }
  109. STDMETHODIMP_(ULONG) CSysmonPropPageFactory::Release(void)
  110. {
  111. if (0!=--m_cRef)
  112. return m_cRef;
  113. delete this;
  114. return 0;
  115. }
  116. /*
  117. * CSysmonPropPageFactory::CreateInstance
  118. * CSysmonPropPageFactory::LockServer
  119. */
  120. STDMETHODIMP CSysmonPropPageFactory::CreateInstance(
  121. IN LPUNKNOWN pUnkOuter,
  122. IN REFIID riid,
  123. OUT PPVOID ppvObj
  124. )
  125. {
  126. PCSysmonPropPage pObj;
  127. HRESULT hr = NOERROR;
  128. //
  129. // No aggregation supported
  130. //
  131. if (NULL != pUnkOuter) {
  132. return (CLASS_E_NOAGGREGATION);
  133. }
  134. switch (m_nPageID) {
  135. case GENERAL_PROPPAGE:
  136. pObj = new CGeneralPropPage();
  137. break;
  138. case SOURCE_PROPPAGE:
  139. pObj = new CSourcePropPage();
  140. break;
  141. case COUNTER_PROPPAGE:
  142. pObj = new CCounterPropPage();
  143. break;
  144. case GRAPH_PROPPAGE:
  145. pObj = new CGraphPropPage();
  146. break;
  147. case APPEAR_PROPPAGE:
  148. pObj = new CAppearPropPage();
  149. break;
  150. default:
  151. pObj = NULL;
  152. }
  153. if (NULL == pObj)
  154. return E_OUTOFMEMORY;
  155. if (pObj->Init()) {
  156. try {
  157. *ppvObj = NULL;
  158. hr = pObj->QueryInterface(riid, ppvObj);
  159. } catch (...) {
  160. hr = E_POINTER;
  161. }
  162. } else {
  163. hr = E_UNEXPECTED;
  164. }
  165. //Kill the object if initial creation or Init failed.
  166. if (FAILED(hr)) {
  167. delete pObj;
  168. }
  169. else {
  170. InterlockedIncrement(&g_cObj);
  171. }
  172. return hr;
  173. }
  174. STDMETHODIMP CSysmonPropPageFactory::LockServer(BOOL fLock)
  175. {
  176. if (fLock) {
  177. InterlockedIncrement(&g_cLock);
  178. }
  179. else {
  180. InterlockedDecrement(&g_cLock);
  181. }
  182. return NOERROR;
  183. }
  184. /*
  185. * CSysmonPropPage implementation
  186. */
  187. CSysmonPropPage::CSysmonPropPage(void)
  188. : m_cRef ( 0 ),
  189. m_hDlg ( NULL ),
  190. m_pIPropertyPageSite ( NULL ),
  191. m_ppISysmon ( NULL ),
  192. m_cObjects ( 0 ),
  193. m_cx ( 300 ), // Default width
  194. m_cy ( 100 ), // Default height
  195. m_fDirty ( FALSE ),
  196. m_fActive ( FALSE ),
  197. m_lcid ( LOCALE_USER_DEFAULT ),
  198. m_dwEditControl ( 0 )
  199. {
  200. return;
  201. }
  202. CSysmonPropPage::~CSysmonPropPage(void)
  203. {
  204. if (NULL != m_hDlg)
  205. DestroyWindow(m_hDlg);
  206. FreeAllObjects();
  207. ReleaseInterface(m_pIPropertyPageSite);
  208. return;
  209. }
  210. /*
  211. * CSysmonPropPage::QueryInterface
  212. * CSysmonPropPage::AddRef
  213. * CSysmonPropPage::Release
  214. */
  215. STDMETHODIMP CSysmonPropPage::QueryInterface(REFIID riid, PPVOID ppv)
  216. {
  217. HRESULT hr = S_OK;
  218. try {
  219. *ppv=NULL;
  220. if (IID_IUnknown==riid || IID_IPropertyPage==riid) {
  221. *ppv=this;
  222. AddRef();
  223. }
  224. else {
  225. hr = E_NOINTERFACE;
  226. }
  227. } catch (...) {
  228. hr = E_POINTER;
  229. }
  230. return hr;
  231. }
  232. STDMETHODIMP_(ULONG) CSysmonPropPage::AddRef(void)
  233. {
  234. return ++m_cRef;
  235. }
  236. STDMETHODIMP_(ULONG) CSysmonPropPage::Release(void)
  237. {
  238. if (0 != --m_cRef)
  239. return m_cRef;
  240. InterlockedDecrement(&g_cObj);
  241. delete this;
  242. return 0;
  243. }
  244. /*
  245. * CSysmonPropPage::Init
  246. *
  247. * Purpose:
  248. * Performs initialization operations that might fail.
  249. *
  250. * Parameters:
  251. * None
  252. *
  253. * Return Value:
  254. * BOOL TRUE if initialization successful, FALSE
  255. * otherwise.
  256. */
  257. BOOL CSysmonPropPage::Init(void)
  258. {
  259. //Nothing to do
  260. return TRUE;
  261. }
  262. /*
  263. * CSysmonPropPage::FreeAllObjects
  264. *
  265. * Purpose:
  266. * Releases all the objects from IPropertyPage::SetObjects
  267. *
  268. * Parameters:
  269. * None
  270. */
  271. void CSysmonPropPage::FreeAllObjects(void)
  272. {
  273. UINT i;
  274. if (NULL==m_ppISysmon)
  275. return;
  276. for (i=0; i < m_cObjects; i++)
  277. ReleaseInterface(m_ppISysmon[i]);
  278. delete [] m_ppISysmon;
  279. m_ppISysmon =NULL;
  280. m_cObjects = 0;
  281. }
  282. /*
  283. * CSysmonPropPage::SetChange
  284. *
  285. * Purpose:
  286. * Set the page dirty flag to indicate a change
  287. * If page site is active, send status change to it.
  288. *
  289. * Parameters:
  290. * None
  291. */
  292. void CSysmonPropPage::SetChange(void)
  293. {
  294. if (m_fActive)
  295. {
  296. m_fDirty=TRUE;
  297. if (NULL != m_pIPropertyPageSite)
  298. {
  299. m_pIPropertyPageSite->OnStatusChange(PROPPAGESTATUS_DIRTY);
  300. }
  301. }
  302. }
  303. /*
  304. * CSysmonPropPage::SetPageSite
  305. *
  306. * Purpose:
  307. * Provides the property page with the IPropertyPageSite
  308. * that contains it. SetPageSite(NULL) will be called as
  309. * part of the close sequence.
  310. *
  311. * Parameters:
  312. * pPageSite LPPROPERTYPAGESITE pointer to the site.
  313. */
  314. STDMETHODIMP CSysmonPropPage::SetPageSite(
  315. LPPROPERTYPAGESITE pPageSite
  316. )
  317. {
  318. HRESULT hr = S_OK;
  319. if (NULL==pPageSite)
  320. ReleaseInterface(m_pIPropertyPageSite)
  321. else
  322. {
  323. HWND hDlg;
  324. RECT rc;
  325. LCID lcid;
  326. try {
  327. m_pIPropertyPageSite=pPageSite;
  328. m_pIPropertyPageSite->AddRef();
  329. if (SUCCEEDED(m_pIPropertyPageSite->GetLocaleID(&lcid)))
  330. m_lcid=lcid;
  331. /*
  332. * Load the dialog and determine the size it will be to
  333. * return through GetPageSize. We just create the dialog
  334. * here and destroy it again to retrieve the size,
  335. * leaving Activate to create it for real.
  336. */
  337. hDlg=CreateDialogParam(g_hInstance,
  338. MAKEINTRESOURCE(m_uIDDialog),
  339. GetDesktopWindow(),
  340. SysmonPropPageProc,
  341. 0L);
  342. //
  343. // If creation fails, use default values set in constructor
  344. // and return success status.
  345. if (NULL!=hDlg)
  346. {
  347. GetWindowRect(hDlg, &rc);
  348. m_cx=rc.right-rc.left;
  349. m_cy=rc.bottom-rc.top;
  350. DestroyWindow(hDlg);
  351. }
  352. } catch (...) {
  353. hr = E_POINTER;
  354. }
  355. }
  356. return hr;
  357. }
  358. /*
  359. * CSysmonPropPage::Activate
  360. *
  361. * Purpose:
  362. * Instructs the property page to create a window in which to
  363. * display its contents, using the given parent window and
  364. * rectangle. The window should be initially visible.
  365. *
  366. * Parameters:
  367. * hWndParent HWND of the parent window.
  368. * prc LPCRECT of the rectangle to use.
  369. * fModal BOOL indicating whether the frame is modal.
  370. */
  371. STDMETHODIMP CSysmonPropPage::Activate(
  372. HWND hWndParent,
  373. LPCRECT prc,
  374. BOOL /* fModal */
  375. )
  376. {
  377. if (NULL!=m_hDlg)
  378. return (E_UNEXPECTED);
  379. m_hDlg=CreateDialogParam(g_hInstance,
  380. MAKEINTRESOURCE(m_uIDDialog),
  381. hWndParent,
  382. SysmonPropPageProc,
  383. (LPARAM)this);
  384. if (NULL==m_hDlg) {
  385. //
  386. // Return E_OUTOFMEMORY because caller of Activate might not
  387. // handle HRESULT_FROM_WIN32(GetLastError());
  388. //
  389. return E_OUTOFMEMORY;
  390. }
  391. if (!InitControls()) {
  392. return E_OUTOFMEMORY;
  393. }
  394. if (!GetProperties()) {
  395. return E_OUTOFMEMORY;
  396. }
  397. //
  398. //Move the page into position and show it.
  399. //
  400. try {
  401. SetWindowPos(m_hDlg, NULL, prc->left, prc->top, 0, 0, SWP_NOSIZE );
  402. } catch (...) {
  403. return E_POINTER;
  404. }
  405. m_fActive = TRUE;
  406. return NOERROR;
  407. }
  408. /*
  409. * CSysmonPropPage::Deactivate
  410. *
  411. * Purpose:
  412. * Instructs the property page to destroy its window that was
  413. * created in Activate.
  414. *
  415. * Parameters:
  416. * None
  417. */
  418. STDMETHODIMP CSysmonPropPage::Deactivate(void)
  419. {
  420. if (NULL==m_hDlg)
  421. return (E_UNEXPECTED);
  422. DeinitControls();
  423. DestroyWindow(m_hDlg);
  424. m_hDlg=NULL;
  425. m_fActive = FALSE;
  426. return NOERROR;
  427. }
  428. /*
  429. * CSysmonPropPage::GetPageInfo
  430. *
  431. * Purpose:
  432. * Fills a PROPPAGEINFO structure describing the page's size,
  433. * contents, and help information.
  434. *
  435. * Parameters:
  436. * pPageInfo LPPROPPAGEINFO to the structure to fill.
  437. */
  438. STDMETHODIMP CSysmonPropPage::GetPageInfo(
  439. LPPROPPAGEINFO pPageInfo
  440. )
  441. {
  442. IMalloc * pIMalloc;
  443. LPWSTR pTitle = NULL;
  444. ULONG ulTitleLen = 0;
  445. LPWSTR pBuf = NULL;
  446. pTitle = ResourceString(m_uIDTitle);
  447. if (pTitle) {
  448. ulTitleLen = wcslen(pTitle) + 1;
  449. if (FAILED(CoGetMalloc(MEMCTX_TASK, &pIMalloc))) {
  450. return (E_FAIL);
  451. }
  452. pBuf = (LPWSTR)pIMalloc->Alloc(ulTitleLen * sizeof(WCHAR));
  453. if (NULL != pBuf) {
  454. //
  455. // We already reserved an extra position for the null character
  456. //
  457. StringCchCopy(pBuf, ulTitleLen, pTitle);
  458. }
  459. pIMalloc->Release();
  460. }
  461. try {
  462. pPageInfo->size.cx = m_cx;
  463. pPageInfo->size.cy = m_cy;
  464. pPageInfo->pszDocString = NULL;
  465. pPageInfo->pszHelpFile = NULL;
  466. pPageInfo->dwHelpContext= 0;
  467. pPageInfo->pszTitle = pBuf;
  468. } catch (...) {
  469. return E_POINTER;
  470. }
  471. return S_OK;
  472. }
  473. /*
  474. * CSysmonPropPage::SetObjects
  475. *
  476. * Purpose:
  477. * Identifies the objects that are being affected by this property
  478. * page (and all other pages in the frame). These are the object
  479. * to which to send new property values in the Apply member.
  480. *
  481. * Parameters:
  482. * cObjects ULONG number of objects
  483. * ppUnk IUnknown ** to the array of objects being
  484. * passed to the page.
  485. */
  486. STDMETHODIMP CSysmonPropPage::SetObjects(
  487. IN ULONG cObjects,
  488. IN IUnknown **ppUnk
  489. )
  490. {
  491. HRESULT hr = S_OK;
  492. FreeAllObjects();
  493. if (0 != cObjects) {
  494. UINT i;
  495. m_ppISysmon = new ISystemMonitor * [(UINT)cObjects];
  496. if (m_ppISysmon == NULL)
  497. return E_OUTOFMEMORY;
  498. try {
  499. for (i=0; i < cObjects; i++)
  500. {
  501. hr=ppUnk[i]->QueryInterface(IID_ISystemMonitor,
  502. (void **)&m_ppISysmon[i]);
  503. if (FAILED(hr)) {
  504. break;
  505. }
  506. }
  507. } catch (...) {
  508. hr = E_POINTER;
  509. }
  510. }
  511. if ( FAILED ( hr ) && NULL != m_ppISysmon ) {
  512. //
  513. // Ref count never incremented, so delete the array.
  514. //
  515. delete [] m_ppISysmon;
  516. m_ppISysmon = NULL;
  517. }
  518. if ( SUCCEEDED ( hr ) ) {
  519. m_cObjects=cObjects;
  520. }
  521. return hr;
  522. }
  523. /*
  524. * CSysmonPropPage::Show
  525. *
  526. * Purpose:
  527. * Instructs the page to show or hide its window created in
  528. * Activate.
  529. *
  530. * Parameters:
  531. * nCmdShow UINT to pass to ShowWindow.
  532. */
  533. STDMETHODIMP CSysmonPropPage::Show(UINT nCmdShow)
  534. {
  535. if (NULL==m_hDlg)
  536. (E_UNEXPECTED);
  537. ShowWindow(m_hDlg, nCmdShow);
  538. // If showing page
  539. if (SW_SHOWNORMAL==nCmdShow || SW_SHOW==nCmdShow) {
  540. // Take the focus
  541. // (Have to delay so it isn't taken back)
  542. PostMessage(m_hDlg,WM_SETPAGEFOCUS,0,0);
  543. }
  544. return NOERROR;
  545. }
  546. /*
  547. * CSysmonPropPage::Move
  548. *
  549. * Purpose:
  550. * Instructs the property page to change its position.
  551. *
  552. * Parameters:
  553. * prc LPCRECT containing the new position.
  554. */
  555. STDMETHODIMP CSysmonPropPage::Move(
  556. LPCRECT prc
  557. )
  558. {
  559. HRESULT hr = S_OK;
  560. try {
  561. SetWindowPos(m_hDlg, NULL, prc->left, prc->top, 0, 0, SWP_NOSIZE );
  562. } catch (...) {
  563. hr = E_POINTER;
  564. }
  565. return hr;
  566. }
  567. /*
  568. * CSysmonPropPage::IsPageDirty
  569. *
  570. * Purpose:
  571. * Asks the page if anything's changed in it, that is, if the
  572. * property values in the page are out of sync with the objects
  573. * under consideration.
  574. *
  575. * Parameters:
  576. * None
  577. *
  578. * Return Value:
  579. * HRESULT NOERROR if dirty, S_FALSE if not.
  580. */
  581. STDMETHODIMP CSysmonPropPage::IsPageDirty(void)
  582. {
  583. return (m_fDirty ? S_OK : S_FALSE);
  584. }
  585. /*
  586. * CSysmonPropPage::Apply
  587. *
  588. * Purpose:
  589. * Instructs the page to send changes in its page to whatever
  590. * objects it knows about through SetObjects. This is the only
  591. * time the page should change the objects' properties, and not
  592. * when the value is changed on the page.
  593. *
  594. * Parameters:
  595. * None
  596. */
  597. STDMETHODIMP CSysmonPropPage::Apply(void)
  598. {
  599. HRESULT hr = NOERROR;
  600. if ( 0 != m_cObjects ) {
  601. // Kill the focus in case a text field has it. This will trigger
  602. // the entry processing code.
  603. SetFocus(NULL);
  604. {
  605. CWaitCursor cursorWait;
  606. if (SetProperties()) {
  607. m_fDirty = FALSE;
  608. } else {
  609. hr = E_FAIL;
  610. }
  611. }
  612. }
  613. return hr;
  614. }
  615. /*
  616. * CSysmonPropPage::Help
  617. *
  618. * Purpose:
  619. * Invokes help for this property page when the user presses
  620. * the Help button. If you return NULLs for the help file
  621. * in GetPageInfo, the button will be grayed. Otherwise the
  622. * page can perform its own help here.
  623. *
  624. * Parameters:
  625. * pszHelpDir LPCOLESTR identifying the default location of
  626. * the help information
  627. *
  628. * Return Value:
  629. * HRESULT NOERROR to tell the frame that we've done our
  630. * own help. Returning an error code or S_FALSE
  631. * causes the frame to use any help information
  632. * in PROPPAGEINFO.
  633. */
  634. STDMETHODIMP CSysmonPropPage::Help(LPCOLESTR /* pszHelpDir */ )
  635. {
  636. /*
  637. * We can either provide help ourselves, or rely on the
  638. * information in PROPPAGEINFO.
  639. */
  640. return (S_FALSE);
  641. }
  642. /*
  643. * CSysmonPropPage::TranslateAccelerator
  644. *
  645. * Purpose:
  646. * Provides the page with the messages that occur in the frame.
  647. * This gives the page to do whatever it wants with the message,
  648. * such as handle keyboard mnemonics.
  649. *
  650. * Parameters:
  651. * pMsg LPMSG containing the keyboard message.
  652. */
  653. STDMETHODIMP CSysmonPropPage::TranslateAccelerator(LPMSG lpMsg)
  654. {
  655. BOOL fTakeIt = TRUE;
  656. BOOL fHandled = FALSE;
  657. HRESULT hr;
  658. HWND hwnd;
  659. if (lpMsg == NULL)
  660. return E_POINTER;
  661. // If TAB key
  662. if (lpMsg->message == WM_KEYDOWN ) {
  663. if ( lpMsg->wParam == VK_TAB
  664. && GetKeyState(VK_CONTROL) >= 0) {
  665. UINT uDir = GetKeyState(VK_SHIFT) >= 0 ? GW_HWNDNEXT : GW_HWNDPREV;
  666. hwnd = GetFocus();
  667. if (IsChild(m_hDlg, hwnd)) {
  668. // Get top level child for controls with children, like combo.
  669. while (GetParent(hwnd) != m_hDlg) hwnd = GetParent(hwnd);
  670. // If this control is the last enabled tab stop, don't steal the TAB key
  671. do {
  672. hwnd = GetWindow(hwnd, uDir);
  673. if ( NULL == hwnd ) {
  674. fTakeIt = FALSE;
  675. break;
  676. }
  677. }
  678. while ((GetWindowLong(hwnd, GWL_STYLE) & (WS_DISABLED | WS_TABSTOP)) != WS_TABSTOP);
  679. }
  680. }
  681. /*
  682. fTakeIt is already TRUE.
  683. // else if Arrow key
  684. else if ( lpMsg->message == WM_KEYDOWN &&
  685. ( lpMsg->wParam == VK_LEFT || lpMsg->wParam == VK_UP
  686. || lpMsg->wParam == VK_RIGHT || lpMsg->wParam == VK_DOWN ) ) {
  687. fTakeIt = TRUE;
  688. }
  689. */
  690. // else if Return or Escape key
  691. else if ( lpMsg->wParam == VK_RETURN || lpMsg->wParam == VK_ESCAPE ) {
  692. fTakeIt = (lpMsg->wParam == VK_RETURN);
  693. if ( fTakeIt ) {
  694. hwnd = GetFocus();
  695. if ( NULL == hwnd ) {
  696. fTakeIt = FALSE;
  697. } else {
  698. fTakeIt = IsChild(m_hDlg, hwnd);
  699. if ( fTakeIt ) {
  700. fTakeIt = (BOOL) SendMessage(hwnd, WM_GETDLGCODE, 0, 0) & DLGC_DEFPUSHBUTTON;
  701. }
  702. }
  703. }
  704. }
  705. } else if ( ( WM_KEYUP == lpMsg->message ) ) {
  706. fTakeIt = FALSE;
  707. }
  708. // if we should process the key
  709. if (fTakeIt) {
  710. // if the target is not one of our controls, change it so IsDialogMessage works
  711. if (!IsChild(m_hDlg, lpMsg->hwnd)) {
  712. hwnd = lpMsg->hwnd;
  713. lpMsg->hwnd = GetWindow(m_hDlg, GW_CHILD);
  714. fHandled = IsDialogMessage(m_hDlg, lpMsg);
  715. lpMsg->hwnd = hwnd;
  716. }
  717. else {
  718. fHandled = IsDialogMessage(m_hDlg, lpMsg);
  719. }
  720. }
  721. if (fHandled){
  722. return S_OK;
  723. } else{
  724. hr = m_pIPropertyPageSite->TranslateAccelerator(lpMsg);
  725. }
  726. return hr;
  727. }
  728. /*
  729. * CSysmonPropPage::EditProperty
  730. *
  731. * Purpose:
  732. * Sets focus to the control corresponding to the supplied DISPID.
  733. *
  734. * Parameters:
  735. * dispID DISPID of the property
  736. */
  737. STDMETHODIMP CSysmonPropPage::EditProperty(DISPID dispID)
  738. {
  739. HRESULT hr;
  740. hr = EditPropertyImpl ( dispID );
  741. if ( SUCCEEDED(hr)) {
  742. SetFocus ( GetDlgItem ( m_hDlg, m_dwEditControl ) );
  743. m_dwEditControl = 0;
  744. }
  745. return hr;
  746. }
  747. /*
  748. * CSysmonPropPage::WndProc
  749. *
  750. * Purpose:
  751. * This is a default message processor that can be overriden by
  752. * a subclass to provide special message handling.
  753. *
  754. * Parameters:
  755. * pMsg LPMSG containing the keyboard message.
  756. */
  757. BOOL
  758. CSysmonPropPage::WndProc (
  759. UINT, // uMsg,
  760. WPARAM, // wParam,
  761. LPARAM // lParam
  762. )
  763. {
  764. return FALSE;
  765. }
  766. /*
  767. * SysmonPropPageProc
  768. *
  769. * Purpose:
  770. * Dialog procedure for the Sysmon Property Page.
  771. */
  772. INT_PTR APIENTRY CALLBACK
  773. SysmonPropPageProc(
  774. HWND hDlg,
  775. UINT iMsg,
  776. WPARAM wParam,
  777. LPARAM lParam
  778. )
  779. {
  780. static WCHAR szObj[] = L"Object";
  781. PCSysmonPropPage pObj = NULL;
  782. PMEASUREITEMSTRUCT pMI;
  783. HWND hwndTabCtrl;
  784. HWND hwndPropSheet;
  785. INT iCtrlID;
  786. WCHAR pszHelpFilePath[MAX_PATH * 2];
  787. LPHELPINFO pInfo;
  788. UINT nLen;
  789. BOOL bReturn = FALSE;
  790. if ( NULL != hDlg ) {
  791. pObj = (PCSysmonPropPage)GetProp(hDlg, szObj);
  792. }
  793. switch (iMsg) {
  794. case WM_INITDIALOG:
  795. pObj=(PCSysmonPropPage)lParam;
  796. if ( NULL != pObj && NULL != hDlg ) {
  797. SetProp(hDlg, szObj, (HANDLE)lParam);
  798. hwndTabCtrl = ::GetParent(hDlg);
  799. hwndPropSheet = ::GetParent(hwndTabCtrl);
  800. SetWindowLongPtr(hwndPropSheet,
  801. GWL_EXSTYLE,
  802. GetWindowLongPtr(hwndPropSheet,GWL_EXSTYLE)|WS_EX_CONTEXTHELP);
  803. }
  804. bReturn = TRUE;
  805. break;
  806. case WM_DESTROY:
  807. if ( NULL != hDlg ) {
  808. RemoveProp(hDlg, szObj);
  809. }
  810. bReturn = TRUE;
  811. break;
  812. case WM_MEASUREITEM:
  813. pMI = (PMEASUREITEMSTRUCT)lParam;
  814. if ( NULL != pMI ) {
  815. pMI->itemWidth = 0 ;
  816. pMI->itemHeight = 16;
  817. }
  818. bReturn = TRUE;
  819. break;
  820. case WM_DRAWITEM:
  821. if ( NULL != pObj ) {
  822. pObj->DrawItem ((PDRAWITEMSTRUCT) lParam) ;
  823. }
  824. bReturn = TRUE;
  825. break;
  826. case WM_COMMAND:
  827. if ( NULL != pObj ) {
  828. pObj->DialogItemChange(LOWORD(wParam), HIWORD(wParam));
  829. }
  830. bReturn = FALSE;
  831. break;
  832. case WM_SETPAGEFOCUS:
  833. if ( NULL != hDlg ) {
  834. SetFocus(hDlg);
  835. bReturn = TRUE;
  836. }
  837. break;
  838. case WM_CONTEXTMENU:
  839. if ( NULL != (HWND) wParam ) {
  840. iCtrlID = GetDlgCtrlID ( (HWND) wParam );
  841. if ( 0 != iCtrlID ) {
  842. nLen = ::GetWindowsDirectory(pszHelpFilePath, 2*MAX_PATH);
  843. if ( 0 < nLen ) {
  844. StringCchCat(pszHelpFilePath, 2* MAX_PATH, L"\\help\\sysmon.hlp" );
  845. bReturn = WinHelp(
  846. (HWND) wParam,
  847. pszHelpFilePath,
  848. HELP_CONTEXTMENU,
  849. (DWORD_PTR) aulControlIdToHelpIdMap);
  850. }
  851. }
  852. }
  853. // bReturn is FALSE by default
  854. break;
  855. case WM_HELP:
  856. if ( NULL != hDlg ) {
  857. pInfo = (LPHELPINFO)lParam;
  858. if ( NULL != pInfo ) {
  859. // Only display help for known context IDs.
  860. if ( 0 != pInfo->dwContextId ) {
  861. nLen = ::GetWindowsDirectory(pszHelpFilePath, 2*MAX_PATH);
  862. if ( 0 < nLen ) {
  863. StringCchCat(pszHelpFilePath, 2* MAX_PATH, L"\\help\\sysmon.hlp" );
  864. bReturn = WinHelp (
  865. hDlg,
  866. pszHelpFilePath,
  867. HELP_CONTEXTPOPUP,
  868. pInfo->dwContextId );
  869. }
  870. }
  871. }
  872. }
  873. // bReturn is FALSE by default
  874. break;
  875. default:
  876. if ( NULL != pObj ) {
  877. bReturn = pObj->WndProc(iMsg, wParam, lParam);
  878. }
  879. }
  880. return bReturn;
  881. }