www.pudn.com > 44757463.rar > FillSetDlg.cpp
// FillSetDlg.cpp : implementation file
//
#include "stdafx.h"
#include "GraphSoft.h"
#include "FillSetDlg.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CFillSetDlg dialog
CFillSetDlg::CFillSetDlg(CWnd* pParent /*=NULL*/)
: CDialog(CFillSetDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CFillSetDlg)
// NOTE: the ClassWizard will add member initialization here
//}}AFX_DATA_INIT
m_NoFillRect.left=1;
m_NoFillRect.right=30;
m_NoFillRect.top=0;
m_NoFillRect.bottom=31;
m_SolidRect.left=0;
m_SolidRect.right=30;
m_SolidRect.top=31;
m_SolidRect.bottom=61;
m_nOld=0;
m_nCurrent=0;
m_nSelect=-1;
m_nMargin=1;
m_pWndParent=pParent;
}
void CFillSetDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CFillSetDlg)
// NOTE: the ClassWizard will add DDX and DDV calls here
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CFillSetDlg, CDialog)
//{{AFX_MSG_MAP(CFillSetDlg)
ON_WM_KILLFOCUS()
ON_WM_LBUTTONDOWN()
ON_WM_LBUTTONUP()
ON_WM_MOUSEMOVE()
ON_WM_PAINT()
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CFillSetDlg message handlers
BOOL CFillSetDlg::OnInitDialog()
{
CDialog::OnInitDialog();
// TODO: Add extra initialization here
return TRUE; // return TRUE unless you set the focus to a control
// EXCEPTION: OCX Property Pages should return FALSE
}
void CFillSetDlg::OnKillFocus(CWnd* pNewWnd)
{
CDialog::OnKillFocus(pNewWnd);
// TODO: Add your message handler code here
this->PostMessage(WM_COMMAND,IDCANCEL) ;
}
void CFillSetDlg::OnLButtonDown(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
int i ;
if(m_NoFillRect.PtInRect(point)) {
SetStyle(0);
this->PostMessage(WM_COMMAND,IDCANCEL) ;
}else if(m_SolidRect.PtInRect(point)) {
SetStyle(1);
this->PostMessage(WM_COMMAND,IDCANCEL) ;
}
CDialog::OnLButtonDown(nFlags, point);
}
void CFillSetDlg::OnLButtonUp(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
CDialog::OnLButtonUp(nFlags, point);
}
void CFillSetDlg::OnMouseMove(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
BOOL flag = FALSE ;
if(m_NoFillRect.PtInRect(point)) {
if(this->m_nSelect!=0) {
CClientDC dc(this);
int old = m_nSelect ;
m_nSelect = -1 ;
if(old>=0) draw_cell(&dc,old) ;
m_nSelect = 0 ;
draw_cell(&dc,0) ;
}
flag = TRUE ;
}
if(!flag){
if(m_SolidRect.PtInRect(point)) {
if(m_nSelect!=1) {
CClientDC dc(this);
int old = m_nSelect ;
m_nSelect = -1 ;
if(old>=0) draw_cell(&dc,old) ;
m_nSelect = 1 ;
draw_cell(&dc,1) ;
}
flag = TRUE ;
}
}
CDialog::OnMouseMove(nFlags, point);
}
void CFillSetDlg::OnPaint()
{
CPaintDC dc(this); // device context for painting
// TODO: Add your message handler code here
draw_cell(&dc,0);
draw_cell(&dc,1) ;
// Do not call CDialog::OnPaint() for painting messages
}
BOOL CFillSetDlg::GetCellRect(int i,CRect* pRect)
{
BOOL bRltVal=FALSE;
if(i==0){
*pRect=m_NoFillRect;
bRltVal=TRUE;
}else if(i==1){
*pRect=m_SolidRect;
bRltVal=TRUE;
}
return bRltVal;
}
void CFillSetDlg::draw_cell(CDC* pDC,int i)
{
if(i==0) {
CRect rect = m_NoFillRect ;
// Fill background
pDC->FillSolidRect(rect, ::GetSysColor(COLOR_3DFACE));
if (i==this->m_nSelect) pDC->DrawEdge(rect, BDR_RAISEDINNER, BF_RECT);
else if (i==this->m_nCurrent) pDC->DrawEdge(rect, BDR_SUNKENOUTER, BF_RECT);
//Fill Black color
CPen pen;
pen.CreatePen(PS_SOLID, 1, ::GetSysColor(COLOR_3DSHADOW));
CBrush brush ;
brush.CreateSolidBrush(::GetSysColor(COLOR_3DFACE)) ;
CPen* pOldPen = (CPen*) pDC->SelectObject(&pen);
CBrush* pOldBrush = (CBrush*) pDC->SelectObject(&brush);
rect.DeflateRect(2*m_nMargin,2*m_nMargin);
pDC->Rectangle(rect);
pDC->SelectObject(pOldBrush);
pDC->SelectObject(pOldPen);
}else if(i==1) {
CRect rect = m_SolidRect ;
// Fill background
pDC->FillSolidRect(rect, ::GetSysColor(COLOR_3DFACE));
if (i==this->m_nSelect) pDC->DrawEdge(rect, BDR_RAISEDINNER, BF_RECT);
else if (i==this->m_nCurrent) pDC->DrawEdge(rect, BDR_SUNKENOUTER, BF_RECT);
//Fill Black color
CPen pen;
pen.CreatePen(PS_SOLID, 1, ::GetSysColor(COLOR_3DSHADOW));
CBrush brush ;
brush.CreateSolidBrush(RGB(0,0,0)) ;
CPen* pOldPen = (CPen*) pDC->SelectObject(&pen);
CBrush* pOldBrush = (CBrush*) pDC->SelectObject(&brush);
rect.DeflateRect(2*m_nMargin,2*m_nMargin);
pDC->Rectangle(rect);
pDC->SelectObject(pOldBrush);
pDC->SelectObject(pOldPen);
}
}
void CFillSetDlg::Init()
{
m_nSelect=-1;
}
void CFillSetDlg::SetStyle(int nStyle)
{
m_nCurrent=nStyle;
if(m_pWndParent!=NULL)
m_pWndParent->PostMessage(WM_SETFILLSTYLE,WPARAM(nStyle));
}