ZhiFangDlg.cpp
资源名称:jw.rar [点击查看]
上传用户:shuijing
上传日期:2011-09-19
资源大小:90k
文件大小:4k
源码类别:
图形图像处理
开发平台:
Visual C++
- // ZhiFangDlg.cpp : implementation file
- //
- #include "stdafx.h"
- #include "sfs.h"
- #include "ZhiFangDlg.h"
- //#include "SfsView.h"
- #ifdef _DEBUG
- #define new DEBUG_NEW
- #undef THIS_FILE
- static char THIS_FILE[] = __FILE__;
- #endif
- /////////////////////////////////////////////////////////////////////////////
- // CZhiFangDlg dialog
- CZhiFangDlg::CZhiFangDlg(CWnd* pParent /*=NULL*/)
- : CDialog(CZhiFangDlg::IDD, pParent)
- {
- //{{AFX_DATA_INIT(CZhiFangDlg)
- // NOTE: the ClassWizard will add member initialization here
- //}}AFX_DATA_INIT
- }
- void CZhiFangDlg::DoDataExchange(CDataExchange* pDX)
- {
- CDialog::DoDataExchange(pDX);
- //{{AFX_DATA_MAP(CZhiFangDlg)
- // NOTE: the ClassWizard will add DDX and DDV calls here
- DDX_Text(pDX, IDC_STATIC_GRAYLEVEL, m_staticGreylevel);
- DDV_MaxChars(pDX, m_staticGreylevel, 3);
- DDX_Text(pDX, IDC_STATIC_PIXNUMBER, m_staticNumpixel);
- DDV_MaxChars(pDX, m_staticNumpixel, 6);
- //}}AFX_DATA_MAP
- }
- BEGIN_MESSAGE_MAP(CZhiFangDlg, CDialog)
- //{{AFX_MSG_MAP(CZhiFangDlg)
- ON_WM_PAINT()
- ON_WM_SIZE()
- ON_WM_MOUSEMOVE()
- //}}AFX_MSG_MAP
- END_MESSAGE_MAP()
- /////////////////////////////////////////////////////////////////////////////
- // CZhiFangDlg message handlers
- void CZhiFangDlg::OnPaint()
- {
- CPaintDC dc(this); // device context for painting
- // TODO: Add your message handler code here
- //画坐标系
- //CSfsView *pview=(CSfsView *)(GetWindow(GW_OWNER));
- //int ddd=pview->ceshi;
- int orin=40;
- int Max=1;
- for(int ii=0; ii<256; ii++)
- {
- Max = (Max>hh[ii]) ? Max : hh[ii];
- }
- dc.MoveTo(40,270);
- dc.TextOut(30,270,"0");
- dc.LineTo(544,270);//x轴
- //dc.SetTextColor(RGB(255,0,0));
- //dc.SetBkColor(dc.GetBkColor());
- dc.TextOut(544,270,"灰度级");
- dc.LineTo(534,265);
- dc.MoveTo(544,270);
- dc.LineTo(534,275);
- dc.MoveTo(40,270);
- dc.LineTo(40,20);//y轴
- dc.TextOut(20,0,"象素数");
- char Tmax[5];
- dc.TextOut(0,15,"Max:");
- dc.TextOut(0,30,itoa(Max, Tmax, 10));
- dc.LineTo(35,30);
- dc.MoveTo(40,20);
- dc.LineTo(45,30);
- for(int i=1;i<=8;i++)
- for(int j=1;j<=10;j++)
- {
- orin=orin+6;
- dc.MoveTo(orin,270);
- if(orin<(40+60*i))
- dc.LineTo(orin,280);
- if(orin==(40+60*i))
- {
- dc.LineTo(orin,285);
- dc.TextOut(orin-7,290,itoa(32*i,Tmax,10));
- }
- }
- for(i=1;i<=6;i++)
- {
- dc.MoveTo(40,270-40*i);
- dc.LineTo(35,270-40*i);
- }
- /////画直方图
- CPen NewPen1(PS_SOLID,1,RGB(0,0,128));
- CPen * OldPen= dc.SelectObject(&NewPen1);
- for(int k=0;k<256;k++)
- {
- int ht=hh[k]*240 / Max;
- dc.MoveTo(40+k*480/256,270);
- dc.LineTo(40+k*480/256,270-ht);
- }
- dc.SelectObject(OldPen);
- // Do not call CDialog::OnPaint() for painting messages
- }
- int CZhiFangDlg::DoModal(int h[256])
- {
- // TODO: Add your specialized code here and/or call the base class
- for(int i=0; i<256; i++)
- hh[i] = h[i];
- return CDialog::DoModal();
- }
- void CZhiFangDlg::OnSize(UINT nType, int cx, int cy)
- {
- CDialog::OnSize(nType, cx, cy);
- // TODO: Add your message handler code here
- CWnd * okbutton=GetDlgItem(IDOK);
- okbutton->MoveWindow(cx-80,10,70,30);
- if(cx <= 620 || cy <= 300)
- MoveWindow(200, 150, 620, 350);
- CenterWindow();
- Invalidate();
- }
- void CZhiFangDlg::OnMouseMove(UINT nFlags, CPoint point)
- {
- // TODO: Add your message handler code here and/or call default
- if((point.x<=520 && point.x>=40) && (point.y<=270 &&point.y>=30))
- {
- m_staticGreylevel.Format("%d",(point.x-40)*256/480);
- m_staticNumpixel.Format("%d",hh[(point.x-40)*256/480]);
- UpdateData(FALSE);
- }
- else
- {
- m_staticGreylevel.Format(_T(""));
- m_staticNumpixel.Format(_T(""));
- UpdateData(FALSE);
- }
- CDialog::OnMouseMove(nFlags, point);
- }
English
