一个基于对话框的程序,背景为一张位图,如何使Static Text的背景透明? 一个基于对话框的程序,把背景设为一张位图,想在上面写几个字,可是Static Text是灰色的,遮住了背景。请问如何使Static Text的背景透明? 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 重载OnCtlColorHBRUSH CXXXXDlg::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor) { HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor); // TODO: Change any attributes of the DC here if(nCtlColor == CTLCOLOR_STATIC && pWnd->GetDlgCtrlID() == IDC_XXX_STATIC) { // IDC_XXX_STATIC 为你想要设为透明的控件ID pDC->SetBkMode(TRANSPARENT); return (HBRUSH)GetStockObject(NULL_BRUSH); } 请问我生成的基于对话框的程序怎么没有OnCtlColor函数? 自己在类里面重载添加OnCtlColor函数 给你个类// Label.cpp : implementation file//#include "stdafx.h"#include "Label.h"#ifdef _DEBUG#define new DEBUG_NEW#undef THIS_FILEstatic char THIS_FILE[] = __FILE__;#endif/////////////////////////////////////////////////////////////////////////////// CLabelCLabel::CLabel(){ m_pBkBrush = NULL; m_crBkColor = RGB(255, 255, 255); m_bTransParent = FALSE;}CLabel::~CLabel(){ if (m_pBkBrush != NULL) { m_pBkBrush->DeleteObject(); delete m_pBkBrush; }}BEGIN_MESSAGE_MAP(CLabel, CStatic) //{{AFX_MSG_MAP(CLabel) ON_WM_CTLCOLOR_REFLECT() //}}AFX_MSG_MAPEND_MESSAGE_MAP()/////////////////////////////////////////////////////////////////////////////// CLabel message handlersHBRUSH CLabel::CtlColor(CDC* pDC, UINT nCtlColor) { if (m_bSetTextColor == TRUE) { pDC->SetTextColor(m_crColor); } if (m_bTransParent == FALSE) { pDC->SetBkMode(TRANSPARENT); if (m_pBkBrush != NULL && m_pBkBrush->GetSafeHandle() != NULL) { pDC->SetBkColor(m_crBkColor); return static_cast<HBRUSH>(m_pBkBrush->GetSafeHandle()); } else { return NULL; } } HBRUSH hbr; pDC->SetBkMode(TRANSPARENT); hbr=(HBRUSH)::GetStockObject(NULL_BRUSH); return hbr;}void CLabel::SetBkColor(COLORREF crBkColor){ m_crBkColor = crBkColor; if (m_pBkBrush == NULL) { m_pBkBrush = new CBrush; } else if (m_pBkBrush->GetSafeHandle() != NULL) { m_pBkBrush->DeleteObject(); } m_pBkBrush->CreateSolidBrush(crBkColor); m_bTransParent = FALSE;}//设置透明底色void CLabel::SetTransParent(BOOL bTransParent){ m_bTransParent = bTransParent;}//设置字体的颜色void CLabel::SetTextColor(COLORREF cr){ m_crColor = cr; m_bSetTextColor = TRUE;} #if !defined(AFX_LABEL_H__B2852342_7F9B_4FA0_8A07_19A4BE8519CD__INCLUDED_)#define AFX_LABEL_H__B2852342_7F9B_4FA0_8A07_19A4BE8519CD__INCLUDED_#if _MSC_VER > 1000#pragma once#endif // _MSC_VER > 1000// Label.h : header file///////////////////////////////////////////////////////////////////////////////// CLabel windowclass CLabel : public CStatic{public: CLabel(); virtual ~CLabel(); CWnd * m_pWnd; void SetBkColor(COLORREF crBkColor); void SetTransParent(BOOL bTransParent); void SetTextColor(COLORREF cr);private: CBrush *m_pBkBrush; COLORREF m_crBkColor; BOOL m_bTransParent; BOOL m_bSetTextColor; COLORREF m_crColor;public:// Overrides // ClassWizard generated virtual function overrides //{{AFX_VIRTUAL(CLabel) //}}AFX_VIRTUAL // Generated message map functionsprotected: //{{AFX_MSG(CLabel) afx_msg HBRUSH CtlColor(CDC* pDC, UINT nCtlColor); //}}AFX_MSG DECLARE_MESSAGE_MAP()};///////////////////////////////////////////////////////////////////////////////{{AFX_INSERT_LOCATION}}// Microsoft Visual C++ will insert additional declarations immediately before the previous line.#endif // !defined(AFX_LABEL_H__B2852342_7F9B_4FA0_8A07_19A4BE8519CD__INCLUDED_) 0xC015000F:正在被停用的激活上下文不是最近激活的bug OCX 怎么抛出事件 一个WIN32的问题 请问如何实现橡皮筋功能? 用CAsyncSocket开发的Udp通信程序能与unix服务器通信吗? 菜鸟问题:请教TV_ITEM的问题. 怎样取得socket缓冲区中数据的字节数? 在线急等答案!!MFC鼠标画椭圆!!!! 用那个函数计算一个类或者一个变量所占的字节最好? 怎样理解DC 请问:怎样获得窗口的后代窗口句柄? 图像问题,大家帮帮忙
HBRUSH CXXXXDlg::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
{
HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor);
// TODO: Change any attributes of the DC here
if(nCtlColor == CTLCOLOR_STATIC && pWnd->GetDlgCtrlID() == IDC_XXX_STATIC)
{ // IDC_XXX_STATIC 为你想要设为透明的控件ID
pDC->SetBkMode(TRANSPARENT);
return (HBRUSH)GetStockObject(NULL_BRUSH);
}
// Label.cpp : implementation file
//#include "stdafx.h"
#include "Label.h"#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif/////////////////////////////////////////////////////////////////////////////
// CLabelCLabel::CLabel()
{
m_pBkBrush = NULL;
m_crBkColor = RGB(255, 255, 255);
m_bTransParent = FALSE;
}CLabel::~CLabel()
{
if (m_pBkBrush != NULL)
{
m_pBkBrush->DeleteObject();
delete m_pBkBrush;
}
}BEGIN_MESSAGE_MAP(CLabel, CStatic)
//{{AFX_MSG_MAP(CLabel)
ON_WM_CTLCOLOR_REFLECT()
//}}AFX_MSG_MAP
END_MESSAGE_MAP()/////////////////////////////////////////////////////////////////////////////
// CLabel message handlersHBRUSH CLabel::CtlColor(CDC* pDC, UINT nCtlColor)
{
if (m_bSetTextColor == TRUE)
{
pDC->SetTextColor(m_crColor);
} if (m_bTransParent == FALSE)
{
pDC->SetBkMode(TRANSPARENT);
if (m_pBkBrush != NULL && m_pBkBrush->GetSafeHandle() != NULL)
{
pDC->SetBkColor(m_crBkColor);
return static_cast<HBRUSH>(m_pBkBrush->GetSafeHandle());
}
else
{
return NULL;
}
} HBRUSH hbr; pDC->SetBkMode(TRANSPARENT);
hbr=(HBRUSH)::GetStockObject(NULL_BRUSH); return hbr;
}void CLabel::SetBkColor(COLORREF crBkColor)
{
m_crBkColor = crBkColor; if (m_pBkBrush == NULL)
{
m_pBkBrush = new CBrush;
}
else if (m_pBkBrush->GetSafeHandle() != NULL)
{
m_pBkBrush->DeleteObject();
} m_pBkBrush->CreateSolidBrush(crBkColor); m_bTransParent = FALSE;
}//设置透明底色
void CLabel::SetTransParent(BOOL bTransParent)
{
m_bTransParent = bTransParent;
}//设置字体的颜色
void CLabel::SetTextColor(COLORREF cr)
{
m_crColor = cr;
m_bSetTextColor = TRUE;
}
#define AFX_LABEL_H__B2852342_7F9B_4FA0_8A07_19A4BE8519CD__INCLUDED_#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
// Label.h : header file
///////////////////////////////////////////////////////////////////////////////
// CLabel windowclass CLabel : public CStatic
{
public:
CLabel();
virtual ~CLabel(); CWnd * m_pWnd; void SetBkColor(COLORREF crBkColor);
void SetTransParent(BOOL bTransParent);
void SetTextColor(COLORREF cr);private:
CBrush *m_pBkBrush;
COLORREF m_crBkColor; BOOL m_bTransParent;
BOOL m_bSetTextColor;
COLORREF m_crColor;public:
// Overrides
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(CLabel)
//}}AFX_VIRTUAL // Generated message map functions
protected:
//{{AFX_MSG(CLabel)
afx_msg HBRUSH CtlColor(CDC* pDC, UINT nCtlColor);
//}}AFX_MSG DECLARE_MESSAGE_MAP()
};///////////////////////////////////////////////////////////////////////////////{{AFX_INSERT_LOCATION}}
// Microsoft Visual C++ will insert additional declarations immediately before the previous line.#endif // !defined(AFX_LABEL_H__B2852342_7F9B_4FA0_8A07_19A4BE8519CD__INCLUDED_)