source: trunk/DirectShowSpy/FilterGraphList.h @ 302

Last change on this file since 302 was 285, checked in by roman, 10 years ago

Added local in-process COM server identification through virtual method table lookup

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