Back

// PSLMonitors.cpp : Implementation of CPSLMonitors

#include "stdafx.h"
#include "PSLMonitor.h"
#include "PSLMonitors.h"


CPSLMonitors::CPSLMonitors()
{
}

HRESULT CPSLMonitors::OnIndexOutOfRange()
{
   return MakeException(EX_INDEXOUTOFRANGE);
}

HRESULT CPSLMonitors::FinalConstruct()
{
   PSL_BEGIN

   InternalUpdate();

   PSL_END
}

void CPSLMonitors::FinalRelease()
{
}

BOOL CALLBACK CPSLMonitors::MonitorEnumProc(HMONITOR hMonitor, HDC hdcMonitor, LPRECT lprcMonitor, LPARAM dwData)
{
   vector<HMONITOR> * pMonitors = (vector<HMONITOR>*)dwData;
   pMonitors->push_back(hMonitor);
   return TRUE;
}

void CPSLMonitors::InternalUpdate()
{
   CCritSecLock cs(m_csCollection);
   m_coll.clear();

   vector<HMONITOR> monitors;
   ::EnumDisplayMonitors(NULL, NULL, MonitorEnumProc, (LPARAM)&monitors);

   CComObject<CPSLMonitor> * pMonitor = NULL;
   for(vector<HMONITOR>::iterator i = monitors.begin();i != monitors.end();i ++)
   {
      if(CComObject<CPSLMonitor>::CreateInstance(&pMonitor) == S_OK)
      {
         pMonitor->Initialize((*i));
         m_coll.push_back(CComPtr<IPSLMonitor>(pMonitor));
      }
   }
}

////////////////////////////////////////////////////////////////////////
// Interface Implementation;
////////////////////////////////////////////////////////////////////////

STDMETHODIMP CPSLMonitors::Update()
{
   PSL_BEGIN

   InternalUpdate();

   PSL_END
}

Top