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

📄 paintparambar.cpp

📁 c语言实现的遥感图像处理的一些基本操作
💻 CPP
字号:
// PaintParambar.cpp : implementation file
//

#include "stdafx.h"

#include "RSImageStar.h"
#include "BrowseBar.h"

#include "RSImageStarDoc.h"
#include "RSImageStarView.h"
#include "PaintParambar.h"

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

/////////////////////////////////////////////////////////////////////////////
// CPaintParambar

CPaintParambar::CPaintParambar()
{
	m_hPalette = NULL;
	m_Draw=true;
	m_nSelectColorMode = PP_PEN_COLOR;
}

CPaintParambar::~CPaintParambar()
{
}


BEGIN_MESSAGE_MAP(CPaintParambar, CDialogBar)
	//{{AFX_MSG_MAP(CPaintParambar)
	ON_WM_CREATE()
	ON_LBN_SELCHANGE(IDC_PEN_STYLE, OnSelchangePenstyle)
	ON_LBN_SELCHANGE(IDC_PEN_WIDTH, OnSelchangePenwidth)
	ON_WM_PAINT()
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()


/////////////////////////////////////////////////////////////////////////////
// CPaintParambar message handlers

int CPaintParambar::OnCreate(LPCREATESTRUCT lpCreateStruct) 
{
	if (CDialogBar::OnCreate(lpCreateStruct) == -1)
		return -1;

//	m_hCursorSelectColor = AfxGetApp()->LoadCursor(IDC_CURSORPICKER);
	CRect rect;
	GetWindowRect(&rect);
	m_listPenWidth.Create(LBS_NOINTEGRALHEIGHT|LBS_OWNERDRAWVARIABLE|LBS_NOTIFY,
						  CRect(2,4,rect.Width()/2-1,rect.Height()/2-rect.Height()/16),
						  this,
						  IDC_PEN_WIDTH);
	m_listPenWidth.AddLPItem(1);
	m_listPenWidth.AddLPItem(2);
	m_listPenWidth.AddLPItem(3);
	m_listPenWidth.AddLPItem(4);
	m_listPenWidth.AddLPItem(5);

	m_listPenWidth.AddLPItem(NULL);
	m_listPenWidth.AddLPItem(NULL);

	m_listPenWidth.ShowWindow(SW_SHOWNORMAL);
	m_listPenWidth.SetCurSel(0);
	
	m_listPenStyle.m_nParamIndex = PEN_STYLE;
	m_listPenStyle.Create(LBS_NOINTEGRALHEIGHT|LBS_OWNERDRAWVARIABLE|LBS_NOTIFY,
						  CRect(rect.Width()/2+1,4,rect.Width()-2,rect.Height()/2-rect.Height()/16),
						  this,
						  IDC_PEN_STYLE);
	m_listPenStyle.AddLPItem(PS_SOLID);
	m_listPenStyle.AddLPItem(PS_DASH);
	m_listPenStyle.AddLPItem(PS_DOT);
	m_listPenStyle.AddLPItem(PS_DASHDOT);
	m_listPenStyle.AddLPItem(PS_DASHDOTDOT);

	m_listPenStyle.ShowWindow(SW_SHOWNORMAL);
	m_listPenStyle.SetCurSel(0);
   CPen pen;

	m_rcPenColor = CRect(2,rect.Height()/2+2,rect.Width()/2-2,rect.Height()*4/5-2);
	m_btPenColor.Create(NULL, WS_CHILD | WS_VISIBLE |WS_BORDER| BS_OWNERDRAW | BS_PUSHBUTTON, 
				CRect(3,rect.Height()/2+3,rect.Width()/2-3,rect.Height()*4/5-3), this, IDC_PEN_COLOR);
	m_btPenColor.SetColor(RGB(255,255,255));
	m_btPenColor.ShowWindow(SW_SHOWNORMAL);

	m_rcFillColor = CRect(rect.Width()/2+2,rect.Height()/2+2,rect.Width()-2,rect.Height()*4/5-2);
	m_btFillColor.Create(NULL, BS_OWNERDRAW | BS_PUSHBUTTON|WS_BORDER, 
				CRect(rect.Width()/2+3,rect.Height()/2+3,rect.Width()-3,rect.Height()*4/5-3), this, IDC_FILL_COLOR);

	m_btFillColor.SetColor(TransColor);
	m_btFillColor.ShowWindow(SW_SHOWNORMAL);

/*	for(int i=0; i<COLOR_NUMBER; i++)
	{
		m_btColor[i].Create(NULL, BS_OWNERDRAW | BS_PUSHBUTTON, 
				CRect(5+i%8*9,93+i/8*9,14+i%8*9,102+i/8*9), this, IDC_COLORTABLE_BASE+i);
		m_btColor[i].ShowWindow(SW_HIDE);
	}
*/
	CRect rc;
	GetWindowRect(&rc);
	m_nWidth = rc.Width();
	m_nHeight = rc.Height();
//	ShowColorGrid(m_hPalette);

	return 0;
}

void CPaintParambar::ShowPenColor(COLORREF crColor)
{
	m_btPenColor.SetColor(crColor);
}

void CPaintParambar::ShowFillColor(COLORREF crColor)
{
	m_btFillColor.SetColor(crColor);
}

void CPaintParambar::ShowPenWidth(int nWidth)
{
	m_listPenWidth.SetCurSel(nWidth-1);
}

void CPaintParambar::ShowPenStyle(int nStyle)
{
	m_listPenStyle.SetCurSel(nStyle-PS_SOLID);
}

void CPaintParambar::ShowColorGrid(HPALETTE hPalette)
{
	m_hPalette = hPalette;
	m_nColors = 0;
	int i;
	if (m_hPalette != NULL)
	{
		PALETTEENTRY pe[256];
		m_nColors = GetPaletteEntries(m_hPalette, 0, 256, pe);
		for(i=0; i<m_nColors; i++)
		{
			m_btColor[i].SetColor(RGB(pe[i].peRed, pe[i].peGreen, pe[i].peBlue));
			m_btColor[i].ShowWindow(SW_SHOWNORMAL);
			m_btColor[i].SetCursorHandle(m_hCursorSelectColor);
		}
	}
	for (i=m_nColors; i<COLOR_NUMBER; ++i)
		if (IsWindow(m_btColor[i].m_hWnd))
			m_btColor[i].ShowWindow(SW_HIDE);

	m_nHeight = 102+m_nColors/8*9;
	if (m_nColors == 0)
		m_nHeight -= 6;
	else if (m_nColors == 2)
		m_nHeight += 8;

	SetWindowPos(&wndTop,0,0,m_nWidth,m_nHeight, SWP_NOMOVE);
}


CSize CPaintParambar::CalcDynamicLayout(int nLength, DWORD dwMode)
{
	return CSize(m_nWidth,m_nHeight);
}

CSize CPaintParambar::CalcFixedLayout(BOOL bStretch, BOOL bHorz)
{
	return CSize(m_nWidth,m_nHeight);
}


CView* CPaintParambar::GetView() 
{
	// Get the active MDI child window.
	CMDIFrameWnd *pFrame =  (CMDIFrameWnd*)AfxGetApp()->m_pMainWnd;
	if (pFrame != NULL)
	{
		CMDIChildWnd *pChild = 
			 (CMDIChildWnd *) pFrame->GetActiveFrame();

		// Get the active view attached to the active MDI child// window.
		return (CRSImageStarView *) pChild->GetActiveView();
	}

	return NULL;
}

void CPaintParambar::OnSelchangePenstyle() 
{
	// Get the active view attached to the active MDI child// window.
	CRSImageStarView *pView = (CRSImageStarView* )GetView();
	if (pView != NULL)
		pView->m_nPenStyle = m_listPenStyle.GetItemData(m_listPenStyle.GetCurSel());
}

void CPaintParambar::OnSelchangePenwidth() 
{
	// Get the active view attached to the active MDI child// window.
	CRSImageStarView *pView = (CRSImageStarView* )GetView();
	if (pView != NULL)
		pView->m_nPenWidth = m_listPenWidth.GetItemData(m_listPenWidth.GetCurSel());
}

void CPaintParambar::SetSelectColorMode(int nSelectColorMode)
{
	m_nSelectColorMode = nSelectColorMode;
	CRect rc;
	rc.UnionRect(&m_rcFillColor, &m_rcPenColor);
	InvalidateRect(&rc);
}

void CPaintParambar::OnPaint() 
{
	CPaintDC dc(this); // device context for painting
/*	if(m_Draw)
	{
		m_Draw=false;
		CRect rect,rect1;
		GetWindowRect(&rect);
		ScreenToClient(rect);
		rect1.left=rect.left+1;
		rect1.top=rect.top+1;
		rect1.right=(rect.Width()/2)-1;
		rect1.bottom=int(rect.Height()*0.6)-1;
		m_listPenWidth.Create(LBS_NOINTEGRALHEIGHT|LBS_OWNERDRAWVARIABLE|LBS_NOTIFY,
			rect1,
			this,
			IDC_PEN_WIDTH);
		m_listPenWidth.AddLPItem(1);
		m_listPenWidth.AddLPItem(2);
		m_listPenWidth.AddLPItem(3);
		m_listPenWidth.AddLPItem(4);
		m_listPenWidth.AddLPItem(5);
		m_listPenWidth.ShowWindow(SW_SHOWNORMAL);
		m_listPenWidth.SetCurSel(0);
		
		rect1.left=(rect.Width()/2)+1;
		rect1.top=rect.top+1;
		rect1.right=rect.Width()-1;
		rect1.bottom=int(rect.Height()*0.6)-1;
		m_listPenStyle.m_nParamIndex = PEN_STYLE;
		m_listPenStyle.Create(LBS_NOINTEGRALHEIGHT|LBS_OWNERDRAWVARIABLE|LBS_NOTIFY,
			rect1,
			this,
			IDC_PEN_STYLE);
		m_listPenStyle.AddLPItem(PS_SOLID);
		m_listPenStyle.AddLPItem(PS_DASH);
		m_listPenStyle.AddLPItem(PS_DOT);
		m_listPenStyle.AddLPItem(PS_DASHDOT);
		m_listPenStyle.AddLPItem(PS_DASHDOTDOT);
		m_listPenStyle.ShowWindow(SW_SHOWNORMAL);
		m_listPenStyle.SetCurSel(0);
		
		rect1.left=rect.left+1;
		rect1.top=int(rect.Height()*0.6)+1;
		rect1.right=(rect.Width()/2)-1;
		rect1.bottom=int(rect.Height()*0.8)-1;
		m_rcPenColor = rect1;
		m_btPenColor.Create(NULL, WS_CHILD | WS_VISIBLE |WS_BORDER| BS_OWNERDRAW | BS_PUSHBUTTON, 
			rect1, this, IDC_PEN_COLOR);
		m_btPenColor.SetColor(RGB(255,255,255));
		m_btPenColor.ShowWindow(SW_SHOWNORMAL);
		
		rect1.left=(rect.Width()/2)+1;
		rect1.top=int(rect.Height()*0.6)+1;
		rect1.right=rect.Width()-1;
		rect1.bottom=int(rect.Height()*0.8)-1;
		m_rcFillColor = rect1;
		m_btFillColor.Create(NULL, BS_OWNERDRAW | BS_PUSHBUTTON|WS_BORDER, 
			rect1, this, IDC_FILL_COLOR);
		
		m_btFillColor.SetColor(RGB(3,5,7));
		m_btFillColor.ShowWindow(SW_SHOWNORMAL);
	}*/

	CPen pen(PS_SOLID,1,RGB(255,0,0));
	CPen *pOldPen = dc.SelectObject(&pen);
	CRect rc;
	if (m_nSelectColorMode == PP_PEN_COLOR)
		dc.Rectangle(&m_rcPenColor);
	else if (m_nSelectColorMode == PP_FILL_COLOR)
		dc.Rectangle(&m_rcFillColor);
	dc.SelectObject(pOldPen);

	CFont fontText;
	fontText.CreateFont(1 * 16, 0, 0, 0, 300, FALSE, FALSE, 0,
	                    ANSI_CHARSET, OUT_DEFAULT_PRECIS,
	                    CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY,
	                    DEFAULT_PITCH | FF_SWISS, "Arial");

	CFont* pOldFont = dc.SelectObject(&fontText);
	CRect rect;
	GetWindowRect(&rect);
	dc.TextOut(4,rect.Height()*4/5,"前景");
    dc.TextOut(rect.Width()*3/5,rect.Height()*4/5,"背景");
	dc.SelectObject(pOldFont);
	fontText.DeleteObject();

	
	// Do not call CDialogBar::OnPaint() for painting messages
}

void CPaintParambar::Restore()
{
	CRSImageStarView *pView = (CRSImageStarView* )GetView();
	if (pView != NULL)
	{
	    ShowPenWidth(pView->m_nPenWidth);
	    ShowPenStyle(pView->m_nPenStyle);
	    ShowPenColor(pView->m_crPenColor);
        ShowFillColor(pView->m_crFillColor);
	}
}


⌨️ 快捷键说明

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