透明的CEdit控件

来源:互联网 发布:arduino单片机 编辑:程序博客网 时间:2024/04/24 04:04

透明的CEdit控件

动手做了一个透明的CEdit控件,发现远没有网上所说的那么复杂,很奇怪的说!

思路很简单,就是让控件处理以下反射消息CtlColo就可以了。

代码如下:

TransparentEdit.h

#pragma once

// CTransparentEdit

class CTransparentEdit : public CRichEditCtrl
{
 DECLARE_DYNAMIC(CTransparentEdit)

public:
 CTransparentEdit();
 virtual ~CTransparentEdit();

protected:
 DECLARE_MESSAGE_MAP()
public:
 afx_msg HBRUSH CtlColor(CDC* pDC, UINT nCtlColor);
};


TransparentEdit.cpp

// TransparentEdit.cpp : implementation file
//

#include "stdafx.h"
#include "TransparentEdit.h"

// CTransparentEdit

IMPLEMENT_DYNAMIC(CTransparentEdit, CRichEditCtrl)
CTransparentEdit::CTransparentEdit()
{
}

CTransparentEdit::~CTransparentEdit()
{
}

BEGIN_MESSAGE_MAP(CTransparentEdit, CRichEditCtrl)
 ON_WM_CTLCOLOR_REFLECT()
END_MESSAGE_MAP()

// CTransparentEdit message handlers

HBRUSH CTransparentEdit::CtlColor(CDC* pDC, UINT nCtlColor)
{
 // TODO:  Change any attributes of the DC here

 // TODO:  Return a non-NULL brush if the parent's handler should not be called
 pDC->SetBkMode(TRANSPARENT);
 pDC->SetTextColor(RGB(255,0,0));
 return HBRUSH(GetStockObject(NULL_BRUSH));
}

原创粉丝点击