Drawing

Previous chapterNext chapter Show allShow all    Hide allHide all

On drawing the control the values of the variables are read via their dispatch drivers, and accordingly one of the four defined bitmaps is displayed. When the value of a variable changes, the control is updated by the OnDraw routine.

 

void CLatchedSwitchCtrl::OnDraw(CDC* pdc, const CRect& rcBounds, const CRect& rcInvalid)

{

CRect rcBitmap = rcBounds;

rcBitmap.NormalizeRect();

 

if (!m_dElement)

{

m_SwitchOn.Render(pdc, &rcBounds, &rcBounds);

return;

}

 

BOOL bVal1 = 0, bVal2 = 0;

VARIANT vRes;

if (m_dSwitchVar) // Variable exists?

{

vRes = m_dSwitchVar.GetValue();

bVal1 = (BOOL)VariantToDouble(&vRes);

}

if (m_dLatchVar) // Variable exists?

{

vRes = m_dLatchVar.GetValue();

bVal1 = (BOOL)VariantToDouble(&vRes);

}

 

if (bVal1 && bVal2)

m_SwitchOn.Render(pdc, rcBitmap, rcBitmap);

else if (!bVal1 && bVal2)

m_SwitchOff.Render(pdc, rcBitmap, rcBitmap);

else if (bVal1 && !bVal2)

m_LatchedOn.Render(pdc, rcBitmap, rcBitmap);

else

m_LatchedOff.Render(pdc, rcBitmap, rcBitmap);

}