source: trunk/DirectShowSpy/FilterGraphList.h @ 276

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

Updated header (on use, applicability, redistribution)

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