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.

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