www.pudn.com > 44757463.rar > ColorBtn.cpp
// ColorBtn.cpp : implementation file
//
#include "stdafx.h"
#include "graphsoft.h"
#include "ColorBtn.h"
#include "ColorSetDlg.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CColorBtn
CColorBtn::CColorBtn()
{
m_pColorSetDlg=new CColorSetDlg(0,this);
m_pColorSetDlg->Create(CColorSetDlg::IDD,this);
m_color=RGB(0,255,0);
}
CColorBtn::~CColorBtn()
{
delete m_pColorSetDlg;
}
BEGIN_MESSAGE_MAP(CColorBtn, CButton)
//{{AFX_MSG_MAP(CColorBtn)
ON_CONTROL_REFLECT(BN_CLICKED, OnClicked)
ON_MESSAGE(WM_SETCOLOR,OnSetColor)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CColorBtn message handlers
void CColorBtn::DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct)
{
// TODO: Add your code to draw the specified item
CRect rect=lpDrawItemStruct->rcItem;
CDC *pDC=CDC::FromHandle(lpDrawItemStruct->hDC);
CBrush brush,*pOldBrush;
if(this->IsWindowEnabled()){
brush.CreateSolidBrush(m_color);
}else{
brush.CreateSolidBrush(RGB(180,180,180));//ûÓб»¼¤»î
}
pOldBrush=pDC->SelectObject(&brush);
pDC->Rectangle(&rect);
pDC->SelectObject(pOldBrush);
}
void CColorBtn::OnClicked()
{
// TODO: Add your control notification handler code here
CRect rect;
GetWindowRect(&rect);
m_pColorSetDlg->SetWindowPos(&wndTopMost, rect.left,rect.bottom, 0, 0, SWP_NOSIZE|SWP_NOZORDER);
m_pColorSetDlg->ShowWindow(SW_SHOW);
m_pColorSetDlg->SetFocus();
}
void CColorBtn::OnSetColor(WPARAM wParam,LPARAM lParam)
{
COLORREF color=(COLORREF)wParam;
m_color=color;
this->Invalidate(TRUE);
}