Setting values

Previous chapterNext chapter Show allShow all    Hide allHide all

A value can be set by clicking the control with the left mouse button. If m_iSollwertDirekt is 0, a dialog for the selection of the set value is opened, otherwise the current value of the switching variable is inverted. If the locking variable has the value 1, only a MessageBeep is executed.No value can be set via the control.

void CLatchedSwitchCtrl::OnLButtonDown(UINT nFlags, CPoint point)

{

CRect rcBounds;

GetWindowRect(&rcBounds);

 

COleVariant coleValue((BYTE)TRUE);

BOOL bLatch = (BOOL)VariantToDouble((LPVARIANT)&m_dLatchVar.GetValue());

BOOL bSwitch = (BOOL)VariantToDouble((LPVARIANT)&m_dSwitchVar.GetValue());

 

if (bLatch) // Locked!!!

MessageBeep(MB_ICONEXCLAMATION);

else

{

if (m_sollwertDirekt)

{

bSwitch = !bSwitch;

}

else

{

CSollwertDlg dlg;

dlg.m_iSollwert = bSwitch ? 1 : 0;

if (dlg.DoModal() == IDOK)

{

if (dlg.m_iSollwert == 2) // Toggle

bSwitch = !bSwitch;

else

bSwitch = (BOOL)dlg.m_iSollwert;

}

}

coleValue = (double)bSwitch;

m_dSwitchVar.SetValue(coleValue);

}

COleControl::OnLButtonDown(nFlags, point);

}