⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 13_3dlg.cpp

📁 一个小程序
💻 CPP
字号:
// 13_3Dlg.cpp : implementation file
//

#include "stdafx.h"
#include "13_3.h"
#include "13_3Dlg.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CAboutDlg dialog used for App About

class CAboutDlg : public CDialog
{
public:
	CAboutDlg();

// Dialog Data
	//{{AFX_DATA(CAboutDlg)
	enum { IDD = IDD_ABOUTBOX };
	//}}AFX_DATA

	// ClassWizard generated virtual function overrides
	//{{AFX_VIRTUAL(CAboutDlg)
	protected:
	virtual void DoDataExchange(CDataExchange* pDX);    // DDX/DDV support
	//}}AFX_VIRTUAL

// Implementation
protected:
	//{{AFX_MSG(CAboutDlg)
	//}}AFX_MSG
	DECLARE_MESSAGE_MAP()
};

CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
{
	//{{AFX_DATA_INIT(CAboutDlg)
	//}}AFX_DATA_INIT
}

void CAboutDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CAboutDlg)
	//}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
	//{{AFX_MSG_MAP(CAboutDlg)
		// No message handlers
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CMy13_3Dlg dialog

CMy13_3Dlg::CMy13_3Dlg(CWnd* pParent /*=NULL*/)
	: CDialog(CMy13_3Dlg::IDD, pParent)
{
	//{{AFX_DATA_INIT(CMy13_3Dlg)
	//}}AFX_DATA_INIT
	// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
	m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}

void CMy13_3Dlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CMy13_3Dlg)
	DDX_Control(pDX, IDC_RED_EDIT, m_Red_Edit);
	DDX_Control(pDX, IDC_BLUE_EDIT, m_Blue_Edit);
	DDX_Control(pDX, IDC_GREEN_EDIT, m_Green_Edit);
	DDX_Control(pDX, IDC_RED_SCROLLBAR, m_Red_ScrollBar);
	DDX_Control(pDX, IDC_GREEN_SCROLLBAR, m_Green_ScrollBar);
	DDX_Control(pDX, IDC_BLUE_SCROLLBAR, m_Blue_ScrollBar);
	//}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CMy13_3Dlg, CDialog)
	//{{AFX_MSG_MAP(CMy13_3Dlg)
	ON_WM_SYSCOMMAND()
	ON_WM_PAINT()
	ON_WM_QUERYDRAGICON()
	ON_WM_VSCROLL()
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CMy13_3Dlg message handlers

BOOL CMy13_3Dlg::OnInitDialog()
{
	CDialog::OnInitDialog();

	// Add "About..." menu item to system menu.

	// IDM_ABOUTBOX must be in the system command range.
	ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
	ASSERT(IDM_ABOUTBOX < 0xF000);

	CMenu* pSysMenu = GetSystemMenu(FALSE);
	if (pSysMenu != NULL)
	{
		CString strAboutMenu;
		strAboutMenu.LoadString(IDS_ABOUTBOX);
		if (!strAboutMenu.IsEmpty())
		{
			pSysMenu->AppendMenu(MF_SEPARATOR);
			pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
		}
	}

	// Set the icon for this dialog.  The framework does this automatically
	//  when the application's main window is not a dialog
	SetIcon(m_hIcon, TRUE);			// Set big icon
	SetIcon(m_hIcon, FALSE);		// Set small icon
	
	// 加入代码.
	m_Red_ScrollBar.SetScrollRange(0,255);		//设定滚动条的范围.
	m_Green_ScrollBar.SetScrollRange(0,255);
	m_Blue_ScrollBar.SetScrollRange(0,255);
	m_Red_ScrollBar.SetScrollPos(100);	
	m_Green_ScrollBar.SetScrollPos(100);		//设定滚动条的当前位置.
	m_Blue_ScrollBar.SetScrollPos(100);	
	
	char sPos[10];								//将当前滚动条的位置输出.
	itoa(m_Red_ScrollBar.GetScrollPos(),sPos,10);//当前位置为100.
	m_Red_Edit.SetWindowText(sPos);
	itoa(m_Green_ScrollBar.GetScrollPos(),sPos,10);
	m_Green_Edit.SetWindowText(sPos);
	itoa(m_Blue_ScrollBar.GetScrollPos(),sPos,10);
	m_Blue_Edit.SetWindowText(sPos);

	//结束代码.

	return TRUE;  // return TRUE  unless you set the focus to a control
}

void CMy13_3Dlg::OnSysCommand(UINT nID, LPARAM lParam)
{
	if ((nID & 0xFFF0) == IDM_ABOUTBOX)
	{
		CAboutDlg dlgAbout;
		dlgAbout.DoModal();
	}
	else
	{
		CDialog::OnSysCommand(nID, lParam);
	}
}

// If you add a minimize button to your dialog, you will need the code below
//  to draw the icon.  For MFC applications using the document/view model,
//  this is automatically done for you by the framework.

void CMy13_3Dlg::OnPaint() 
{
	if (IsIconic())
	{
		CPaintDC dc(this); // device context for painting

		SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);

		// Center icon in client rectangle
		int cxIcon = GetSystemMetrics(SM_CXICON);
		int cyIcon = GetSystemMetrics(SM_CYICON);
		CRect rect;
		GetClientRect(&rect);
		int x = (rect.Width() - cxIcon + 1) / 2;
		int y = (rect.Height() - cyIcon + 1) / 2;

		// Draw the icon
		dc.DrawIcon(x, y, m_hIcon);
	}
	else
	{
		CDialog::OnPaint();
	}
}

// The system calls this to obtain the cursor to display while the user drags
//  the minimized window.
HCURSOR CMy13_3Dlg::OnQueryDragIcon()
{
	return (HCURSOR) m_hIcon;
}


//滚动条处理函数.
void CMy13_3Dlg::OnVScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar) 
{
	// 加入代码.
	char sPos[10];				//记录滚动条位置的字符数组.
	int iRedNowPos,iBlueNowPos,iGreenNowPos;	//记录滚动条的整形数.
	
	iRedNowPos=m_Red_ScrollBar.GetScrollPos();		//获得滚动条当前位置.
	iGreenNowPos=m_Green_ScrollBar.GetScrollPos();
	iBlueNowPos=m_Blue_ScrollBar.GetScrollPos();
	if(pScrollBar==&m_Red_ScrollBar)	//对红滚动条进行操作.
	{
		switch(nSBCode)
		{
			case SB_THUMBTRACK:			//拖动滚动条
				m_Red_ScrollBar.SetScrollPos(nPos);	//设定滚动条位置.
				iRedNowPos=nPos;
				break;
			case SB_LINEDOWN:			//按向下按钮.
				iRedNowPos=m_Red_ScrollBar.GetScrollPos();//得到当前滚动条位置.
				iRedNowPos=iRedNowPos+1;	//位置量+1
				if(iRedNowPos>255)
					iRedNowPos=255;
				break;
			case SB_LINEUP:				//按向上按钮.
				iRedNowPos=m_Red_ScrollBar.GetScrollPos();//得到当前滚动条位置.
				iRedNowPos=iRedNowPos-1;	//位置量-1
				if(iRedNowPos<0)
					iRedNowPos=0;
				break;
			case SB_PAGEDOWN:			//点击向上按钮和滑动块之间的区域.
				iRedNowPos=m_Red_ScrollBar.GetScrollPos();//得到当前滚动条位置.
				iRedNowPos=iRedNowPos+10;	//位置量+10
				if(iRedNowPos>255)
					iRedNowPos=255;
				break;
			case SB_PAGEUP:				//点击向下按钮和滑动块之间的区域.
				iRedNowPos=m_Red_ScrollBar.GetScrollPos();//得到当前滚动条位置.
				iRedNowPos=iRedNowPos-10;	//位置量-10
				if(iRedNowPos<0)
					iRedNowPos=0;
				break;
		}
	}
	if(pScrollBar==&m_Green_ScrollBar)	//对绿滚动条进行操作.
	{
		switch(nSBCode)
		{
		case SB_THUMBTRACK:				//拖动滑块.
				m_Green_ScrollBar.SetScrollPos(nPos);//设定滚动条位置.
				iGreenNowPos=nPos;
				break;
			case SB_LINEDOWN:			//向下按钮.
				iGreenNowPos=m_Green_ScrollBar.GetScrollPos();//得到当前滚动条位置.
				iGreenNowPos=iGreenNowPos+1;	//位置量+1
				if(iGreenNowPos>255)
					iGreenNowPos=255;
				break;	
			case SB_LINEUP:				//向上按钮
				iGreenNowPos=m_Green_ScrollBar.GetScrollPos();
				iGreenNowPos=iGreenNowPos-1;	//位置量-1
				if(iGreenNowPos<0)
					iGreenNowPos=0;
				break;
			case SB_PAGEDOWN:			//点击向上按钮和滑动块之间的区域			
				iGreenNowPos=m_Green_ScrollBar.GetScrollPos();
				iGreenNowPos=iGreenNowPos+10;	//位置量+10	
				if(iGreenNowPos>255)
					iGreenNowPos=255;
				break;
			case SB_PAGEUP:				//点击向下按钮和滑动块之间的区域
				iGreenNowPos=m_Green_ScrollBar.GetScrollPos();
				iGreenNowPos=iGreenNowPos-10;	//位置量-10
				if(iGreenNowPos<0)
					iGreenNowPos=0;
				break;
		}
	}
	if(pScrollBar==&m_Blue_ScrollBar)	//对蓝色滚动条进行操作.
	{
		switch(nSBCode)
		{
		case SB_THUMBTRACK:				//拖动滑块.
				m_Blue_ScrollBar.SetScrollPos(nPos);
				iBlueNowPos=nPos;
				break;
			case SB_LINEDOWN:			//向上按钮
				iBlueNowPos=m_Blue_ScrollBar.GetScrollPos();
				iBlueNowPos=iBlueNowPos+1;
				if(iBlueNowPos>255)
					iBlueNowPos=255;
				break;
			case SB_LINEUP:				//向下按钮
				iBlueNowPos=m_Blue_ScrollBar.GetScrollPos();
				iBlueNowPos=iBlueNowPos-1;
				if(iBlueNowPos<0)
					iBlueNowPos=0;
				break;
			case SB_PAGEDOWN:			//点击向上按钮和滑动块之间的区域
				iBlueNowPos=m_Blue_ScrollBar.GetScrollPos();
				iBlueNowPos=iBlueNowPos+10;
				if(iBlueNowPos>255)
					iBlueNowPos=255;
				break;
			case SB_PAGEUP:				//点击向下按钮和滑动块之间的区域
				iBlueNowPos=m_Blue_ScrollBar.GetScrollPos();
				iBlueNowPos=iBlueNowPos-10;
				if(iBlueNowPos<0)
					iBlueNowPos=0;
				break;
		}
	}

	//设定滑块位置和在编辑框中显示.
	m_Red_ScrollBar.SetScrollPos(iRedNowPos);
	itoa(iRedNowPos,sPos,10);
	m_Red_Edit.SetWindowText(sPos);
	m_Green_ScrollBar.SetScrollPos(iGreenNowPos);
	itoa(iGreenNowPos,sPos,10);
	m_Green_Edit.SetWindowText(sPos);
	m_Blue_ScrollBar.SetScrollPos(iBlueNowPos);
	itoa(iBlueNowPos,sPos,10);
	m_Blue_Edit.SetWindowText(sPos);

	//图像输出.
	CDC *pDC=GetDC();		//得到设备环境指针.
	CBrush newBrush;		//定义新画刷.
	CPen newPen;			//定义新画笔.
	newBrush.CreateSolidBrush(RGB(iRedNowPos,iGreenNowPos,iBlueNowPos));
	newPen.CreatePen(PS_SOLID,1,RGB(iRedNowPos,iGreenNowPos,iBlueNowPos));
	pDC->SelectObject(&newPen);		//选入新画笔.
	pDC->SelectObject(&newBrush);	//选入新画刷.
	pDC->Ellipse(70,30,170,200);	//画椭圆.
	ReleaseDC(pDC);
	//代码结束.

}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -