기본카테고리

[VC++]배경이 투명한 컨트롤 만들기

DevAdd 2010. 8. 11. 10:25




#pragma once


// CTransparentStatic

class CTransparentStatic : public CStatic
{
DECLARE_DYNAMIC(CTransparentStatic)

public:
CTransparentStatic();
virtual ~CTransparentStatic();

protected:

afx_msg LRESULT OnSetText(WPARAM,LPARAM);

 

afx_msg HBRUSH CtlColor(CDC* /*pDC*/, UINT /*nCtlColor*/)

;
DECLARE_MESSAGE_MAP()
};


// TransparentStatic.cpp : implementation file
//

#include "stdafx.h"
#include "TransparentStatic.h"


// CTransparentStatic

IMPLEMENT_DYNAMIC(CTransparentStatic, CStatic)
CTransparentStatic::CTransparentStatic()
{
}

CTransparentStatic::~CTransparentStatic()
{
}


BEGIN_MESSAGE_MAP(CTransparentStatic, CStatic)
ON_MESSAGE(WM_SETTEXT,OnSetText)
ON_WM_CTLCOLOR_REFLECT()
END_MESSAGE_MAP()

 

// CTransparentStatic message handlers

LRESULT CTransparentStatic::OnSetText(WPARAM wParam,LPARAM lParam)
{
LRESULT Result = Default();
CRect Rect;
GetWindowRect(&Rect);
GetParent()->ScreenToClient(&Rect);

GetParent()->InvalidateRect(&Rect);
GetParent()->UpdateWindow();


return Result;
}


HBRUSH CTransparentStatic::CtlColor(CDC* pDC, UINT /*nCtlColor*/)
{

pDC->SetBkMode(TRANSPARENT);
return (HBRUSH)GetStockObject(NULL_BRUSH);

}