// SpinnerTBView.cpp : implementation of the CSpinnerTBView class
#include "stdafx.h"
#include "SpinnerTB.h"
#include "SpinnerTBDoc.h"
#include "SpinnerTBView.h"
#include "MainFrm.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CSpinnerTBView
IMPLEMENT_DYNCREATE(CSpinnerTBView, CView)
BEGIN_MESSAGE_MAP(CSpinnerTBView, CView)
//{{AFX_MSG_MAP(CSpinnerTBView)
ON_WM_PAINT()
ON_WM_CREATE()
ON_WM_ERASEBKGND()
ON_WM_QUERYNEWPALETTE()
ON_WM_PALETTECHANGED()
ON_COMMAND(ID_COLORS_RED, OnColorsRed)
ON_COMMAND(ID_COLORS_GREEN, OnColorsGreen)
ON_COMMAND(ID_COLORS_BLUE, OnColorsBlue)
ON_COMMAND(ID_COLORS_SPINNERS, OnColorsSpinners)
ON_EN_CHANGE(ID_EDIT_R, OnUpdateRed)
ON_EN_CHANGE(ID_EDIT_G, OnUpdateGreen)
ON_EN_CHANGE(ID_EDIT_B, OnUpdateBlue)
ON_EN_CHANGE(ID_EDIT_SLD, OnUpdateGradient)
//}}AFX_MSG_MAP
// Standard printing commands
ON_COMMAND(ID_FILE_PRINT, CView::OnFilePrint)
ON_COMMAND(ID_FILE_PRINT_DIRECT, CView::OnFilePrint)
ON_COMMAND(ID_FILE_PRINT_PREVIEW, CView::OnFilePrintPreview)
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CSpinnerTBView construction/destruction
CSpinnerTBView::CSpinnerTBView()
{
// TODO: add construction code here
}
CSpinnerTBView::~CSpinnerTBView()
{
}
BOOL CSpinnerTBView::PreCreateWindow(CREATESTRUCT& cs)
{
// TODO: Modify the Window class or styles here by modifying
// the CREATESTRUCT cs
return CView::PreCreateWindow(cs);
}
/////////////////////////////////////////////////////////////////////////////
// CSpinnerTBView drawing
void CSpinnerTBView::OnDraw(CDC* pDC)
{
CSpinnerTBDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
}
/////////////////////////////////////////////////////////////////////////////
// CSpinnerTBView printing
BOOL CSpinnerTBView::OnPreparePrinting(CPrintInfo* pInfo)
{
// default preparation
return DoPreparePrinting(pInfo);
}
void CSpinnerTBView::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add extra initialization before printing
}
void CSpinnerTBView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add cleanup after printing
}
/////////////////////////////////////////////////////////////////////////////
// CSpinnerTBView diagnostics
#ifdef _DEBUG
void CSpinnerTBView::AssertValid() const
{
CView::AssertValid();
}
void CSpinnerTBView::Dump(CDumpContext& dc) const
{
CView::Dump(dc);
}
CSpinnerTBDoc* CSpinnerTBView::GetDocument() // non-debug version is inline
{
ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CSpinnerTBDoc)));
return (CSpinnerTBDoc*)m_pDocument;
}
#endif //_DEBUG
/////////////////////////////////////////////////////////////////////////////
// CSpinnerTBView message handlers
void CSpinnerTBView::OnPaint()
{
CRect rect;
GetClientRect (&rect);
rect.OffsetRect (0, 60);
CPaintDC dc (this);
DoDrawText (&dc, &rect);
}
int CSpinnerTBView::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
if (CView::OnCreate(lpCreateStruct) == -1)
return -1;
CClientDC dc (this);
if (dc.GetDeviceCaps (RASTERCAPS) & RC_PALETTE) {
struct {
LOGPALETTE lp;
PALETTEENTRY ape[63];
} pal;
LOGPALETTE* pLP = (LOGPALETTE*) &pal;
pLP->palVersion = 0x300;
pLP->palNumEntries = 64;
for (int i=0; i<64; i++) {
pLP->palPalEntry[i].peRed = 0;
pLP->palPalEntry[i].peGreen = 0;
pLP->palPalEntry[i].peBlue = 255 - (i * 4);
pLP->palPalEntry[i].peFlags = 0;
}
m_palette.CreatePalette (pLP);
}
return 0;
}
BOOL CSpinnerTBView::OnEraseBkgnd(CDC* pDC)
{
CRect rect;
GetClientRect (&rect);
CPalette* pOldPalette;
if ((HPALETTE) m_palette != NULL) {
pOldPalette = pDC->SelectPalette (&m_palette, FALSE);
pDC->RealizePalette ();
}
DoGradientFill (pDC, &rect);
if ((HPALETTE) m_palette != NULL)
pDC->SelectPalette (pOldPalette, FALSE);
return TRUE;
}
BOOL CSpinnerTBView::OnQueryNewPalette ()
{
if ((HPALETTE) m_palette == NULL) // Shouldn't happen, but
return 0; // let's be sure.
CClientDC dc (this);
CPalette* pOldPalette = dc.SelectPalette (&m_palette, FALSE);
UINT nCount;
if (nCount = dc.RealizePalette ())
Invalidate ();
dc.SelectPalette (pOldPalette, FALSE);
return nCount;
}
void CSpinnerTBView::OnPaletteChanged (CWnd* pFocusWnd)
{
if ((HPALETTE) m_palette == NULL) // Shouldn't happen, but
return; // let's be sure.
if (pFocusWnd != this) {
CClientDC dc (this);
CPalette* pOldPalette = dc.SelectPalette (&m_palette, FALSE);
if (dc.RealizePalette ())
Invalidate ();
dc.SelectPalette (pOldPalette, FALSE);
}
}
void CSpinnerTBView::DoGradientFill (CDC* pDC, LPRECT pRect)
{
CSpinnerTBDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
CBrush* pBrush[64];
for (int i=0; i<64; i++)
pBrush[i] = new CBrush (PALETTERGB (pDoc->m_nGradValue,
pDoc->m_nGradValue,
pDoc->m_nGradValue - (i * 4)));
int nWidth = pRect->right - pRect->left;
int nHeight = pRect->bottom - pRect->top;
CRect rect;
for (i=0; i<nHeight; i++) {
rect.SetRect (0, i, nWidth, i + 1);
pDC->FillRect (&rect, pBrush[(i * 63) / nHeight]);
}
AfxGetMainWnd ()->SendMessage (WM_USER_UPDATE_GRADIENT, 0,
(LPARAM) (UINT) pDoc->m_nGradValue);
m_strRGB.Format("Gradient Value: %d ",pDoc->m_nGradValue);
AfxGetMainWnd ()->SendMessage (WM_USER_UPDATE_GRADIENT_STATUS, 0,
(LPARAM) (LPCTSTR) m_strRGB);
for (i=0; i<64; i++)
delete pBrush[i];
}
void CSpinnerTBView::DoDrawText (CDC* pDC, LPRECT pRect)
{
CSpinnerTBDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
CFont font;
font.CreatePointFont (120,
_T ("Comic Sans MS"));
CFont* pOldFont = pDC->SelectObject (&font);
pDC->SetBkMode (TRANSPARENT);
pDC->SetTextColor(pDoc->m_clrTextClr);
pDC->DrawText (pDoc->m_strText, -1, pRect,
DT_CENTER | DT_VCENTER);
pDC->SelectObject (pOldFont);
m_strRGB.Format("Text: Red=%d, Green=%d, Blue=%d.", pDoc->m_nRed, pDoc->m_nGreen, pDoc->m_nBlue);
AfxGetMainWnd ()->SendMessage (WM_USER_UPDATE_COLOR, 0,
(LPARAM) (LPCTSTR) m_strRGB);
AfxGetMainWnd ()->SendMessage (WM_USER_UPDATE_SPINNER_RED, 0,
(LPARAM) (UINT) pDoc->m_nRed);
AfxGetMainWnd ()->SendMessage (WM_USER_UPDATE_SPINNER_GREEN, 0,
(LPARAM) (UINT) pDoc->m_nGreen);
AfxGetMainWnd ()->SendMessage (WM_USER_UPDATE_SPINNER_BLUE, 0,
(LPARAM) (UINT) pDoc->m_nBlue);
}
void CSpinnerTBView::OnColorsRed()
{
// Get a pointer to our Main Frame
// CMainFrame* pFrame = (CMainFrame*) AfxGetApp()->m_pMainWnd;
// ASSERT_VALID(pFrame);
CSpinnerTBDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
pDoc->m_nRed = 255;
pDoc->m_nGreen = 0;
pDoc->m_nBlue = 0;
pDoc->m_clrTextClr = RGB(pDoc->m_nRed, pDoc->m_nGreen, pDoc->m_nBlue);
pDoc->UpdateAllViews(0);
pDoc->SetModifiedFlag();
m_strRGB.Format("Text: Red=%d, Green=%d, Blue=%d.", pDoc->m_nRed, pDoc->m_nGreen, pDoc->m_nBlue);
AfxGetMainWnd ()->SendMessage (WM_USER_UPDATE_COLOR, 0,
(LPARAM) (LPCTSTR) m_strRGB);
AfxGetMainWnd ()->SendMessage (WM_USER_UPDATE_SPINNER_RED, 0,
(LPARAM) (UINT) pDoc->m_nRed);
AfxGetMainWnd ()->SendMessage (WM_USER_UPDATE_SPINNER_GREEN, 0,
(LPARAM) (UINT) pDoc->m_nGreen);
AfxGetMainWnd ()->SendMessage (WM_USER_UPDATE_SPINNER_BLUE, 0,
(LP
没有合适的资源?快使用搜索试试~ 我知道了~
资源推荐
资源详情
资源评论
收起资源包目录
Spin_Slide_ToolBar.rar (35个子文件)
Spin_Slide_ToolBar
SpinnerToolBar.h 2KB
StdAfx.cpp 211B
resource.h 4KB
SpinnerTBDoc.h 2KB
SpinnerTB.dsp 5KB
SpinnerTB.dsw 543B
SpinnerTB.cpp 4KB
SlideToolBar.h 2KB
SpinnerTB.opt 52KB
MainFrm.h 2KB
SpinnerTB.aps 42KB
SpinnerTB.mak 6KB
SpinnerTBView.cpp 13KB
Debug
SpinnerTB.exe 156KB
SpinnerToolBar.cpp 7KB
StdAfx.h 1KB
SpinnerTB.rc 16KB
SpinnerTBView.h 2KB
MainFrm.cpp 6KB
SpinnerTB.ncb 129KB
SpinnerTBDoc.cpp 2KB
res
SpinnerTBDoc.ico 1KB
cursor_slider.cur 326B
Toolbar.bmp 1KB
SpinnerTB.ico 1KB
spinner_bar.bmp 2KB
cursor_spinner.cur 326B
slider_bar.bmp 2KB
SpinnerTB.rc2 401B
SpinnerTB.plg 2KB
ChildFrm.cpp 1KB
SlideToolBar.cpp 7KB
ChildFrm.h 1KB
SpinnerTB.h 1KB
SpinnerTB.dep 2KB
共 35 条
- 1
资源评论
- wrnrunner2012-07-25没看懂怎么用,哎,有教程就好了。
onezeros
- 粉丝: 1087
- 资源: 211
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功