source: trunk/DirectShowSpy/FilterGraphList.h @ 440

Last change on this file since 440 was 432, checked in by roman, 9 years ago

VS2013 related updates; use of CSIDL_LOCAL_APPDATA instead of CSIDL_APPDATA for fallback log writes; added bitness and privilege indication in all captions

File size: 23.4 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
26#pragma comment(lib, "psapi.lib")
27
28////////////////////////////////////////////////////////////
29// CFilterGraphListPropertySheet
30
31//INT_PTR DoFilterGraphListPropertySheetModal(HWND hParentWindow = GetActiveWindow(), COptions* pOptions = NULL);
32INT_PTR DoFilterGraphListPropertySheetModal(HWND hParentWindow, COptions* pOptions);
33
34class CFilterGraphListPropertySheet :
35        public CSizablePropertySheetT<CFilterGraphListPropertySheet>,
36        public CPropertySheetWithAcceleratorsT<CFilterGraphListPropertySheet>
37{
38public:
39
40BEGIN_MSG_MAP_EX(CFilterGraphListPropertySheet)
41        CHAIN_MSG_MAP(CSizablePropertySheet)
42        MSG_WM_SYSCOMMAND(OnSysCommand)
43END_MSG_MAP()
44
45public:
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                VOID Refresh()
252                {
253                        CRoMapT<CStringW, CItem> ItemMap;
254                        #pragma region Enumerate
255                        _ATLTRY
256                        {
257                                LONG nProcessIdentifier;
258                                const BOOL bProcessIdentifierAvailable = m_PropertySheet.m_Options.TryGetLongValue(_T("FilterGraphListPropertySheet.ProcessIdentifier"), nProcessIdentifier);
259                                if(!m_pRunningObjectTable)
260                                        __C(GetRunningObjectTable(0, &m_pRunningObjectTable));
261                                CComPtr<IEnumMoniker> pEnumMoniker;
262                                __C(m_pRunningObjectTable->EnumRunning(&pEnumMoniker));
263                                CComPtr<IMalloc> pMalloc;
264                                __C(CoGetMalloc(1, &pMalloc));
265                                for(; ; )
266                                {
267                                        CComPtr<IMoniker> pMoniker;
268                                        if(pEnumMoniker->Next(1, &pMoniker, NULL) != S_OK)
269                                                break;
270                                        _ATLTRY
271                                        {
272                                                CComPtr<IBindCtx> pBindCtx;
273                                                __C(CreateBindCtx(0, &pBindCtx));
274                                                LPOLESTR pszDisplayName = NULL;
275                                                __C(pMoniker->GetDisplayName(pBindCtx, NULL, &pszDisplayName));
276                                                const CStringW sDisplayName = pszDisplayName;
277                                                _Z4(atlTraceGeneral, 4, _T("sDisplayName %ls\n"), sDisplayName);
278                                                pMalloc->Free(pszDisplayName);
279                                                static CRoStaticReW g_Expression(L"^\\!FilterGraph {[0-9A-F]+} pid {[0-9A-F]+}(; process\\: {.+?}, time\\: {[0-9]+\\-[0-9]+\\-[0-9]+})?", FALSE);
280                                                CRoReMatchContext MatchContext;
281                                                if(g_Expression.Match(sDisplayName, &MatchContext))
282                                                {
283                                                        CItem Item;
284                                                        Item.m_pMoniker = pMoniker;
285                                                        Item.m_sDisplayName = sDisplayName;
286                                                        _W(StrToInt64ExW(CStringW(L"0x") + MatchContext.GetMatchString(0), STIF_SUPPORT_HEX, &reinterpret_cast<LONGLONG&>(Item.m_nInstance)));
287                                                        _W(StrToIntExW(CStringW(L"0x") + MatchContext.GetMatchString(1), STIF_SUPPORT_HEX, &reinterpret_cast<INT&>(Item.m_nProcessIdentifier)));
288                                                        Item.m_sTime = CString(MatchContext.GetMatchString(3));
289                                                        Item.m_sTime.Replace(_T("-"), _T(":"));
290                                                        if(bProcessIdentifierAvailable && Item.m_nProcessIdentifier != (DWORD) nProcessIdentifier)
291                                                                continue; // Skip
292                                                        _W(ItemMap.SetAt(sDisplayName, Item) >= 0);
293                                                }
294                                        }
295                                        _ATLCATCHALL()
296                                        {
297                                                _Z_EXCEPTION();
298                                        }
299                                }
300                        }
301                        _ATLCATCHALL()
302                        {
303                                _Z_EXCEPTION();
304                        }
305                        #pragma endregion
306                        CWindowRedraw GraphListViewRedraw(m_GraphListView);
307                        BOOL bSortNeeded = FALSE;
308                        #pragma region Remove
309                        for(INT nItem = m_GraphListView.GetItemCount() - 1; nItem >= 0; nItem--)
310                        {
311                                const POSITION Position = ItemMap.Lookup(m_GraphListView.GetItemData(nItem).m_sDisplayName);
312                                if(Position)
313                                        ItemMap.RemoveAtPos(Position);
314                                else
315                                        _W(m_GraphListView.DeleteItem(nItem));
316                        }
317                        #pragma endregion
318                        #pragma region Add
319                        INT nItemIndex = m_GraphListView.GetItemCount();
320                        for(POSITION Position = ItemMap.GetStartPosition(); Position; ItemMap.GetNext(Position))
321                        {
322                                CItem& Item = ItemMap.GetValueAt(Position);
323                                _ATLTRY
324                                {
325                                        CHandle Process;
326                                        //Process.Attach(OpenProcess(PROCESS_QUERY_INFORMATION, FALSE, Item.m_nProcessIdentifier));
327                                        Process.Attach(OpenProcess(PROCESS_QUERY_INFORMATION | PROCESS_VM_READ, FALSE, Item.m_nProcessIdentifier));
328                                        __E(Process);
329                                        TCHAR pszPath[MAX_PATH] = { 0 };
330                                        //_W(GetProcessImageFileName(Process, pszPath, DIM(pszPath)));
331                                        _W(GetModuleFileNameEx(Process, NULL, pszPath, DIM(pszPath)));
332                                        Item.m_sProcessImagePath = pszPath;
333                                }
334                                _ATLCATCHALL()
335                                {
336                                        _Z_EXCEPTION();
337                                }
338                                const INT nItem = m_GraphListView.InsertItem(nItemIndex++, Item);
339                                _A(nItem >= 0);
340                                bSortNeeded = TRUE;
341                        }
342                        #pragma endregion
343                        if(bSortNeeded)
344                                m_GraphListView.SortItems(&CListPropertyPage::SortGraphListViewItems, (LPARAM) this);
345                }
346                CString GetText()
347                {
348                        CRoArrayT<CString> GraphArray;
349                        for(INT nItem = m_GraphListView.GetNextItem(-1, LVNI_SELECTED); nItem >= 0; nItem = m_GraphListView.GetNextItem(nItem, LVNI_SELECTED))
350                        {
351                                CItem& Item = m_GraphListView.GetItemData(nItem);
352                                _ATLTRY
353                                {
354                                        if(Item.FilterGraphNeeded(m_pRunningObjectTable))
355                                        {
356                                                Item.Check();
357                                                m_GraphListView.RedrawItems(nItem, nItem);
358                                                GraphArray.Add(CFilterGraphHelper::GetText(Item.m_pFilterGraph, &Item.GetProcessData()));
359                                        }
360                                }
361                                _ATLCATCHALL()
362                                {
363                                        _Z_EXCEPTION();
364                                }
365                        }
366                        return _StringHelper::Join(GraphArray, _T("\r\n") _T("---") _T("\r\n") _T("\r\n"));
367                }
368
369        // Window Message Handler
370                LRESULT OnInitDialog(HWND, LPARAM)
371                {
372                        _ATLTRY
373                        {
374                                CWaitCursor WaitCursor;
375                                m_GraphListView.Initialize(GetDlgItem(IDC_FILTERGRAPHLIST_LIST_GRAPH));
376                                CToolTipCtrl ToolTip = m_GraphListView.GetToolTips();
377                                ToolTip.SetDelayTime(TTDT_AUTOPOP, 30 * 1000); // 30 seconds
378                                ToolTip.SetMaxTipWidth(max(GetSystemMetrics(SM_CXSCREEN) * 5 / 8, 600));
379                                m_RefreshButton = GetDlgItem(IDC_FILTERGRAPHLIST_LIST_REFRESH);
380                                m_CheckButton = GetDlgItem(IDC_FILTERGRAPHLIST_LIST_CHECK);
381                                m_CopyToClipboardButton = GetDlgItem(IDC_FILTERGRAPHLIST_LIST_COPYTOCLIPBOARD);
382                                m_PropertiesButton = GetDlgItem(IDC_FILTERGRAPHLIST_LIST_PROPERTIES);
383                                DlgResize_Init(FALSE, FALSE);
384                                Refresh();
385                                #if _DEVELOPMENT
386                                        m_GraphListView.SetItemState(0, LVIS_FOCUSED | LVIS_SELECTED, LVIS_FOCUSED | LVIS_SELECTED);
387                                #endif // _DEVELOPMENT
388                                UpdateControls();
389                                #pragma region Default Property Sheet Size
390                                CRect Position;
391                                _W(m_PropertySheet.GetWindowRect(Position));
392                                Position.InflateRect(6 * Position.Width() / 8, 1 * Position.Height() / 8);
393                                CSize ScreenExtent(GetSystemMetrics(SM_CXSCREEN), GetSystemMetrics(SM_CYSCREEN));
394                                ScreenExtent.cx -= ScreenExtent.cx / 8;
395                                ScreenExtent.cy -= ScreenExtent.cy / 8;
396                                if(Position.Width() > ScreenExtent.cx)
397                                        Position.right = Position.left + ScreenExtent.cx;
398                                if(Position.Height() > ScreenExtent.cy)
399                                        Position.bottom = Position.top + ScreenExtent.cy;
400                                _W(m_PropertySheet.MoveWindow(Position));
401                                _W(m_PropertySheet.CenterWindow());
402                                #pragma endregion
403                                CancelToClose();
404                                BOOL bAutomaticInitialCheck = FALSE;
405                                m_PropertySheet.m_Options.TryGetBoolValue(_T("FilterGraphListPropertySheet.AutomaticInitialCheck"), bAutomaticInitialCheck);
406                                if(bAutomaticInitialCheck)
407                                        PostMessage(WM_COMMAND, MAKEWPARAM(IDC_FILTERGRAPHLIST_LIST_CHECKALL, BN_CLICKED));
408                        }
409                        _ATLCATCHALL()
410                        {
411                                for(CWindow Window = GetWindow(GW_CHILD); Window.IsWindow(); Window = Window.GetWindow(GW_HWNDNEXT))
412                                        Window.EnableWindow(FALSE);
413                                _ATLRETHROW;
414                        }
415                        return TRUE;
416                }
417                LRESULT OnDestroy()
418                {
419                        return 0;
420                }
421                LRESULT OnTranslateAccelerator(MSG* pMessage)
422                {
423                        return TranslateAccelerator(m_hWnd, m_hAccelerators, pMessage) ? PSNRET_MESSAGEHANDLED : PSNRET_NOERROR;
424                }
425                LRESULT OnGraphListViewGetDispInfo(NMLVDISPINFO* pHeader)
426                {
427                        const CItem& Item = m_GraphListView.DataFromParameter(pHeader->item.lParam);
428                        if(pHeader->item.mask & LVIF_TEXT)
429                        {
430                                CString& sTextBuffer = m_GraphListView.GetTextBufferString(TRUE);
431                                switch(pHeader->item.iSubItem)
432                                {
433                                case 1: // Process Name
434                                        sTextBuffer = PathFindFileName(Item.m_sProcessImagePath);
435                                        break;
436                                case 2: // Creation Time
437                                        sTextBuffer = Item.m_sTime;
438                                        break;
439                                case 3: // Friendly Name
440                                        sTextBuffer = CString(Item.m_sFriendlyName);
441                                        break;
442                                case 4: // Filter Count
443                                        if(Item.m_pFilterGraph)
444                                                sTextBuffer = AtlFormatString(_T("%d"), Item.m_nFilterCount);
445                                        break;
446                                case 5: // State
447                                        if(Item.m_pFilterGraph)
448                                                sTextBuffer = Item.m_sState;
449                                        break;
450                                case 6: // Process Image Directory
451                                        sTextBuffer = (LPCTSTR) GetPathDirectory(Item.m_sProcessImagePath);
452                                        break;
453                                default: // Process, Instance
454                                        sTextBuffer = AtlFormatString(_T("%d - 0x%p"), Item.m_nProcessIdentifier, Item.m_nInstance);
455                                }
456                                pHeader->item.pszText = m_GraphListView.GetTextBuffer();
457                        }
458                        return 0;
459                }
460                LRESULT OnGraphListViewGetInfoTip(NMLVGETINFOTIP* pHeader)
461                {
462                        const CItem& Item = m_GraphListView.GetItemData(pHeader->iItem);
463                        CString& sTextBuffer = m_GraphListView.GetTextBufferString(TRUE);
464                        sTextBuffer.AppendFormat(_T("Process: %d (0x%X) %s\r\n"), Item.m_nProcessIdentifier, Item.m_nProcessIdentifier, CString(FindFileName(Item.m_sProcessImagePath)));
465                        if(!Item.m_sTime.IsEmpty())
466                                sTextBuffer.AppendFormat(_T("Creation Time: %s\r\n"), Item.m_sTime);
467                        if(!Item.m_sFriendlyName.IsEmpty())
468                                sTextBuffer.AppendFormat(_T("Friendly Name: %ls\r\n"), Item.m_sFriendlyName);
469                        if(Item.m_pFilterGraph)
470                        {
471                                sTextBuffer.AppendFormat(_T("Filter Count: %d\r\n"), Item.m_nFilterCount);
472                                if(!Item.m_sState.IsEmpty())
473                                        sTextBuffer.AppendFormat(_T("State: %s\r\n"), Item.m_sState);
474                                if(Item.m_fDuration > 0)
475                                {
476                                        sTextBuffer.AppendFormat(_T("Duration: %s seconds\r\n"), _StringHelper::FormatNumber(Item.m_fDuration, 3));
477                                        sTextBuffer.AppendFormat(_T("Position: %s seconds\r\n"), _StringHelper::FormatNumber(Item.m_fPosition, 3));
478                                }
479                        }
480                        sTextBuffer.AppendFormat(_T("Display Name: %ls\r\n"), Item.m_sDisplayName);
481                        sTextBuffer.AppendFormat(_T("Instance: 0x%p\r\n"), Item.m_nInstance);
482                        const CString sDirectory = (LPCTSTR) GetPathDirectory(Item.m_sProcessImagePath);
483                        if(!sDirectory.IsEmpty())
484                                sTextBuffer.AppendFormat(_T("Process Directory: %s\r\n"), sDirectory);
485                        sTextBuffer.TrimRight(_T("\t\n\r ."));
486                        #pragma region Clipboard Copy
487                        if(GetKeyState(VK_CONTROL) < 0 && GetKeyState(VK_SHIFT) < 0)
488                                _ATLTRY
489                                {
490                                        SetClipboardText(m_hWnd, sTextBuffer);
491                                        MessageBeep(MB_OK);
492                                }
493                                _ATLCATCHALL()
494                                {
495                                        _Z_EXCEPTION();
496                                        MessageBeep(MB_ICONERROR);
497                                }
498                        #pragma endregion
499                        _tcsncpy_s(pHeader->pszText, pHeader->cchTextMax, m_GraphListView.GetTextBuffer(), _TRUNCATE);
500                        return 0;
501                }
502                LRESULT OnGraphListViewItemChanged(NMLISTVIEW* pHeader)
503                {
504                        UpdateControls();
505                        return 0;
506                }
507                LRESULT OnGraphListViewDblClk(NMITEMACTIVATE* pHeader)
508                {
509                        //m_CheckButton.Click();
510                        m_PropertiesButton.Click();
511                        return 0;
512                }
513                LRESULT OnContextMenu(CWindow Window, CPoint Position)
514                {
515                        if(Window == m_GraphListView)
516                        {
517                                CMenu ContainerMenu = AtlLoadMenu(IDD);
518                                CMenuHandle Menu = ContainerMenu.GetSubMenu(0);
519                                const UINT nCount = m_GraphListView.GetItemCount();
520                                const UINT nSelectedCount = m_GraphListView.GetSelectedCount();
521                                Menu.EnableMenuItem(IDC_FILTERGRAPHLIST_LIST_CHECK, MF_BYCOMMAND | (m_CheckButton.IsWindowEnabled() ? MF_ENABLED : MF_GRAYED | MF_DISABLED));
522                                Menu.EnableMenuItem(IDC_FILTERGRAPHLIST_LIST_CHECKALL, MF_BYCOMMAND | ((nCount > 0) ? MF_ENABLED : MF_GRAYED | MF_DISABLED));
523                                Menu.EnableMenuItem(IDC_FILTERGRAPHLIST_LIST_COPYTOCLIPBOARD, MF_BYCOMMAND | (m_CopyToClipboardButton.IsWindowEnabled() ? MF_ENABLED : MF_GRAYED | MF_DISABLED));
524                                Menu.EnableMenuItem(IDC_FILTERGRAPHLIST_LIST_OPENGSN, MF_BYCOMMAND | ((nSelectedCount == 1) ? MF_ENABLED : MF_GRAYED | MF_DISABLED));
525                                Menu.EnableMenuItem(IDC_FILTERGRAPHLIST_LIST_OPENGE, MF_BYCOMMAND | ((nSelectedCount == 1) ? MF_ENABLED : MF_GRAYED | MF_DISABLED));
526                                Menu.EnableMenuItem(IDC_FILTERGRAPHLIST_LIST_REFRESH, MF_BYCOMMAND | (m_RefreshButton.IsWindowEnabled() ? MF_ENABLED : MF_GRAYED | MF_DISABLED));
527                                Menu.EnableMenuItem(IDC_FILTERGRAPHLIST_LIST_PROPERTIES, MF_BYCOMMAND | (m_PropertiesButton.IsWindowEnabled() ? MF_ENABLED : MF_GRAYED | MF_DISABLED));
528                                Menu.SetMenuDefaultItem(IDC_FILTERGRAPHLIST_LIST_PROPERTIES);
529                                Menu.TrackPopupMenu(TPM_RIGHTBUTTON | TPM_LEFTALIGN | TPM_TOPALIGN, Position.x, Position.y, m_hWnd); 
530                        }
531                        return 0;
532                }
533                LRESULT OnRefresh(UINT, INT, HWND)
534                {
535                        CWaitCursor WaitCursor;
536                        Refresh();
537                        UpdateControls();
538                        return 0;
539                }
540                LRESULT OnCheck(UINT, INT, HWND)
541                {
542                        CWaitCursor WaitCursor;
543                        for(INT nItem = m_GraphListView.GetNextItem(-1, LVNI_SELECTED); nItem >= 0; nItem = m_GraphListView.GetNextItem(nItem, LVNI_SELECTED))
544                        {
545                                CItem& Item = m_GraphListView.GetItemData(nItem);
546                                if(Item.FilterGraphNeeded(m_pRunningObjectTable))
547                                        if(Item.Check())
548                                                m_GraphListView.RedrawItems(nItem, nItem);
549                        }
550                        return 0;
551                }
552                LRESULT OnCheckAll(UINT, INT, HWND)
553                {
554                        CWaitCursor WaitCursor;
555                        for(INT nItem = m_GraphListView.GetItemCount() - 1; nItem >= 0; nItem--)
556                        {
557                                CItem& Item = m_GraphListView.GetItemData(nItem);
558                                if(Item.FilterGraphNeeded(m_pRunningObjectTable))
559                                        if(Item.Check())
560                                                m_GraphListView.RedrawItems(nItem, nItem);
561                        }
562                        return 0;
563                }
564                LRESULT OnCopyToClipboard(UINT, INT, HWND)
565                {
566                        CWaitCursor WaitCursor;
567                        const CString sText = GetText();
568                        if(sText.IsEmpty())
569                                return 0;
570                        SetClipboardText(m_hWnd, sText);
571                        MessageBeep(MB_OK);
572                        return 0;
573                }
574                LRESULT OnProperties(UINT, INT, HWND)
575                {
576                        const INT nItem = m_GraphListView.GetNextItem(-1, LVNI_SELECTED);
577                        if(nItem < 0)
578                                return 0;
579                        CItem& Item = m_GraphListView.GetItemData(nItem);
580                        if(!Item.FilterGraphNeeded(m_pRunningObjectTable))
581                                return 0;
582                        Item.Check();
583                        CLocalObjectPtr<CFilterGraphHelper> pFilterGraphHelper;
584                        pFilterGraphHelper->SetFilterGraph(Item.m_pFilterGraph, &Item.GetProcessData());
585                        _V(pFilterGraphHelper->DoPropertyFrameModal((LONG) (LONG_PTR) m_hWnd));
586                        return 0;
587                }
588                LRESULT OnOpenGsn(UINT, INT, HWND)
589                {
590                        const INT nItem = m_GraphListView.GetNextItem(-1, LVNI_SELECTED);
591                        if(nItem < 0)
592                                return 0;
593                        CItem& Item = m_GraphListView.GetItemData(nItem);
594                        if(!Item.FilterGraphNeeded(m_pRunningObjectTable))
595                                return 0;
596                        CFilterGraphHelper::OpenMonikerWithGsn(Item.m_sDisplayName, m_hWnd);
597                        return 0;
598                }
599                LRESULT OnOpenGe(UINT, INT, HWND)
600                {
601                        const INT nItem = m_GraphListView.GetNextItem(-1, LVNI_SELECTED);
602                        if(nItem < 0)
603                                return 0;
604                        CItem& Item = m_GraphListView.GetItemData(nItem);
605                        if(!Item.FilterGraphNeeded(m_pRunningObjectTable))
606                                return 0;
607                        CFilterGraphHelper::OpenMonikerWithGe(Item.m_sDisplayName, m_hWnd);
608                        return 0;
609                }
610        };
611
612private:
613        COptions m_Options;
614        CListPropertyPage m_ListPropertyPage;
615
616public:
617// CFilterGraphListPropertySheet
618        CFilterGraphListPropertySheet(COptions* pOptions = NULL) :
619                CSizablePropertySheetT<CFilterGraphListPropertySheet>(IDS_FILTERGRAPHLIST_LIST_PROPERTYSHEETCAPTION),
620                m_ListPropertyPage(this)
621        {
622                if(pOptions)
623                        m_Options = *pOptions;
624                AddPage(m_ListPropertyPage);
625        }
626        BOOL SetInitialPosition()
627        {
628                if(!__super::SetInitialPosition())
629                        return FALSE;
630                SetIcon(AtlLoadIconImage(IDI_MODULE, LR_DEFAULTCOLOR, GetSystemMetrics(SM_CXICON), GetSystemMetrics(SM_CYICON)), TRUE);
631                SetIcon(AtlLoadIconImage(IDI_MODULE, LR_DEFAULTCOLOR, GetSystemMetrics(SM_CXSMICON), GetSystemMetrics(SM_CYSMICON)), FALSE);
632                CAboutDialog::UpdateCaption(*this);
633                #pragma region System Menu
634                CMenuHandle Menu = GetSystemMenu(FALSE);
635                _W(Menu.AppendMenu(MF_SEPARATOR));
636                _W(Menu.AppendMenu(MF_STRING, ID_APP_ABOUT, _T("&About...")));
637                #pragma endregion
638                return TRUE;
639        }
640        INT_PTR DoModal(HWND hParentWindow)
641        {
642                return CPropertySheetWithAccelerators::DoModal(hParentWindow);
643        }
644
645// Window Message Handelr
646        LRESULT OnSysCommand(UINT nCommand, CPoint)
647        {
648                switch(nCommand)
649                {
650                case ID_APP_ABOUT:
651                        {
652                                CAboutDialog Dialog;
653                                Dialog.DoModal(m_hWnd);
654                        }
655                        break;
656                default:
657                        SetMsgHandled(FALSE);
658                }
659                return 0;
660        }
661};
662
663inline INT_PTR DoFilterGraphListPropertySheetModal(HWND hParentWindow, COptions* pOptions)
664{
665        CFilterGraphListPropertySheet PropertySheet(pOptions);
666        return PropertySheet.DoModal(hParentWindow);
667}
Note: See TracBrowser for help on using the repository browser.