source: trunk/DirectShowSpy/FilterGraphList.h @ 267

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

Updated source code/copyright notice

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