📄 linecolor.cpp
字号:
// LineColor.cpp : implementation file
//
#include "stdafx.h"
#include "Draw.h"
#include "LineColor.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CLineColor dialog
CLineColor::CLineColor(CWnd* pParent /*=NULL*/)
: CDialog(CLineColor::IDD, pParent)
{
//{{AFX_DATA_INIT(CLineColor)
// NOTE: the ClassWizard will add member initialization here
//}}AFX_DATA_INIT
}
void CLineColor::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CLineColor)
// NOTE: the ClassWizard will add DDX and DDV calls here
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CLineColor, CDialog)
//{{AFX_MSG_MAP(CLineColor)
ON_BN_CLICKED(IDC_BUTTON1, OnButton1)
ON_WM_HSCROLL()
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CLineColor message handlers
void CLineColor::OnButton1()
{
// TODO: Add your control notification handler code here
CColorDialog dlg;
if (dlg.DoModal()==IDOK)
{
CStatic *pic=(CStatic*)GetDlgItem(IDC_STATIC1);
CRect rect;
pic->GetClientRect(rect);
CDC *dc=pic->GetDC();
CBrush newbrush,*oldbrush;
color=dlg.GetColor();
newbrush.CreateSolidBrush(color);
oldbrush=dc->SelectObject(&newbrush);
dc->Rectangle(rect);
dc->SelectObject(oldbrush);
}
}
BOOL CLineColor::OnInitDialog()
{
CDialog::OnInitDialog();
// TODO: Add extra initialization here
CScrollBar *s1,*s2,*s3;
s1=(CScrollBar*)GetDlgItem(IDC_SCROLLBAR1);
s1->SetScrollRange(0,255);
s1->SetScrollPos(0);
s2=(CScrollBar*)GetDlgItem(IDC_SCROLLBAR2);
s2->SetScrollRange(0,255);
s2->SetScrollPos(0);
s3=(CScrollBar*)GetDlgItem(IDC_SCROLLBAR3);
s3->SetScrollRange(0,255);
s3->SetScrollPos(0);
return TRUE; // return TRUE unless you set the focus to a control
// EXCEPTION: OCX Property Pages should return FALSE
}
void CLineColor::OnHScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar)
{
// TODO: Add your message handler code here and/or call default
CScrollBar *s1=(CScrollBar*)GetDlgItem(IDC_SCROLLBAR1);
r=s1->GetScrollPos();
CScrollBar *s2=(CScrollBar*)GetDlgItem(IDC_SCROLLBAR2);
g=s2->GetScrollPos();
CScrollBar *s3=(CScrollBar*)GetDlgItem(IDC_SCROLLBAR3);
b=s3->GetScrollPos();
if (pScrollBar->GetDlgCtrlID()==IDC_SCROLLBAR1)
{
switch (nSBCode)
{
case SB_THUMBTRACK:
r=nPos;
break;
case SB_LINELEFT:
r-=1;
break;
case SB_LINERIGHT:
r+=1;
break;
case SB_PAGELEFT:
r-=3;
break;
case SB_PAGERIGHT:
r+=3;
break;
default:
break;
}
if (r<0)
r=0;
if (r>255)
r=255;
s1->SetScrollPos(r);
color=RGB(r,g,b);
}
if (pScrollBar->GetDlgCtrlID()==IDC_SCROLLBAR2)
{
switch (nSBCode)
{
case SB_THUMBTRACK:
g=nPos;
break;
case SB_LINELEFT:
g-=1;
break;
case SB_LINERIGHT:
g+=1;
break;
case SB_PAGELEFT:
g-=3;
break;
case SB_PAGERIGHT:
g+=3;
break;
default:
break;
}
if (g<0)
g=0;
if (g>255)
g=255;
s2->SetScrollPos(g);
color=RGB(r,g,b);
}
if (pScrollBar->GetDlgCtrlID()==IDC_SCROLLBAR3)
{
switch (nSBCode)
{
case SB_THUMBTRACK:
b=nPos;
break;
case SB_LINELEFT:
b-=1;
break;
case SB_LINERIGHT:
b+=1;
break;
case SB_PAGELEFT:
b-=3;
break;
case SB_PAGERIGHT:
b+=3;
break;
default:
break;
}
if (b<0)
b=0;
if (b>255)
b=255;
s3->SetScrollPos(b);
color=RGB(r,g,b);
}
CStatic *pic=(CStatic*)GetDlgItem(IDC_STATIC1);
CRect rect;
pic->GetClientRect(rect);
CDC *dc=pic->GetDC();
CBrush newbrush,*oldbrush;
newbrush.CreateSolidBrush(color);
oldbrush=dc->SelectObject(&newbrush);
dc->Rectangle(rect);
dc->SelectObject(oldbrush);
CDialog::OnHScroll(nSBCode, nPos, pScrollBar);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -