ViewHistogram.cpp
上传用户:alisonmail
上传日期:2013-02-28
资源大小:500k
文件大小:3k
- // ViewHistogram.cpp : implementation file
- //
- #include "stdafx.h"
- #include "ImageView.h"
- #include "ViewHistogram.h"
- #ifdef _DEBUG
- #define new DEBUG_NEW
- #undef THIS_FILE
- static char THIS_FILE[] = __FILE__;
- #endif
- /////////////////////////////////////////////////////////////////////////////
- // CViewHistogram dialog
- CViewHistogram::CViewHistogram(CWnd* pParent /*=NULL*/)
- : CDialog(CViewHistogram::IDD, pParent)
- {
- //{{AFX_DATA_INIT(CViewHistogram)
- // NOTE: the ClassWizard will add member initialization here
- //}}AFX_DATA_INIT
- m_nCurSel = 0;
- m_pnHistogram = NULL;
- }
- void CViewHistogram::DoDataExchange(CDataExchange* pDX)
- {
- CDialog::DoDataExchange(pDX);
- //{{AFX_DATA_MAP(CViewHistogram)
- DDX_Control(pDX, IDC_TAB1, m_Histogram);
- //}}AFX_DATA_MAP
- }
- BEGIN_MESSAGE_MAP(CViewHistogram, CDialog)
- //{{AFX_MSG_MAP(CViewHistogram)
- ON_NOTIFY(TCN_SELCHANGE, IDC_TAB1, OnSelchangeTab1)
- ON_WM_PAINT()
- //}}AFX_MSG_MAP
- END_MESSAGE_MAP()
- /////////////////////////////////////////////////////////////////////////////
- // CViewHistogram message handlers
- void CViewHistogram::OnSelchangeTab1(NMHDR* pNMHDR, LRESULT* pResult)
- {
- m_nCurSel = m_Histogram.GetCurSel();
- InvalidateRect( NULL, FALSE );
- UpdateWindow();
-
- *pResult = 0;
- }
- void CViewHistogram::OnPaint()
- {
- CPaintDC dc(this); // device context for painting
-
- RECT Rect1;
- GetWindowRect( &Rect1 );
- CWnd *pWnd;
- pWnd = GetDlgItem( IDC_HISTOGRAM );
- RECT Rect2;
- pWnd->GetWindowRect( &Rect2 );
- COLORREF Color = GetSysColor( COLOR_BTNFACE );
- CBrush Brush( Color );
- CPen Pen( PS_SOLID, 1, Color );
- CBrush *pOldBrush;
- CPen *pOldPen;
- CPen BlackPen( PS_SOLID, 1, RGB( 0, 0, 0 ) );
- CPen RedPen( PS_SOLID, 1, RGB( 255, 0, 0 ) );
- CPen GreenPen( PS_SOLID, 1, RGB( 0, 255, 0 ) );
- CPen BluePen( PS_SOLID, 1, RGB( 0, 0, 255 ) );
- pOldBrush = (CBrush *) dc.SelectObject( &Brush );
- pOldPen = (CPen *) dc.SelectObject( &Pen );
- int x1 = Rect2.left - Rect1.left;
- int y1 = Rect2.top - Rect1.top - 12;
- int x2 = Rect2.right - Rect1.left - 6;
- int y2 = Rect2.bottom - Rect1.top - 25;
- dc.Rectangle( x1, y1, x2, y2 );
- int midx = x1 + ( ( x2 - x1 ) / 2 );
- if( m_nCurSel == 0 ) dc.SelectObject( &BlackPen );
- else if( m_nCurSel == 3 ) dc.SelectObject( &BluePen );
- else if( m_nCurSel == 2 ) dc.SelectObject( &GreenPen );
- else dc.SelectObject( &RedPen );
- for( int i=0; i<256; i++ ){
- if( m_pnHistogram != NULL && m_pnHistogram[m_nCurSel*256+i] != 0 ){
- dc.MoveTo( midx - 128 + i, y2 - 1 );
- dc.LineTo( midx - 128 + i, y2 - m_pnHistogram[m_nCurSel*256+i] );
- }
- }
- dc.SelectObject( pOldBrush );
- dc.SelectObject( pOldPen );
- }
- BOOL CViewHistogram::OnInitDialog()
- {
- CDialog::OnInitDialog();
-
- TC_ITEM Item;
- int i;
- static char *pszTexts[] = { "Gray", "Red", "Green", "Blue" };
- for( i=0; i<4; i++ ){
- memset( &Item, 0, sizeof( TC_ITEM ) );
- Item.mask = TCIF_TEXT;
- Item.pszText = pszTexts[i];
- Item.iImage = -1;
- m_Histogram.InsertItem( i, &Item );
- }
-
- return TRUE; // return TRUE unless you set the focus to a control
- // EXCEPTION: OCX Property Pages should return FALSE
- }
- void CViewHistogram::PostNcDestroy()
- {
- CDialog::PostNcDestroy();
- }