|
// PSLMonitor.cpp : Implementation of CPSLMonitor
#include "stdafx.h"
#include "PSLMonitor.h"
CPSLMonitor::CPSLMonitor()
{
m_bPrimary = false;
m_DeviceName = _T("");
m_MonitorName = _T("");
m_RefreshRate = 0;
m_ColorRes = 0;
m_pBounds = NULL;
m_pWorkArea = NULL;
m_pPhysicalSize = NULL;
}
HRESULT CPSLMonitor::FinalConstruct()
{
CComObject<CPSLRect>::CreateInstance(&m_pBounds);
m_pBounds->AddRef();
CComObject<CPSLRect>::CreateInstance(&m_pWorkArea);
m_pWorkArea->AddRef();
CComObject<CPSLSize>::CreateInstance(&m_pPhysicalSize);
m_pPhysicalSize->AddRef();
return S_OK;
}
void CPSLMonitor::FinalRelease()
{
m_pPhysicalSize->Release();
m_pWorkArea->Release();
m_pBounds->Release();
}
void CPSLMonitor::Initialize(HMONITOR hMonitor)
{
MONITORINFOEX info;
info.cbSize = sizeof(MONITORINFOEX);
::GetMonitorInfo(hMonitor, &info);
m_bPrimary = (info.dwFlags & MONITORINFOF_PRIMARY) > 0;
m_DeviceName = info.szDevice;
m_pBounds->Initialize(&info.rcMonitor);
m_pWorkArea->Initialize(&info.rcWork);
HDC hDC = ::CreateDC(NULL, m_DeviceName, NULL, NULL);
if(hDC)
{
SIZE s = {::GetDeviceCaps(hDC, HORZSIZE), ::GetDeviceCaps(hDC, VERTSIZE)};
m_pPhysicalSize->Initialize(&s);
m_RefreshRate = ::GetDeviceCaps(hDC, VREFRESH);
m_ColorRes = ::GetDeviceCaps(hDC, COLORRES);
::DeleteDC(hDC);
}
// When monitor device name is specified,
// it is the first display device that represents
// our monitor, and that's why we do not enumerate
// all objects, just take the one with index 0:
DISPLAY_DEVICE device;
device.cb = sizeof(DISPLAY_DEVICE);
if(::EnumDisplayDevices(m_DeviceName, 0, &device, 0))
m_MonitorName = device.DeviceString;
}
////////////////////////////////////////////////////////////////////////
// Interface Implementation;
////////////////////////////////////////////////////////////////////////
STDMETHODIMP CPSLMonitor::get_IsPrimary(VARIANT_BOOL * pValue)
{
PSL_BEGIN
*pValue = m_bPrimary?VARIANT_TRUE:VARIANT_FALSE;
PSL_END
}
STDMETHODIMP CPSLMonitor::get_DeviceName(BSTR * pValue)
{
PSL_BEGIN
*pValue = m_DeviceName.copy();
PSL_END
}
STDMETHODIMP CPSLMonitor::get_MonitorName(BSTR * pValue)
{
PSL_BEGIN
*pValue = m_MonitorName.copy();
PSL_END
}
STDMETHODIMP CPSLMonitor::get_Bounds(IPSLRect ** ppValue)
{
PSL_BEGIN
m_pBounds->AddRef();
*ppValue = CComPtr<IPSLRect>(m_pBounds);
PSL_END
}
STDMETHODIMP CPSLMonitor::get_WorkArea(IPSLRect ** ppValue)
{
PSL_BEGIN
m_pWorkArea->AddRef();
*ppValue = CComPtr<IPSLRect>(m_pWorkArea);
PSL_END
}
STDMETHODIMP CPSLMonitor::get_PhysicalSize(IPSLSize ** ppValue)
{
PSL_BEGIN
m_pPhysicalSize->AddRef();
*ppValue = CComPtr<IPSLSize>(m_pPhysicalSize);
PSL_END
}
STDMETHODIMP CPSLMonitor::get_RefreshRate(short * pValue)
{
PSL_BEGIN
*pValue = m_RefreshRate;
PSL_END
}
STDMETHODIMP CPSLMonitor::get_ColorRes(short * pValue)
{
PSL_BEGIN
*pValue = m_ColorRes;
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.