source: trunk/DirectShowSpy/FilterGraphList.h @ 937

Last change on this file since 937 was 831, checked in by roman, 6 years ago

Upgrade to VS2017; removed exception filter (hook); improved tracing

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