|
// PSLWindowsFilter.cpp : Implementation of CPSLWindowsFilter
#include "stdafx.h"
#include "PSLWindowsFilter.h"
CPSLWindowsFilter::CWindowsFilter::CWindowsFilter()
{
TopLevel = ffAny;
HasText = ffAny;
Visible = ffAny;
Enabled = ffAny;
ThreadID = 0;
ParentWnd = NULL;
}
bool CPSLWindowsFilter::CWindowsFilter::Reset()
{
if(TopLevel != ffAny || HasText != ffAny || Visible != ffAny || Enabled != ffAny || ThreadID || ParentWnd)
{
TopLevel = ffAny;
HasText = ffAny;
Visible = ffAny;
Enabled = ffAny;
ThreadID = 0;
ParentWnd = NULL;
return true;
}
return false;
}
/////////////////////////////////////////////////////////
// Implementation of class CPSLWindowsFilter
/////////////////////////////////////////////////////////
CPSLWindowsFilter::CPSLWindowsFilter()
{
::InitializeCriticalSection(&m_cs);
m_bLocalProcess = true; // Using filter for the current process by default;
Reset();
m_bDirty = true;
}
CPSLWindowsFilter::~CPSLWindowsFilter()
{
::DeleteCriticalSection(&m_cs);
}
HRESULT CPSLWindowsFilter::FinalConstruct()
{
return S_OK;
}
void CPSLWindowsFilter::FinalRelease()
{
}
bool CPSLWindowsFilter::CheckDirtyAndReset(CWindowsFilter * pFilter)
{
CCritSecLock lock(m_cs);
bool bDirty = m_bDirty;
m_bDirty = false;
*pFilter = m_Filter;
return bDirty;
}
////////////////////////////////////////////////////////////////////////
// Interface Implementation;
////////////////////////////////////////////////////////////////////////
STDMETHODIMP CPSLWindowsFilter::get_TopLevel(PSLFilterFlag * pValue)
{
PSL_BEGIN
CCritSecLock lock(m_cs);
*pValue = m_Filter.TopLevel;
PSL_END
}
STDMETHODIMP CPSLWindowsFilter::put_TopLevel(PSLFilterFlag newValue)
{
PSL_BEGIN
CCritSecLock lock(m_cs);
if(m_Filter.TopLevel != newValue)
{
m_Filter.TopLevel = newValue;
m_bDirty = true;
}
PSL_END
}
STDMETHODIMP CPSLWindowsFilter::get_HasText(PSLFilterFlag * pValue)
{
PSL_BEGIN
CCritSecLock lock(m_cs);
*pValue = m_Filter.HasText;
PSL_END
}
STDMETHODIMP CPSLWindowsFilter::put_HasText(PSLFilterFlag newValue)
{
PSL_BEGIN
CCritSecLock lock(m_cs);
if(m_Filter.HasText != newValue)
{
m_Filter.HasText = newValue;
m_bDirty = true;
}
PSL_END
}
STDMETHODIMP CPSLWindowsFilter::get_Visible(PSLFilterFlag * pValue)
{
PSL_BEGIN
CCritSecLock lock(m_cs);
*pValue = m_Filter.Visible;
PSL_END
}
STDMETHODIMP CPSLWindowsFilter::put_Visible(PSLFilterFlag newValue)
{
PSL_BEGIN
CCritSecLock lock(m_cs);
if(m_Filter.Visible != newValue)
{
m_Filter.Visible = newValue;
m_bDirty = true;
}
PSL_END
}
STDMETHODIMP CPSLWindowsFilter::get_Enabled(PSLFilterFlag * pValue)
{
PSL_BEGIN
CCritSecLock lock(m_cs);
*pValue = m_Filter.Enabled;
PSL_END
}
STDMETHODIMP CPSLWindowsFilter::put_Enabled(PSLFilterFlag newValue)
{
PSL_BEGIN
CCritSecLock lock(m_cs);
if(m_Filter.Enabled != newValue)
{
m_Filter.Enabled = newValue;
m_bDirty = true;
}
PSL_END
}
STDMETHODIMP CPSLWindowsFilter::get_ThreadID(long * pValue)
{
PSL_BEGIN
CCritSecLock lock(m_cs);
*pValue = m_Filter.ThreadID;
PSL_END
}
STDMETHODIMP CPSLWindowsFilter::put_ThreadID(long newValue)
{
PSL_BEGIN
if(newValue)
{
HANDLE hThread = ::OpenThread(THREAD_ALL_ACCESS, FALSE, newValue);
if(hThread)
::CloseHandle(hThread);
else
{
// Either invalid thread ID, or the thread
// doesn't belong to the current process;
return MakeException(exInvalidParameter);
}
}
CCritSecLock lock(m_cs);
if(m_Filter.ThreadID != newValue)
{
m_Filter.ThreadID = newValue;
m_bDirty = true;
}
PSL_END
}
STDMETHODIMP CPSLWindowsFilter::get_ParentHandle(VARIANT * pValue)
{
PSL_BEGIN
CCritSecLock lock(m_cs);
CPSLUtilities::SetVariantBig(pValue, (ABIG)m_Filter.ParentWnd);
PSL_END
}
STDMETHODIMP CPSLWindowsFilter::put_ParentHandle(VARIANT newValue)
{
PSL_BEGIN
bool bError = false;
HWND hWnd = (HWND)CPSLUtilities::GetVariantBig(&newValue, &bError);
if(bError)
return MakeException(exInvalidParameter);
if(hWnd)
{
if(::IsWindow(hWnd))
{
if(m_bLocalProcess)
{
// This means we can only set window handle
// that belongs to the current process here!
DWORD dwProcessID = 0;
::GetWindowThreadProcessId(hWnd, &dwProcessID);
if(::GetCurrentProcessId() != dwProcessID)
return MakeException(exInvalidParameter);
}
}
else
return MakeException(exInvalidParameter);
}
CCritSecLock lock(m_cs);
if(m_Filter.ParentWnd != hWnd)
{
m_Filter.ParentWnd = hWnd;
m_bDirty = true;
}
PSL_END
}
STDMETHODIMP CPSLWindowsFilter::Reset()
{
PSL_BEGIN
CCritSecLock lock(m_cs);
m_bDirty = m_Filter.Reset();
PSL_END
}
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.