TransparentStatic.h:class CTransparentStatic : public CStatic
{
// Construction
public:
CTransparentStatic();// Attributes
public:// Operations
public:
CFont*   m_pfont;   //字体指针
COLORREF m_crColor;   //字颜色
UINT   m_nFormat;   //字位置// Overrides
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(CTransparentStatic)
//}}AFX_VIRTUAL// Implementation
public:
virtual ~CTransparentStatic();protected:
CFont   m_font;    //字体// Generated message map functions
//{{AFX_MSG(CTransparentStatic)
afx_msg void OnPaint();
//}}AFX_MSGDECLARE_MESSAGE_MAP()
};
TransparentStatic.cpp://///////////////////////////////////////////////////////////////////////////
// CTransparentStaticCTransparentStatic::CTransparentStatic()
{
m_font.CreateFont
   (
   15,        // nHeight
   0,        // nWidth
   0,        // nEscapement
   0,        // nOrientation
   FW_NORMAL,      // nWeight
   FALSE,       // bItalic
   FALSE,       // bUnderline
   0,        // cStrikeOut
   ANSI_CHARSET,     // nCharSet
   OUT_DEFAULT_PRECIS,    // nOutPrecision
   CLIP_DEFAULT_PRECIS,   // nClipPrecision
   DEFAULT_QUALITY,    // nQuality
   DEFAULT_PITCH | FF_SWISS, // nPitchAndFamily
   "Tahoma"      // lpszFacename
   );
m_pfont   = &m_font;
m_crColor = RGB(255, 255, 255);
m_nFormat = DT_LEFT;
}CTransparentStatic::~CTransparentStatic()
{
}BEGIN_MESSAGE_MAP(CTransparentStatic, CStatic)
//{{AFX_MSG_MAP(CTransparentStatic)
ON_WM_PAINT()
//}}AFX_MSG_MAP
END_MESSAGE_MAP()/////////////////////////////////////////////////////////////////////////////
// CTransparentStatic message handlersvoid CTransparentStatic::OnPaint() 
{
CPaintDC dc(this); // device context for painting// 取得位置
CRect client_rect;
GetClientRect(client_rect);// 取得文本
CString szText;
GetWindowText(szText);// 取得字体,并选入设备文件
dc.SelectObject(m_pfont);// 用透明背景填充设备文件
dc.SetBkMode(TRANSPARENT);// 显示文字
dc.SetTextColor(m_crColor);
dc.DrawText(szText, client_rect, m_nFormat);
}
代码比较简单,其实就是在OnPaint事件内重新填充背景及显示文字.如果想在程序中动态改变字体,颜色等信息,在修改了成员变量之后调用Invalidate(FALSE)刷新即可.现在又想到其实可以弄得更简单一些,写一个成员函数,传参数进去,在里面完成变量的修改和窗口刷新过程,这样一句话就够了.恩,过两天考试完了改写一下^_^/////////////////////////////////////////////////////////////////////////////ok,考试全部OVER了~现在贴上改进之后的CTransparentStatic:TransparentStatic.h:class CTransparentStatic : public CStatic
{
// Construction
public:
CTransparentStatic();// Attributes
public:// Operations
public:
void SetOutward(CFont* pfont, COLORREF crColor, UINT nFormat);CFont* GetpFont();
COLORREF GetColor();
UINT GetFormat();// Overrides
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(CTransparentStatic)
//}}AFX_VIRTUAL// Implementation
public:
virtual ~CTransparentStatic();protected:
CFont*   m_pfont;   //字体指针
COLORREF m_crColor;   //字颜色
UINT   m_nFormat;   //字位置// Generated message map functions
//{{AFX_MSG(CTransparentStatic)
afx_msg void OnPaint();
//}}AFX_MSGDECLARE_MESSAGE_MAP()
};TransparentStatic.cpp://///////////////////////////////////////////////////////////////////////////
// CTransparentStaticCTransparentStatic::CTransparentStatic()
{
m_pfont   = new CFont;
m_pfont->CreateFont
   (
   15,        // nHeight
   0,        // nWidth
   0,        // nEscapement
   0,        // nOrientation
   FW_NORMAL,      // nWeight
   FALSE,       // bItalic
   FALSE,       // bUnderline
   0,        // cStrikeOut
   ANSI_CHARSET,     // nCharSet
   OUT_DEFAULT_PRECIS,    // nOutPrecision
   CLIP_DEFAULT_PRECIS,   // nClipPrecision
   DEFAULT_QUALITY,    // nQuality
   DEFAULT_PITCH | FF_SWISS, // nPitchAndFamily
   "Tahoma"      // lpszFacename
   );
m_crColor = RGB(255, 255, 255);
m_nFormat = DT_LEFT;
}CTransparentStatic::~CTransparentStatic()
{
delete m_pfont;
}void CTransparentStatic::SetOutward(CFont* pfont, COLORREF crColor, UINT nFormat)
{
if(pfont)
{
   //获得LOGFONT
   LOGFONT lf;
   pfont ->GetLogFont(&lf);
   //删除原先字体,创建新字体
   delete m_pfont;
   m_pfont = new CFont;
   m_pfont ->CreateFontIndirect(&lf);
}
if(crColor)
   m_crColor = crColor;
if(nFormat)
   m_nFormat = nFormat;Invalidate(FALSE);
}CFont* CTransparentStatic::GetpFont()
{
return m_pfont;
}COLORREF CTransparentStatic::GetColor()
{
return m_crColor;
}UINT CTransparentStatic::GetFormat()
{
return m_nFormat;
}BEGIN_MESSAGE_MAP(CTransparentStatic, CStatic)
//{{AFX_MSG_MAP(CTransparentStatic)
ON_WM_PAINT()
//}}AFX_MSG_MAP
END_MESSAGE_MAP()/////////////////////////////////////////////////////////////////////////////
// CTransparentStatic message handlersvoid CTransparentStatic::OnPaint() 
{
CPaintDC dc(this); // device context for painting// 取得位置
CRect client_rect;
GetClientRect(client_rect);// 取得文本
CString szText;
GetWindowText(szText);// 取得字体,并选入设备文件
dc.SelectObject(m_pfont);// 用透明背景填充设备文件
dc.SetBkMode(TRANSPARENT);// 显示文字
dc.SetTextColor(m_crColor);
dc.DrawText(szText, client_rect, m_nFormat);
}
这次利用SetOutward成员函数来设置并刷新窗口,这样直接调用SetOutward就可以动态的调整文本的外观了.
比如调整字体颜色为红色:m_Static.SetOutward(NULL, RGB(255, 0, 0), NULL);即可~

解决方案 »

  1.   

    方差是实际值与期望值之差平方的平均值,而标准差是方差平方根。 在实际计算中,我们用以下公式计算方差。   方差是各个数据与平均数之差的平方的平均数,即 s^2=1/n[(x1-x_)^2+(x2-x_)^2+...+(xn-x_)^2] ,其中,x_表示样本的平均数,n表示样本的数量,^2表示平方,xn表示个体,而s^2就表示方差。   而当用(1/n)[(x1-x_)^2+(x2-x_)^2+...+(xn-x_)^2]作为总体X的方差的估计时,发现其数学期望并不是X的方差,而是X方差的(n-1)/n倍,[1/(n-1)][(x1-x_)^2+(x2-x_)^2+...+(xn-x_)^2]的数学期望才是X的方差,用它作为X的方差的估计具有“无偏性”,所以我们总是用[1/(n-1)]∑(Xi-X~)^2来估计X的方差,并且把它叫做“样本方差”。 
      

  2.   

    当在项目中插入ActiveX控件ClassWizard生成的CWnd的派生类C++类中,可以看到其成员函数的代码中都有对InvokeHelper函数的调用,InvokeHelper函数的第一个参数都和对应的属性或方法在ActiveX控件中的分发(dispatch)ID(标识ActiveX控件的方法或属性的)相对应。通过查看ActiveX控件hlp文件可以发现,ActiveX控件的方法在生存的C++类中都有同名的成员函数与之对应,ActiveX控件的属性都有一组Get和Set函数对其操作,其中ActiveX控件的方法和属性操作与生成的C++类成员函数相关联都是通过InvokeHelper函数的调用来完成的,InvokeHelper函数的第一个参数是由Component Gallery(控件提供者)提供的。因为经过这样的处理,所以我们如果要调用ActiveX控件的方法或对其属性进行取和设置操作,只需调用生成的C++类对应的成员函数便可。   下面对InvokeHelper单独说明:   CWnd::InvokeHelper   void InvokeHelper( DISPID dwDispID, WORD wFlags, VARTYPE vtRet, void* pvRet, const BYTE* pbParamInfo, ... );   说明:   Call this member function to invoke the OLE control method or property specified by dwDispID, in the context specified by wFlags.   其中参数:   dwDispID:   //Identifies the method or property to be invoked. This value is usually supplied by Component Gallery.   wFlags:可以为下面些值,指明调用InvokeHelper的目的。   //[ DISPATCH_METHOD ] The member is invoked as a method. If a property has the same name, both this and the DISPATCH_PROPERTYGET flag may be set.   [ DISPATCH_PROPERTYGET ] The member is retrieved as a property or data member.   [ DISPATCH_PROPERTYPUT ] The member is changed as a property or data member.   [ DISPATCH_PROPERTYPUTREF ] The member is changed by a reference assignment, rather than a value assignment. This flag is valid only when the property accepts a reference to an object.   vtRet:   //Specifies the type of the return value.   VT_EMPTY void   VT_I2 short   VT_I4 long   VT_R4 float   VT_R8 double   VT_CY CY   VT_DATE DATE   VT_BSTR BSTR   VT_DISPATCH LPDISPATCH   VT_ERROR SCODE   VT_BOOL BOOL   VT_VARIANT VARIANT   VT_UNKNOWN LPUNKNOWN   pvRet:   //Address of the variable that will that will receive the property value or return value. It must match the type specified by vtRet.   pbParamInfo:一般都设置为NULL   //Pointer to a null-terminated string of bytes specifying the types of the parameters following pbParamInfo.   specifies the types of the parameters passed to the method or property.   ...:   //Variable List of parameters, of types specified in pbParamInfo.   InvokeHelper()函数的用法   1、播放文件的函数:   void CActiveMovie3::Run()   {   InvokeHelper(0x60020001, DISPATCH_METHOD, VT_EMPTY, NULL, NULL);   }   2、暂停播放的函数: void CActiveMovie3::Pause()   {   InvokeHelper(0x60020002, DISPATCH_METHOD, VT_EMPTY, NULL, NULL);   }   4、停止播放的函数: void CActiveMovie3::Stop()   {   InvokeHelper(0x60020003, DISPATCH_METHOD, VT_EMPTY, NULL, NULL);   } 
      

  3.   

    LZ 我不明白这个CStatic不是本来就透明的嘛?另外:代码里面资源泄漏了,你delete m_pfont,内存里的选入对象应该释放不出来的吧...