ColorStatic.cpp
上传用户:ywlong9188
上传日期:2022-05-31
资源大小:2656k
文件大小:2k
- // ColorStatic.cpp : implementation file
- //
- #include "stdafx.h"
- #include "ColorStatic.h"
- //#include "rdlg.h"
- #ifdef _DEBUG
- #define new DEBUG_NEW
- #undef THIS_FILE
- static char THIS_FILE[] = __FILE__;
- #endif
- /////////////////////////////////////////////////////////////////////////////
- // CColorStatic
- CColorStatic::CColorStatic()
- {
- }
- CColorStatic::~CColorStatic()
- {
- }
- BEGIN_MESSAGE_MAP(CColorStatic, CStatic)
- //{{AFX_MSG_MAP(CColorStatic)
- ON_WM_LBUTTONDOWN()
- ON_WM_PAINT()
- ON_WM_KEYDOWN()
- //}}AFX_MSG_MAP
- END_MESSAGE_MAP()
- /////////////////////////////////////////////////////////////////////////////
- // CColorStatic message handlers
- void CColorStatic::OnLButtonDown(UINT nFlags, CPoint point)
- {
- if(m_cDlg.DoModal() == IDOK)
- m_color = m_cDlg.GetColor();
- Invalidate(FALSE);
- CStatic::OnLButtonDown(nFlags, point);
- }
- void CColorStatic::SetColor(COLORREF color)
- {
- m_color = color;
- }
- void CColorStatic::GetColor(COLORREF& color)
- {
- color = m_color;
- }
- void CColorStatic::OnPaint()
- {
- CPaintDC dc(this); // device context for painting
-
- // TODO: Add your message handler code here
- CRect client;
- CBrush brush(m_color);
- CBrush* pOld;
- GetClientRect(client);
-
- pOld = dc.SelectObject( &brush );
- dc.Rectangle(client);
- dc.SelectObject(pOld);
- // Do not call CStatic::OnPaint() for painting messages
- }
- void CColorStatic::OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags)
- {
- // TODO: Add your message handler code here and/or call default
- if(nChar == 0x13 ){
- if(m_cDlg.DoModal() == IDOK)
- m_color = m_cDlg.GetColor();
- }
- CStatic::OnKeyDown(nChar, nRepCnt, nFlags);
- }