1 | //////////////////////////////////////////////////////////// |
---|
2 | // Copyright (C) Roman Ryltsov, 2008-2015 |
---|
3 | // Created by Roman Ryltsov roman@alax.info, http://alax.info |
---|
4 | // |
---|
5 | // This source code is published to complement DirectShowSpy developer powertoy |
---|
6 | // and demonstrate the internal use of APIs and tricks powering the tool. It is |
---|
7 | // allowed to freely re-use the portions of the code in other projects, commercial |
---|
8 | // or otherwise (provided that you dont pretend that you wrote the original tool). |
---|
9 | // |
---|
10 | // Please keep in mind that DirectShowSpy is a developer tool, it is strongly recommended |
---|
11 | // that it is not shipped with release grade software. It is allowed to distribute |
---|
12 | // DirectShowSpy if only it is not registered with Windows by default and either |
---|
13 | // used privately, or registered on specific throubleshooting request. The advice applies |
---|
14 | // to hooking methods used by DirectShowSpy in general as well. |
---|
15 | |
---|
16 | #pragma once |
---|
17 | |
---|
18 | #include <psapi.h> |
---|
19 | #include <atlctrlx.h> |
---|
20 | #include <atlsplit.h> |
---|
21 | #include "rofiles.h" |
---|
22 | #include "FilterGraphSpy.h" |
---|
23 | #include "FilterGraphHelper.h" |
---|
24 | #include "AboutDialog.h" |
---|
25 | |
---|
26 | #pragma comment(lib, "psapi.lib") |
---|
27 | |
---|
28 | //////////////////////////////////////////////////////////// |
---|
29 | // CFilterGraphListPropertySheet |
---|
30 | |
---|
31 | //INT_PTR DoFilterGraphListPropertySheetModal(HWND hParentWindow = GetActiveWindow(), COptions* pOptions = NULL); |
---|
32 | INT_PTR DoFilterGraphListPropertySheetModal(HWND hParentWindow, COptions* pOptions); |
---|
33 | |
---|
34 | class CFilterGraphListPropertySheet : |
---|
35 | public CSizablePropertySheetT<CFilterGraphListPropertySheet>, |
---|
36 | public CPropertySheetWithAcceleratorsT<CFilterGraphListPropertySheet> |
---|
37 | { |
---|
38 | public: |
---|
39 | |
---|
40 | BEGIN_MSG_MAP_EX(CFilterGraphListPropertySheet) |
---|
41 | CHAIN_MSG_MAP(CSizablePropertySheet) |
---|
42 | MSG_WM_SYSCOMMAND(OnSysCommand) |
---|
43 | END_MSG_MAP() |
---|
44 | |
---|
45 | public: |
---|
46 | |
---|
47 | //////////////////////////////////////////////////////// |
---|
48 | // CListPropertyPage |
---|
49 | |
---|
50 | class CListPropertyPage : |
---|
51 | public CPropertyPageT<CListPropertyPage>, |
---|
52 | public CDialogResize<CListPropertyPage>, |
---|
53 | public CPropertyPageWithAcceleratorsT<CListPropertyPage> |
---|
54 | { |
---|
55 | public: |
---|
56 | |
---|
57 | enum { IDD = IDD_FILTERGRAPHLIST_LIST_PROPERTYPAGE }; |
---|
58 | |
---|
59 | BEGIN_MSG_MAP_EX(CListPropertyPage) |
---|
60 | CHAIN_MSG_MAP(CPropertyPage) |
---|
61 | CHAIN_MSG_MAP(CDialogResize<CListPropertyPage>) |
---|
62 | CHAIN_MSG_MAP(CPropertyPageWithAccelerators) |
---|
63 | MSG_WM_INITDIALOG(OnInitDialog) |
---|
64 | MSG_WM_DESTROY(OnDestroy) |
---|
65 | MSG_LVN_GETDISPINFO(IDC_FILTERGRAPHLIST_LIST_GRAPH, OnGraphListViewGetDispInfo) |
---|
66 | MSG_LVN_GETINFOTIP(IDC_FILTERGRAPHLIST_LIST_GRAPH, OnGraphListViewGetInfoTip) |
---|
67 | MSG_LVN_ITEMCHANGED(IDC_FILTERGRAPHLIST_LIST_GRAPH, OnGraphListViewItemChanged) |
---|
68 | MSG_LVN_DBLCLK(IDC_FILTERGRAPHLIST_LIST_GRAPH, OnGraphListViewDblClk) |
---|
69 | MSG_WM_CONTEXTMENU(OnContextMenu) |
---|
70 | COMMAND_ID_HANDLER_EX(IDC_FILTERGRAPHLIST_LIST_REFRESH, OnRefresh) |
---|
71 | COMMAND_ID_HANDLER_EX(IDC_FILTERGRAPHLIST_LIST_CHECK, OnCheck) |
---|
72 | COMMAND_ID_HANDLER_EX(IDC_FILTERGRAPHLIST_LIST_CHECKALL, OnCheckAll) |
---|
73 | COMMAND_ID_HANDLER_EX(IDC_FILTERGRAPHLIST_LIST_COPYTOCLIPBOARD, OnCopyToClipboard) |
---|
74 | COMMAND_ID_HANDLER_EX(IDC_FILTERGRAPHLIST_LIST_PROPERTIES, OnProperties) |
---|
75 | COMMAND_ID_HANDLER_EX(IDC_FILTERGRAPHLIST_LIST_OPENGSN, OnOpenGsn) |
---|
76 | COMMAND_ID_HANDLER_EX(IDC_FILTERGRAPHLIST_LIST_OPENGE, OnOpenGe) |
---|
77 | REFLECT_NOTIFICATIONS() |
---|
78 | END_MSG_MAP() |
---|
79 | |
---|
80 | BEGIN_DLGRESIZE_MAP(CListPropertyPage) |
---|
81 | DLGRESIZE_CONTROL(IDC_FILTERGRAPHLIST_LIST_GRAPH, DLSZ_SIZE_X | DLSZ_SIZE_Y) |
---|
82 | DLGRESIZE_CONTROL(IDC_FILTERGRAPHLIST_LIST_REFRESH, DLSZ_MOVE_Y) |
---|
83 | DLGRESIZE_CONTROL(IDC_FILTERGRAPHLIST_LIST_CHECK, DLSZ_MOVE_Y) |
---|
84 | DLGRESIZE_CONTROL(IDC_FILTERGRAPHLIST_LIST_COPYTOCLIPBOARD, DLSZ_MOVE_Y) |
---|
85 | DLGRESIZE_CONTROL(IDC_FILTERGRAPHLIST_LIST_PROPERTIES, DLSZ_MOVE_Y) |
---|
86 | END_DLGRESIZE_MAP() |
---|
87 | |
---|
88 | public: |
---|
89 | |
---|
90 | //////////////////////////////////////////////////// |
---|
91 | // CItem |
---|
92 | |
---|
93 | class CItem |
---|
94 | { |
---|
95 | public: |
---|
96 | CComPtr<IMoniker> m_pMoniker; |
---|
97 | CStringW m_sDisplayName; |
---|
98 | DWORD64 m_nInstance; |
---|
99 | DWORD m_nProcessIdentifier; |
---|
100 | CPath m_sProcessImagePath; |
---|
101 | CString m_sTime; |
---|
102 | CComPtr<IUnknown> m_pFilterGraphUnknown; |
---|
103 | CComPtr<IFilterGraph> m_pFilterGraph; |
---|
104 | CStringW m_sFriendlyName; |
---|
105 | SIZE_T m_nFilterCount; |
---|
106 | CString m_sState; |
---|
107 | DOUBLE m_fDuration; |
---|
108 | DOUBLE m_fPosition; |
---|
109 | |
---|
110 | public: |
---|
111 | // CItem |
---|
112 | CItem() throw() : |
---|
113 | m_nFilterCount(0), |
---|
114 | m_fDuration(0), |
---|
115 | m_fPosition(0) |
---|
116 | { |
---|
117 | } |
---|
118 | CComPtr<IFilterGraph>& FilterGraphNeeded(IRunningObjectTable* pRunningObjectTable) |
---|
119 | { |
---|
120 | _A(pRunningObjectTable); |
---|
121 | if(!m_pFilterGraph && pRunningObjectTable && m_pMoniker) |
---|
122 | { |
---|
123 | _A(m_pMoniker); |
---|
124 | CComPtr<IBindCtx> pBindCtx; |
---|
125 | __C(CreateBindCtx(0, &pBindCtx)); |
---|
126 | CComPtr<IUnknown> pUnknown; |
---|
127 | __C(pRunningObjectTable->GetObject(m_pMoniker, &pUnknown)); |
---|
128 | const CComQIPtr<IFilterGraph> pFilterGraph = pUnknown; |
---|
129 | __D(pFilterGraph, E_NOINTERFACE); |
---|
130 | m_pFilterGraphUnknown = pUnknown; |
---|
131 | m_pFilterGraph = pFilterGraph; |
---|
132 | _ATLTRY |
---|
133 | { |
---|
134 | const CComQIPtr<ISpy> pSpy = pFilterGraph; |
---|
135 | if(pSpy) |
---|
136 | { |
---|
137 | CComBSTR sFriendlyName; |
---|
138 | __C(pSpy->get_FriendlyName(&sFriendlyName)); |
---|
139 | m_sFriendlyName = sFriendlyName; |
---|
140 | } |
---|
141 | } |
---|
142 | _ATLCATCHALL() |
---|
143 | { |
---|
144 | _Z_EXCEPTION(); |
---|
145 | } |
---|
146 | m_nFilterCount = 0; |
---|
147 | m_sState.Empty(); |
---|
148 | } |
---|
149 | return m_pFilterGraph; |
---|
150 | } |
---|
151 | CFilterGraphHelper::CProcessData GetProcessData() const |
---|
152 | { |
---|
153 | CFilterGraphHelper::CProcessData ProcessData; |
---|
154 | ProcessData.m_sDisplayName = m_sDisplayName; |
---|
155 | ProcessData.m_nIdentifier = m_nProcessIdentifier; |
---|
156 | ProcessData.m_sImagePath = m_sProcessImagePath; |
---|
157 | return ProcessData; |
---|
158 | } |
---|
159 | BOOL Check() |
---|
160 | { |
---|
161 | _ATLTRY |
---|
162 | { |
---|
163 | _FilterGraphHelper::CFilterArray FilterArray; |
---|
164 | _FilterGraphHelper::GetGraphFilters(m_pFilterGraph, FilterArray); |
---|
165 | m_nFilterCount = FilterArray.GetCount(); |
---|
166 | #pragma region IMediaControl |
---|
167 | _ATLTRY |
---|
168 | { |
---|
169 | m_sState.Empty(); |
---|
170 | const CComQIPtr<IMediaControl> pMediaControl = m_pFilterGraph; |
---|
171 | if(pMediaControl) |
---|
172 | { |
---|
173 | OAFilterState State; |
---|
174 | if(SUCCEEDED(pMediaControl->GetState(0, &State))) |
---|
175 | { |
---|
176 | static LPCTSTR g_ppszStates[] = { _T("Stopped"), _T("Paused"), _T("Running") }; |
---|
177 | if((SIZE_T) State < DIM(g_ppszStates)) |
---|
178 | m_sState = g_ppszStates[(SIZE_T) State]; |
---|
179 | } |
---|
180 | } |
---|
181 | } |
---|
182 | _ATLCATCHALL() |
---|
183 | { |
---|
184 | _Z_EXCEPTION(); |
---|
185 | } |
---|
186 | #pragma endregion |
---|
187 | #pragma region IMediaPosition |
---|
188 | _ATLTRY |
---|
189 | { |
---|
190 | m_fDuration = 0; |
---|
191 | m_fPosition = 0; |
---|
192 | const CComQIPtr<IMediaPosition> pMediaPosition = m_pFilterGraph; |
---|
193 | if(pMediaPosition) |
---|
194 | if(SUCCEEDED(pMediaPosition->get_Duration(&m_fDuration))) |
---|
195 | pMediaPosition->get_CurrentPosition(&m_fPosition); |
---|
196 | } |
---|
197 | _ATLCATCHALL() |
---|
198 | { |
---|
199 | _Z_EXCEPTION(); |
---|
200 | } |
---|
201 | #pragma endregion |
---|
202 | // SUGG: Source and Sink Paths |
---|
203 | } |
---|
204 | _ATLCATCHALL() |
---|
205 | { |
---|
206 | _Z_EXCEPTION(); |
---|
207 | return FALSE; |
---|
208 | } |
---|
209 | return TRUE; |
---|
210 | } |
---|
211 | }; |
---|
212 | |
---|
213 | private: |
---|
214 | CFilterGraphListPropertySheet& m_PropertySheet; |
---|
215 | CRoListViewT<CItem, CRoListControlDataTraitsT> m_GraphListView; |
---|
216 | CButton m_RefreshButton; |
---|
217 | CButton m_CheckButton; |
---|
218 | CButton m_CopyToClipboardButton; |
---|
219 | CButton m_PropertiesButton; |
---|
220 | CComPtr<IRunningObjectTable> m_pRunningObjectTable; |
---|
221 | |
---|
222 | public: |
---|
223 | // CListPropertyPage |
---|
224 | CListPropertyPage(CFilterGraphListPropertySheet* pPropertySheet) throw() : |
---|
225 | m_PropertySheet(*pPropertySheet) |
---|
226 | { |
---|
227 | } |
---|
228 | VOID UpdateControls() |
---|
229 | { |
---|
230 | const UINT nSelectedCount = m_GraphListView.GetSelectedCount(); |
---|
231 | m_CheckButton.EnableWindow(nSelectedCount > 0); |
---|
232 | m_CopyToClipboardButton.EnableWindow(nSelectedCount > 0); |
---|
233 | m_PropertiesButton.EnableWindow(nSelectedCount == 1); |
---|
234 | } |
---|
235 | INT SortGraphListViewItems(LPARAM nItemParameter1, LPARAM nItemParameter2) |
---|
236 | { |
---|
237 | const CItem& Item1 = m_GraphListView.DataFromParameter(nItemParameter1); |
---|
238 | const CItem& Item2 = m_GraphListView.DataFromParameter(nItemParameter2); |
---|
239 | const INT nTime = _tcscmp(Item1.m_sTime, Item2.m_sTime); |
---|
240 | if(nTime) |
---|
241 | return -nTime; |
---|
242 | const INT nProcess = (INT) (Item1.m_nProcessIdentifier, Item2.m_nProcessIdentifier); |
---|
243 | if(nProcess) |
---|
244 | return -nProcess; |
---|
245 | return wcscmp(Item1.m_sDisplayName, Item2.m_sDisplayName); |
---|
246 | } |
---|
247 | static int CALLBACK SortGraphListViewItems(LPARAM nItemParameter1, LPARAM nItemParameter2, LPARAM nParameter) |
---|
248 | { |
---|
249 | return ((CListPropertyPage*) nParameter)->SortGraphListViewItems(nItemParameter1, nItemParameter2); |
---|
250 | } |
---|
251 | static VOID EnumerateItems(IRunningObjectTable* pRunningObjectTable, CRoMapT<CStringW, CItem>& ItemMap, const LONG* pnProcessIdentifier = NULL) |
---|
252 | { |
---|
253 | _A(pRunningObjectTable); |
---|
254 | _A(ItemMap.IsEmpty()); |
---|
255 | _ATLTRY |
---|
256 | { |
---|
257 | CComPtr<IEnumMoniker> pEnumMoniker; |
---|
258 | __C(pRunningObjectTable->EnumRunning(&pEnumMoniker)); |
---|
259 | CComPtr<IMalloc> pMalloc; |
---|
260 | __C(CoGetMalloc(1, &pMalloc)); |
---|
261 | for(; ; ) |
---|
262 | { |
---|
263 | CComPtr<IMoniker> pMoniker; |
---|
264 | if(pEnumMoniker->Next(1, &pMoniker, NULL) != S_OK) |
---|
265 | break; |
---|
266 | _ATLTRY |
---|
267 | { |
---|
268 | CComPtr<IBindCtx> pBindCtx; |
---|
269 | __C(CreateBindCtx(0, &pBindCtx)); |
---|
270 | LPOLESTR pszDisplayName = NULL; |
---|
271 | __C(pMoniker->GetDisplayName(pBindCtx, NULL, &pszDisplayName)); |
---|
272 | const CStringW sDisplayName = pszDisplayName; |
---|
273 | _Z4(atlTraceGeneral, 4, _T("sDisplayName %ls\n"), sDisplayName); |
---|
274 | pMalloc->Free(pszDisplayName); |
---|
275 | static CRoStaticReW g_Expression(L"^\\!FilterGraph {[0-9A-F]+} pid {[0-9A-F]+}(; process\\: {.+?}, time\\: {[0-9]+\\-[0-9]+\\-[0-9]+})?", FALSE); |
---|
276 | CRoReMatchContext MatchContext; |
---|
277 | if(g_Expression.Match(sDisplayName, &MatchContext)) |
---|
278 | { |
---|
279 | CItem Item; |
---|
280 | Item.m_pMoniker = pMoniker; |
---|
281 | Item.m_sDisplayName = sDisplayName; |
---|
282 | _W(StrToInt64ExW(CStringW(L"0x") + MatchContext.GetMatchString(0), STIF_SUPPORT_HEX, &reinterpret_cast<LONGLONG&>(Item.m_nInstance))); |
---|
283 | _W(StrToIntExW(CStringW(L"0x") + MatchContext.GetMatchString(1), STIF_SUPPORT_HEX, &reinterpret_cast<INT&>(Item.m_nProcessIdentifier))); |
---|
284 | Item.m_sTime = CString(MatchContext.GetMatchString(3)); |
---|
285 | Item.m_sTime.Replace(_T("-"), _T(":")); |
---|
286 | if(pnProcessIdentifier && Item.m_nProcessIdentifier != (DWORD) *pnProcessIdentifier) |
---|
287 | continue; // Skip |
---|
288 | _W(ItemMap.SetAt(sDisplayName, Item) >= 0); |
---|
289 | } |
---|
290 | } |
---|
291 | _ATLCATCHALL() |
---|
292 | { |
---|
293 | _Z_EXCEPTION(); |
---|
294 | } |
---|
295 | } |
---|
296 | } |
---|
297 | _ATLCATCHALL() |
---|
298 | { |
---|
299 | _Z_EXCEPTION(); |
---|
300 | } |
---|
301 | } |
---|
302 | VOID Refresh() |
---|
303 | { |
---|
304 | if(!m_pRunningObjectTable) |
---|
305 | __C(GetRunningObjectTable(0, &m_pRunningObjectTable)); |
---|
306 | LONG nProcessIdentifier; |
---|
307 | const BOOL bProcessIdentifierAvailable = m_PropertySheet.m_Options.TryGetLongValue(_T("FilterGraphListPropertySheet.ProcessIdentifier"), nProcessIdentifier); |
---|
308 | CRoMapT<CStringW, CItem> ItemMap; |
---|
309 | EnumerateItems(m_pRunningObjectTable, ItemMap, bProcessIdentifierAvailable ? &nProcessIdentifier : NULL); |
---|
310 | CWindowRedraw GraphListViewRedraw(m_GraphListView); |
---|
311 | BOOL bSortNeeded = FALSE; |
---|
312 | #pragma region Remove |
---|
313 | for(INT nItem = m_GraphListView.GetItemCount() - 1; nItem >= 0; nItem--) |
---|
314 | { |
---|
315 | const POSITION Position = ItemMap.Lookup(m_GraphListView.GetItemData(nItem).m_sDisplayName); |
---|
316 | if(Position) |
---|
317 | ItemMap.RemoveAtPos(Position); |
---|
318 | else |
---|
319 | _W(m_GraphListView.DeleteItem(nItem)); |
---|
320 | } |
---|
321 | #pragma endregion |
---|
322 | #pragma region Add |
---|
323 | INT nItemIndex = m_GraphListView.GetItemCount(); |
---|
324 | for(POSITION Position = ItemMap.GetStartPosition(); Position; ItemMap.GetNext(Position)) |
---|
325 | { |
---|
326 | CItem& Item = ItemMap.GetValueAt(Position); |
---|
327 | _ATLTRY |
---|
328 | { |
---|
329 | CHandle Process; |
---|
330 | //Process.Attach(OpenProcess(PROCESS_QUERY_INFORMATION, FALSE, Item.m_nProcessIdentifier)); |
---|
331 | Process.Attach(OpenProcess(PROCESS_QUERY_INFORMATION | PROCESS_VM_READ, FALSE, Item.m_nProcessIdentifier)); |
---|
332 | __E(Process); |
---|
333 | TCHAR pszPath[MAX_PATH] = { 0 }; |
---|
334 | //_W(GetProcessImageFileName(Process, pszPath, DIM(pszPath))); |
---|
335 | _W(GetModuleFileNameEx(Process, NULL, pszPath, DIM(pszPath))); |
---|
336 | Item.m_sProcessImagePath = pszPath; |
---|
337 | } |
---|
338 | _ATLCATCHALL() |
---|
339 | { |
---|
340 | _Z_EXCEPTION(); |
---|
341 | } |
---|
342 | const INT nItem = m_GraphListView.InsertItem(nItemIndex++, Item); |
---|
343 | _A(nItem >= 0); |
---|
344 | bSortNeeded = TRUE; |
---|
345 | } |
---|
346 | #pragma endregion |
---|
347 | if(bSortNeeded) |
---|
348 | m_GraphListView.SortItems(&CListPropertyPage::SortGraphListViewItems, (LPARAM) this); |
---|
349 | } |
---|
350 | CString GetText() |
---|
351 | { |
---|
352 | CRoArrayT<CString> GraphArray; |
---|
353 | for(INT nItem = m_GraphListView.GetNextItem(-1, LVNI_SELECTED); nItem >= 0; nItem = m_GraphListView.GetNextItem(nItem, LVNI_SELECTED)) |
---|
354 | { |
---|
355 | CItem& Item = m_GraphListView.GetItemData(nItem); |
---|
356 | _ATLTRY |
---|
357 | { |
---|
358 | if(Item.FilterGraphNeeded(m_pRunningObjectTable)) |
---|
359 | { |
---|
360 | Item.Check(); |
---|
361 | m_GraphListView.RedrawItems(nItem, nItem); |
---|
362 | GraphArray.Add(CFilterGraphHelper::GetText(Item.m_pFilterGraph, &Item.GetProcessData())); |
---|
363 | } |
---|
364 | } |
---|
365 | _ATLCATCHALL() |
---|
366 | { |
---|
367 | _Z_EXCEPTION(); |
---|
368 | } |
---|
369 | } |
---|
370 | return _StringHelper::Join(GraphArray, _T("\r\n") _T("---") _T("\r\n") _T("\r\n")); |
---|
371 | } |
---|
372 | |
---|
373 | // Window Message Handler |
---|
374 | LRESULT OnInitDialog(HWND, LPARAM) |
---|
375 | { |
---|
376 | _ATLTRY |
---|
377 | { |
---|
378 | CWaitCursor WaitCursor; |
---|
379 | m_GraphListView.Initialize(GetDlgItem(IDC_FILTERGRAPHLIST_LIST_GRAPH)); |
---|
380 | CToolTipCtrl ToolTip = m_GraphListView.GetToolTips(); |
---|
381 | ToolTip.SetDelayTime(TTDT_AUTOPOP, 30 * 1000); // 30 seconds |
---|
382 | ToolTip.SetMaxTipWidth(max(GetSystemMetrics(SM_CXSCREEN) * 5 / 8, 600)); |
---|
383 | m_RefreshButton = GetDlgItem(IDC_FILTERGRAPHLIST_LIST_REFRESH); |
---|
384 | m_CheckButton = GetDlgItem(IDC_FILTERGRAPHLIST_LIST_CHECK); |
---|
385 | m_CopyToClipboardButton = GetDlgItem(IDC_FILTERGRAPHLIST_LIST_COPYTOCLIPBOARD); |
---|
386 | m_PropertiesButton = GetDlgItem(IDC_FILTERGRAPHLIST_LIST_PROPERTIES); |
---|
387 | DlgResize_Init(FALSE, FALSE); |
---|
388 | Refresh(); |
---|
389 | #if _DEVELOPMENT |
---|
390 | m_GraphListView.SetItemState(0, LVIS_FOCUSED | LVIS_SELECTED, LVIS_FOCUSED | LVIS_SELECTED); |
---|
391 | #endif // _DEVELOPMENT |
---|
392 | UpdateControls(); |
---|
393 | #pragma region Default Property Sheet Size |
---|
394 | CRect Position; |
---|
395 | _W(m_PropertySheet.GetWindowRect(Position)); |
---|
396 | Position.InflateRect(6 * Position.Width() / 8, 1 * Position.Height() / 8); |
---|
397 | CSize ScreenExtent(GetSystemMetrics(SM_CXSCREEN), GetSystemMetrics(SM_CYSCREEN)); |
---|
398 | ScreenExtent.cx -= ScreenExtent.cx / 8; |
---|
399 | ScreenExtent.cy -= ScreenExtent.cy / 8; |
---|
400 | if(Position.Width() > ScreenExtent.cx) |
---|
401 | Position.right = Position.left + ScreenExtent.cx; |
---|
402 | if(Position.Height() > ScreenExtent.cy) |
---|
403 | Position.bottom = Position.top + ScreenExtent.cy; |
---|
404 | _W(m_PropertySheet.MoveWindow(Position)); |
---|
405 | _W(m_PropertySheet.CenterWindow()); |
---|
406 | #pragma endregion |
---|
407 | CancelToClose(); |
---|
408 | BOOL bAutomaticInitialCheck = FALSE; |
---|
409 | m_PropertySheet.m_Options.TryGetBoolValue(_T("FilterGraphListPropertySheet.AutomaticInitialCheck"), bAutomaticInitialCheck); |
---|
410 | if(bAutomaticInitialCheck) |
---|
411 | PostMessage(WM_COMMAND, MAKEWPARAM(IDC_FILTERGRAPHLIST_LIST_CHECKALL, BN_CLICKED)); |
---|
412 | } |
---|
413 | _ATLCATCHALL() |
---|
414 | { |
---|
415 | for(CWindow Window = GetWindow(GW_CHILD); Window.IsWindow(); Window = Window.GetWindow(GW_HWNDNEXT)) |
---|
416 | Window.EnableWindow(FALSE); |
---|
417 | _ATLRETHROW; |
---|
418 | } |
---|
419 | return TRUE; |
---|
420 | } |
---|
421 | LRESULT OnDestroy() |
---|
422 | { |
---|
423 | return 0; |
---|
424 | } |
---|
425 | LRESULT OnTranslateAccelerator(MSG* pMessage) |
---|
426 | { |
---|
427 | return TranslateAccelerator(m_hWnd, m_hAccelerators, pMessage) ? PSNRET_MESSAGEHANDLED : PSNRET_NOERROR; |
---|
428 | } |
---|
429 | LRESULT OnGraphListViewGetDispInfo(NMLVDISPINFO* pHeader) |
---|
430 | { |
---|
431 | const CItem& Item = m_GraphListView.DataFromParameter(pHeader->item.lParam); |
---|
432 | if(pHeader->item.mask & LVIF_TEXT) |
---|
433 | { |
---|
434 | CString& sTextBuffer = m_GraphListView.GetTextBufferString(TRUE); |
---|
435 | switch(pHeader->item.iSubItem) |
---|
436 | { |
---|
437 | case 1: // Process Name |
---|
438 | sTextBuffer = PathFindFileName(Item.m_sProcessImagePath); |
---|
439 | break; |
---|
440 | case 2: // Creation Time |
---|
441 | sTextBuffer = Item.m_sTime; |
---|
442 | break; |
---|
443 | case 3: // Friendly Name |
---|
444 | sTextBuffer = CString(Item.m_sFriendlyName); |
---|
445 | break; |
---|
446 | case 4: // Filter Count |
---|
447 | if(Item.m_pFilterGraph) |
---|
448 | sTextBuffer = AtlFormatString(_T("%d"), Item.m_nFilterCount); |
---|
449 | break; |
---|
450 | case 5: // State |
---|
451 | if(Item.m_pFilterGraph) |
---|
452 | sTextBuffer = Item.m_sState; |
---|
453 | break; |
---|
454 | case 6: // Process Image Directory |
---|
455 | sTextBuffer = (LPCTSTR) GetPathDirectory(Item.m_sProcessImagePath); |
---|
456 | break; |
---|
457 | default: // Process, Instance |
---|
458 | sTextBuffer = AtlFormatString(_T("%d - 0x%p"), Item.m_nProcessIdentifier, Item.m_nInstance); |
---|
459 | } |
---|
460 | pHeader->item.pszText = m_GraphListView.GetTextBuffer(); |
---|
461 | } |
---|
462 | return 0; |
---|
463 | } |
---|
464 | LRESULT OnGraphListViewGetInfoTip(NMLVGETINFOTIP* pHeader) |
---|
465 | { |
---|
466 | const CItem& Item = m_GraphListView.GetItemData(pHeader->iItem); |
---|
467 | CString& sTextBuffer = m_GraphListView.GetTextBufferString(TRUE); |
---|
468 | sTextBuffer.AppendFormat(_T("Process: %d (0x%X) %s\r\n"), Item.m_nProcessIdentifier, Item.m_nProcessIdentifier, CString(FindFileName(Item.m_sProcessImagePath))); |
---|
469 | if(!Item.m_sTime.IsEmpty()) |
---|
470 | sTextBuffer.AppendFormat(_T("Creation Time: %s\r\n"), Item.m_sTime); |
---|
471 | if(!Item.m_sFriendlyName.IsEmpty()) |
---|
472 | sTextBuffer.AppendFormat(_T("Friendly Name: %ls\r\n"), Item.m_sFriendlyName); |
---|
473 | if(Item.m_pFilterGraph) |
---|
474 | { |
---|
475 | sTextBuffer.AppendFormat(_T("Filter Count: %d\r\n"), Item.m_nFilterCount); |
---|
476 | if(!Item.m_sState.IsEmpty()) |
---|
477 | sTextBuffer.AppendFormat(_T("State: %s\r\n"), Item.m_sState); |
---|
478 | if(Item.m_fDuration > 0) |
---|
479 | { |
---|
480 | sTextBuffer.AppendFormat(_T("Duration: %s seconds\r\n"), _StringHelper::FormatNumber(Item.m_fDuration, 3)); |
---|
481 | sTextBuffer.AppendFormat(_T("Position: %s seconds\r\n"), _StringHelper::FormatNumber(Item.m_fPosition, 3)); |
---|
482 | } |
---|
483 | } |
---|
484 | sTextBuffer.AppendFormat(_T("Display Name: %ls\r\n"), Item.m_sDisplayName); |
---|
485 | sTextBuffer.AppendFormat(_T("Instance: 0x%p\r\n"), Item.m_nInstance); |
---|
486 | const CString sDirectory = (LPCTSTR) GetPathDirectory(Item.m_sProcessImagePath); |
---|
487 | if(!sDirectory.IsEmpty()) |
---|
488 | sTextBuffer.AppendFormat(_T("Process Directory: %s\r\n"), sDirectory); |
---|
489 | sTextBuffer.TrimRight(_T("\t\n\r .")); |
---|
490 | #pragma region Clipboard Copy |
---|
491 | if(GetKeyState(VK_CONTROL) < 0 && GetKeyState(VK_SHIFT) < 0) |
---|
492 | _ATLTRY |
---|
493 | { |
---|
494 | SetClipboardText(m_hWnd, sTextBuffer); |
---|
495 | MessageBeep(MB_OK); |
---|
496 | } |
---|
497 | _ATLCATCHALL() |
---|
498 | { |
---|
499 | _Z_EXCEPTION(); |
---|
500 | MessageBeep(MB_ICONERROR); |
---|
501 | } |
---|
502 | #pragma endregion |
---|
503 | _tcsncpy_s(pHeader->pszText, pHeader->cchTextMax, m_GraphListView.GetTextBuffer(), _TRUNCATE); |
---|
504 | return 0; |
---|
505 | } |
---|
506 | LRESULT OnGraphListViewItemChanged(NMLISTVIEW* pHeader) |
---|
507 | { |
---|
508 | UpdateControls(); |
---|
509 | return 0; |
---|
510 | } |
---|
511 | LRESULT OnGraphListViewDblClk(NMITEMACTIVATE* pHeader) |
---|
512 | { |
---|
513 | //m_CheckButton.Click(); |
---|
514 | m_PropertiesButton.Click(); |
---|
515 | return 0; |
---|
516 | } |
---|
517 | LRESULT OnContextMenu(CWindow Window, CPoint Position) |
---|
518 | { |
---|
519 | if(Window == m_GraphListView) |
---|
520 | { |
---|
521 | CMenu ContainerMenu = AtlLoadMenu(IDD); |
---|
522 | CMenuHandle Menu = ContainerMenu.GetSubMenu(0); |
---|
523 | const UINT nCount = m_GraphListView.GetItemCount(); |
---|
524 | const UINT nSelectedCount = m_GraphListView.GetSelectedCount(); |
---|
525 | Menu.EnableMenuItem(IDC_FILTERGRAPHLIST_LIST_CHECK, MF_BYCOMMAND | (m_CheckButton.IsWindowEnabled() ? MF_ENABLED : MF_GRAYED | MF_DISABLED)); |
---|
526 | Menu.EnableMenuItem(IDC_FILTERGRAPHLIST_LIST_CHECKALL, MF_BYCOMMAND | ((nCount > 0) ? MF_ENABLED : MF_GRAYED | MF_DISABLED)); |
---|
527 | Menu.EnableMenuItem(IDC_FILTERGRAPHLIST_LIST_COPYTOCLIPBOARD, MF_BYCOMMAND | (m_CopyToClipboardButton.IsWindowEnabled() ? MF_ENABLED : MF_GRAYED | MF_DISABLED)); |
---|
528 | Menu.EnableMenuItem(IDC_FILTERGRAPHLIST_LIST_OPENGSN, MF_BYCOMMAND | ((nSelectedCount == 1) ? MF_ENABLED : MF_GRAYED | MF_DISABLED)); |
---|
529 | Menu.EnableMenuItem(IDC_FILTERGRAPHLIST_LIST_OPENGE, MF_BYCOMMAND | ((nSelectedCount == 1) ? MF_ENABLED : MF_GRAYED | MF_DISABLED)); |
---|
530 | Menu.EnableMenuItem(IDC_FILTERGRAPHLIST_LIST_REFRESH, MF_BYCOMMAND | (m_RefreshButton.IsWindowEnabled() ? MF_ENABLED : MF_GRAYED | MF_DISABLED)); |
---|
531 | Menu.EnableMenuItem(IDC_FILTERGRAPHLIST_LIST_PROPERTIES, MF_BYCOMMAND | (m_PropertiesButton.IsWindowEnabled() ? MF_ENABLED : MF_GRAYED | MF_DISABLED)); |
---|
532 | Menu.SetMenuDefaultItem(IDC_FILTERGRAPHLIST_LIST_PROPERTIES); |
---|
533 | Menu.TrackPopupMenu(TPM_RIGHTBUTTON | TPM_LEFTALIGN | TPM_TOPALIGN, Position.x, Position.y, m_hWnd); |
---|
534 | } |
---|
535 | return 0; |
---|
536 | } |
---|
537 | LRESULT OnRefresh(UINT, INT, HWND) |
---|
538 | { |
---|
539 | CWaitCursor WaitCursor; |
---|
540 | Refresh(); |
---|
541 | UpdateControls(); |
---|
542 | return 0; |
---|
543 | } |
---|
544 | LRESULT OnCheck(UINT, INT, HWND) |
---|
545 | { |
---|
546 | CWaitCursor WaitCursor; |
---|
547 | for(INT nItem = m_GraphListView.GetNextItem(-1, LVNI_SELECTED); nItem >= 0; nItem = m_GraphListView.GetNextItem(nItem, LVNI_SELECTED)) |
---|
548 | { |
---|
549 | CItem& Item = m_GraphListView.GetItemData(nItem); |
---|
550 | if(Item.FilterGraphNeeded(m_pRunningObjectTable)) |
---|
551 | if(Item.Check()) |
---|
552 | m_GraphListView.RedrawItems(nItem, nItem); |
---|
553 | } |
---|
554 | return 0; |
---|
555 | } |
---|
556 | LRESULT OnCheckAll(UINT, INT, HWND) |
---|
557 | { |
---|
558 | CWaitCursor WaitCursor; |
---|
559 | for(INT nItem = m_GraphListView.GetItemCount() - 1; nItem >= 0; nItem--) |
---|
560 | { |
---|
561 | CItem& Item = m_GraphListView.GetItemData(nItem); |
---|
562 | if(Item.FilterGraphNeeded(m_pRunningObjectTable)) |
---|
563 | if(Item.Check()) |
---|
564 | m_GraphListView.RedrawItems(nItem, nItem); |
---|
565 | } |
---|
566 | return 0; |
---|
567 | } |
---|
568 | LRESULT OnCopyToClipboard(UINT, INT, HWND) |
---|
569 | { |
---|
570 | CWaitCursor WaitCursor; |
---|
571 | const CString sText = GetText(); |
---|
572 | if(sText.IsEmpty()) |
---|
573 | return 0; |
---|
574 | SetClipboardText(m_hWnd, sText); |
---|
575 | MessageBeep(MB_OK); |
---|
576 | return 0; |
---|
577 | } |
---|
578 | LRESULT OnProperties(UINT, INT, HWND) |
---|
579 | { |
---|
580 | const INT nItem = m_GraphListView.GetNextItem(-1, LVNI_SELECTED); |
---|
581 | if(nItem < 0) |
---|
582 | return 0; |
---|
583 | CItem& Item = m_GraphListView.GetItemData(nItem); |
---|
584 | if(!Item.FilterGraphNeeded(m_pRunningObjectTable)) |
---|
585 | return 0; |
---|
586 | Item.Check(); |
---|
587 | CLocalObjectPtr<CFilterGraphHelper> pFilterGraphHelper; |
---|
588 | pFilterGraphHelper->SetFilterGraph(Item.m_pFilterGraph, &Item.GetProcessData()); |
---|
589 | _V(pFilterGraphHelper->DoPropertyFrameModal((LONG) (LONG_PTR) m_hWnd)); |
---|
590 | return 0; |
---|
591 | } |
---|
592 | LRESULT OnOpenGsn(UINT, INT, HWND) |
---|
593 | { |
---|
594 | const INT nItem = m_GraphListView.GetNextItem(-1, LVNI_SELECTED); |
---|
595 | if(nItem < 0) |
---|
596 | return 0; |
---|
597 | CItem& Item = m_GraphListView.GetItemData(nItem); |
---|
598 | if(!Item.FilterGraphNeeded(m_pRunningObjectTable)) |
---|
599 | return 0; |
---|
600 | CFilterGraphHelper::OpenMonikerWithGsn(Item.m_sDisplayName, m_hWnd); |
---|
601 | return 0; |
---|
602 | } |
---|
603 | LRESULT OnOpenGe(UINT, INT, HWND) |
---|
604 | { |
---|
605 | const INT nItem = m_GraphListView.GetNextItem(-1, LVNI_SELECTED); |
---|
606 | if(nItem < 0) |
---|
607 | return 0; |
---|
608 | CItem& Item = m_GraphListView.GetItemData(nItem); |
---|
609 | if(!Item.FilterGraphNeeded(m_pRunningObjectTable)) |
---|
610 | return 0; |
---|
611 | CFilterGraphHelper::OpenMonikerWithGe(Item.m_sDisplayName, m_hWnd); |
---|
612 | return 0; |
---|
613 | } |
---|
614 | }; |
---|
615 | |
---|
616 | private: |
---|
617 | COptions m_Options; |
---|
618 | CListPropertyPage m_ListPropertyPage; |
---|
619 | |
---|
620 | public: |
---|
621 | // CFilterGraphListPropertySheet |
---|
622 | CFilterGraphListPropertySheet(COptions* pOptions = NULL) : |
---|
623 | CSizablePropertySheetT<CFilterGraphListPropertySheet>(IDS_FILTERGRAPHLIST_LIST_PROPERTYSHEETCAPTION, TRUE), |
---|
624 | m_ListPropertyPage(this) |
---|
625 | { |
---|
626 | if(pOptions) |
---|
627 | m_Options = *pOptions; |
---|
628 | AddPage(m_ListPropertyPage); |
---|
629 | } |
---|
630 | BOOL SetInitialPosition() |
---|
631 | { |
---|
632 | if(!__super::SetInitialPosition()) |
---|
633 | return FALSE; |
---|
634 | SetIcon(AtlLoadIconImage(IDI_MODULE, LR_DEFAULTCOLOR, GetSystemMetrics(SM_CXICON), GetSystemMetrics(SM_CYICON)), TRUE); |
---|
635 | SetIcon(AtlLoadIconImage(IDI_MODULE, LR_DEFAULTCOLOR, GetSystemMetrics(SM_CXSMICON), GetSystemMetrics(SM_CYSMICON)), FALSE); |
---|
636 | CAboutDialog::UpdateCaption(*this); |
---|
637 | #pragma region System Menu |
---|
638 | CMenuHandle Menu = GetSystemMenu(FALSE); |
---|
639 | _W(Menu.AppendMenu(MF_SEPARATOR)); |
---|
640 | _W(Menu.AppendMenu(MF_STRING, ID_APP_ABOUT, _T("&About..."))); |
---|
641 | #pragma endregion |
---|
642 | return TRUE; |
---|
643 | } |
---|
644 | INT_PTR DoModal(HWND hParentWindow) |
---|
645 | { |
---|
646 | return CPropertySheetWithAccelerators::DoModal(hParentWindow); |
---|
647 | } |
---|
648 | |
---|
649 | // Window Message Handelr |
---|
650 | LRESULT OnSysCommand(UINT nCommand, CPoint) |
---|
651 | { |
---|
652 | switch(nCommand) |
---|
653 | { |
---|
654 | case ID_APP_ABOUT: |
---|
655 | { |
---|
656 | CAboutDialog Dialog; |
---|
657 | Dialog.DoModal(m_hWnd); |
---|
658 | } |
---|
659 | break; |
---|
660 | default: |
---|
661 | SetMsgHandled(FALSE); |
---|
662 | } |
---|
663 | return 0; |
---|
664 | } |
---|
665 | }; |
---|
666 | |
---|
667 | inline INT_PTR DoFilterGraphListPropertySheetModal(HWND hParentWindow, COptions* pOptions) |
---|
668 | { |
---|
669 | CFilterGraphListPropertySheet PropertySheet(pOptions); |
---|
670 | return PropertySheet.DoModal(hParentWindow); |
---|
671 | } |
---|