【VC开源代码栏目提醒】:网学会员鉴于大家对VC开源代码十分关注,论文会员在此为大家搜集整理了“CLRPAGE.CPP”一文,供大家参考学习
// ColorPage.cpp : implementation file
//
#include "stdafx.h"
#include "wzd.h"
#include "ClrPage.h"
#include "WzdPrjct.h"
#include "MainFrm.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CColorPage property page
IMPLEMENT_DYNCREATE(CColorPage, CPropertyPage)
CColorPage::CColorPage() : CPropertyPage(CColorPage::IDD)
{
//{{AFX_DATA_INIT(CColorPage)
//}}AFX_DATA_INIT
}
CColorPage::~CColorPage()
{
}
void CColorPage::DoDataExchange(CDataExchange* pDX)
{
CPropertyPage::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CColorPage)
DDX_Control(pDX, IDC_COLOR1_DISPLAY, m_ctrlColor1Display);
DDX_Control(pDX, IDC_COLOR2_DISPLAY, m_ctrlColor2Display);
DDX_Control(pDX, IDC_BLUE_SLIDER1, m_ctrlBlueSlider1);
DDX_Control(pDX, IDC_GRN_SLIDER1, m_ctrlGrnSlider1);
DDX_Control(pDX, IDC_RED_SLIDER1, m_ctrlRedSlider1);
DDX_Control(pDX, IDC_BLUE_SLIDER2, m_ctrlBlueSlider2);
DDX_Control(pDX, IDC_GRN_SLIDER2, m_ctrlGrnSlider2);
DDX_Control(pDX, IDC_RED_SLIDER2, m_ctrlRedSlider2);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CColorPage, CPropertyPage)
//{{AFX_MSG_MAP(CColorPage)
ON_WM_VSCROLL()
ON_WM_PAINT()
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CColorPage message handlers
BOOL CColorPage::OnInitDialog()
{
CPropertyPage::OnInitDialog();
// setup slider bars
m_ctrlBlueSlider1.SetTicFreq(15);
m_ctrlBlueSlider1.SetRange(0,255,TRUE);
m_ctrlBlueSlider1.SetPos(255-GetBValue(m_rgbColors[COLOR1_COLOR]));
m_ctrlGrnSlider1.SetTicFreq(15);
m_ctrlGrnSlider1.SetRange(0,255,TRUE);
m_ctrlGrnSlider1.SetPos(255-GetGValue(m_rgbColors[COLOR1_COLOR]));
m_ctrlRedSlider1.SetTicFreq(15);
m_ctrlRedSlider1.SetRange(0,255,TRUE);
m_ctrlRedSlider1.SetPos(255-GetRValue(m_rgbColors[COLOR1_COLOR]));
m_ctrlBlueSlider2.SetTicFreq(15);
m_ctrlBlueSlider2.SetRange(0,255,TRUE);
m_ctrlBlueSlider2.SetPos(255-GetBValue(m_rgbColors[COLOR2_COLOR]));
m_ctrlGrnSlider2.SetTicFreq(15);
m_ctrlGrnSlider2.SetRange(0,255,TRUE);
m_ctrlGrnSlider2.SetPos(255-GetGValue(m_rgbColors[COLOR2_COLOR]));
m_ctrlRedSlider2.SetTicFreq(15);
m_ctrlRedSlider2.SetRange(0,255,TRUE);
m_ctrlRedSlider2.SetPos(255-GetRValue(m_rgbColors[COLOR2_COLOR]));
return TRUE; // return TRUE unless you set the focus to a control
// EXCEPTION: OCX Property Pages should return FALSE
}
void CColorPage::OnPaint()
{
CPaintDC dc(this); // device context for painting
DrawColorRects();
}
void CColorPage::OnVScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar)
{
int i;
int color=0;
UINT id = pScrollBar->GetDlgCtrlID();
switch (nSBCode)
{
case SB_TOP:
color=255;
break;
case SB_BOTTOM:
color=0;
break;
case SB_LINEDOWN:
case SB_LINEUP:
case SB_PAGEDOWN:
case SB_PAGEUP:
switch (id)
{
case IDC_RED_SLIDER1:
color=m_ctrlRedSlider1.GetPos();
break;
case IDC_BLUE_SLIDER1:
color=m_ctrlBlueSlider1.GetPos();
break;
case IDC_GRN_SLIDER1:
color=m_ctrlGrnSlider1.GetPos();
break;
case IDC_RED_SLIDER2:
color=m_ctrlRedSlider2.GetPos();
break;
case IDC_BLUE_SLIDER2:
color=m_ctrlBlueSlider2.GetPos();
break;
case IDC_GRN_SLIDER2:
color=m_ctrlGrnSlider2.GetPos();
break;
}
break;
case SB_THUMBPOSITION:
case SB_THUMBTRACK:
color=nPos;
break;
case SB_ENDSCROLL:
break;
}
if (nSBCode!=SB_ENDSCROLL)
{
color=255-color;
switch (id)
{
case IDC_RED_SLIDER1:
case IDC_RED_SLIDER2:
i=COLOR1_COLOR;
if (id==IDC_RED_SLIDER2) i=COLOR2_COLOR;
m_rgbColors[i]=RGB(color,GetGValue(m_rgbColors[i]),GetBValue(m_rgbColors[i]));
break;
case IDC_BLUE_SLIDER1:
case IDC_BLUE_SLIDER2:
i=COLOR1_COLOR;
if (id==IDC_BLUE_SLIDER2) i=COLOR2_COLOR;
m_rgbColors[i]=RGB(GetRValue(m_rgbColors[i]),GetGValue(m_rgbColors[i]),color);
break;
case IDC_GRN_SLIDER1:
case IDC_GRN_SLIDER2:
i=COLOR1_COLOR;
if (id==IDC_GRN_SLIDER2) i=COLOR2_COLOR;
m_rgbColors[i]=RGB(GetRValue(m_rgbColors[i]),color,GetBValue(m_rgbColors[i]));
break;
}
// select palette into a device context
// (NOTE: you MUST select a palette into a device context for AnimatePalette() to work!)
CDC *pDC=GetDC();
CMainFrame *pFrame=(CMainFrame *)AfxGetMainWnd();
CPalette *pPalette=pFrame->GetPalette();
CPalette *pOPalette=pDC->SelectPalette(pPalette,FALSE);
// add new color to palette using animation
PALETTEENTRY pentry;
pentry.peRed=GetRValue(m_rgbColors[i]);
pentry.peGreen=GetGValue(m_rgbColors[i]);
pentry.peBlue=GetBValue(m_rgbColors[i]);
pentry.peFlags=PC_RESERVED;
pPalette->AnimatePalette(i,1,&pentry);
// reselect old palette
pDC->SelectPalette(pOPalette,FALSE);
// change color in CMainFrame
pFrame->SetColorRef(i,m_rgbColors[i]);
}
CPropertyPage::OnVScroll(nSBCode, nPos, pScrollBar);
}
void CColorPage::DrawColorRects()
{
// create a solid brush using our palette
CDC *pDC=GetDC();
CMainFrame *pFrame=(CMainFrame *)AfxGetMainWnd();
CPalette *pPalette=pFrame->GetPalette();
CPalette *pOPalette=pDC->SelectPalette(pPalette,FALSE);
CBrush brush1(PALETTEINDEX(COLOR1_COLOR));
CBrush brush2(PALETTEINDEX(COLOR2_COLOR));
// draw the rectangle
CRect rect;
m_ctrlColor1Display.GetWindowRect(&rect);
ScreenToClient(&rect);
rect.DeflateRect(2,2,2,2);
CBrush *pOBrush=pDC->SelectObject(&brush1);
pDC->Rectangle(&rect);
m_ctrlColor2Display.GetWindowRect(&rect);
ScreenToClient(&rect);
rect.DeflateRect(2,2,2,2);
pDC->SelectObject(&brush2);
pDC->Rectangle(&rect);
// unselect everything
pDC->SelectObject(pOBrush);
pDC->SelectPalette(pOPalette,FALSE);
ReleaseDC(pDC);
}
上一篇:
ClrGradientPrgssCtrlDlg.cpp
下一篇:
结合教学实际谈对小学音标教学的心得