ActiveX控件:不能独立运行的,必需嵌入容器才能得到执行的函数功能组合。
容器应用程序是可以嵌入或链接对象的应用程序。Word就是容器应用程序。
服务器应用程序是创建对象并且当对象被双击时,可以被启动的应用程序。Excel就是服务器应用程序。
ActiveX控件的四种属性
Stock:为每个控件提供的标准属性,如字体或颜色。
Ambient:围绕控件的环境属性——已被置入容器的属性。这些属性不能被更改,但控件可以使用它们调整自己的属性。
Extended:这些是由容器处理的属性,一般包括大小和在屏幕上的位置。
Custom:由控件开发者添加的属性。
代码如下:
创建时建立计时器
int CClockCtrl::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
if (COleControl::OnCreate(lpCreateStruct) == -1)
return -1;
// TODO: Add your specialized creation code here
SetTimer(1,m_interval,NULL);
return 0;
}
调用OnTimer消息函数使窗口无效
void CClockCtrl::OnTimer(UINT nIDEvent)
{
// TODO: Add your message handler code here and/or call default
//Invalidate();
if(AmbientUserMode())
InvalidateControl();
COleControl::OnTimer(nIDEvent);
}
重画窗口时修改修改控件的属性(颜色与背景)显示效果、与事件
void CClockCtrl::OnDraw(CDC* pdc, const CRect& rcBounds, const CRect& rcInvalid)
{
// TODO: Replace the following code with your own drawing code.
// pdc->FillRect(rcBounds, CBrush::FromHandle((HBRUSH)GetStockObject(WHITE_BRUSH)));
// pdc->Ellipse(rcBounds);
CBrush brush(TranslateColor(GetBackColor()));
pdc->FillRect(rcBounds, &brush);
pdc->SetBkMode(TRANSPARENT);
pdc->SetTextColor(TranslateColor(GetForeColor()));
CTime time=CTime::GetCurrentTime();
if(0==time.GetSecond())
{
FireNewMinute();
}
CString str=time.Format("%H:%M:%S");
pdc->TextOut(0,0,str);
}
如何添加修改控件的属性与事件
如何动态添加一个控件