ColorBtn.cpp
资源名称:44757463.rar [点击查看]
上传用户:lj3531212
上传日期:2007-06-18
资源大小:346k
文件大小:2k
源码类别:
绘图程序
开发平台:
Visual C++
- // 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);
- }