Next, you will write the code that sets the default value of the FlashColor property. Choosing the default value is relatively unimportant for the example; any arbitrary value will do, as long as it's not the same as the background color.
Windows uses a 32-bit unsigned integer value to represent a color. The lowest three bytes specify red, green, and blue values, each with a range from 0 through 255. Therefore, the value 0x000000FF is red, 0x0000FF00 is green, and 0x00FF0000 is blue. To simplify the process of assigning color values, you will use the RGB macro. Its three parameters consist of red, green, and blue values, in that order.
The member function DoPropExchange
initializes the m_flashColor
member variable to a value corresponding to the color red. Because the PX_Long function expects a reference to a long and m_flashColor
is an unsigned long, m_flashColor
is cast to a long reference.
Add the following line to the DoPropExchange
function in CIRCCTL.CPP:
PX_Long(pPX, _T("FlashColor"), (long &)m_flashColor, RGB(0xFF, 0x00, 0x00));
as shown in the following code example:
void CCircCtrl::DoPropExchange(CPropExchange* pPX)
{
ExchangeVersion(pPX, MAKELONG(_wVerMinor, _wVerMajor));
COleControl::DoPropExchange(pPX);
PX_Bool(pPX, _T("CircleShape"), m_circleShape, TRUE);
PX_Short(pPX, _T("CircleOffset"), m_circleOffset, 0);
PX_Long(pPX, _T("FlashColor"), (long &)m_flashColor, RGB(0xFF, 0x00, 0x00));
}
As with all literal strings, the property name string is passed through the _T macro before being passed as a parameter to the PX_Long function.