ZhiFangDlg.cpp
上传用户:shuijing
上传日期:2011-09-19
资源大小:90k
文件大小:4k
源码类别:

图形图像处理

开发平台:

Visual C++

  1. // ZhiFangDlg.cpp : implementation file
  2. //
  3. #include "stdafx.h"
  4. #include "sfs.h"
  5. #include "ZhiFangDlg.h"
  6. //#include "SfsView.h"
  7. #ifdef _DEBUG
  8. #define new DEBUG_NEW
  9. #undef THIS_FILE
  10. static char THIS_FILE[] = __FILE__;
  11. #endif
  12. /////////////////////////////////////////////////////////////////////////////
  13. // CZhiFangDlg dialog
  14. CZhiFangDlg::CZhiFangDlg(CWnd* pParent /*=NULL*/)
  15. : CDialog(CZhiFangDlg::IDD, pParent)
  16. {
  17. //{{AFX_DATA_INIT(CZhiFangDlg)
  18. // NOTE: the ClassWizard will add member initialization here
  19. //}}AFX_DATA_INIT
  20. }
  21. void CZhiFangDlg::DoDataExchange(CDataExchange* pDX)
  22. {
  23. CDialog::DoDataExchange(pDX);
  24. //{{AFX_DATA_MAP(CZhiFangDlg)
  25. // NOTE: the ClassWizard will add DDX and DDV calls here
  26. DDX_Text(pDX, IDC_STATIC_GRAYLEVEL, m_staticGreylevel);
  27. DDV_MaxChars(pDX, m_staticGreylevel, 3);
  28. DDX_Text(pDX, IDC_STATIC_PIXNUMBER, m_staticNumpixel);
  29. DDV_MaxChars(pDX, m_staticNumpixel, 6);
  30. //}}AFX_DATA_MAP
  31. }
  32. BEGIN_MESSAGE_MAP(CZhiFangDlg, CDialog)
  33. //{{AFX_MSG_MAP(CZhiFangDlg)
  34. ON_WM_PAINT()
  35. ON_WM_SIZE()
  36. ON_WM_MOUSEMOVE()
  37. //}}AFX_MSG_MAP
  38. END_MESSAGE_MAP()
  39. /////////////////////////////////////////////////////////////////////////////
  40. // CZhiFangDlg message handlers
  41. void CZhiFangDlg::OnPaint() 
  42. {
  43. CPaintDC dc(this); // device context for painting
  44. // TODO: Add your message handler code here
  45. //画坐标系
  46. //CSfsView *pview=(CSfsView *)(GetWindow(GW_OWNER));
  47. //int ddd=pview->ceshi;
  48. int orin=40;
  49. int Max=1;
  50. for(int ii=0; ii<256; ii++)
  51. {  
  52.     Max = (Max>hh[ii]) ? Max : hh[ii];
  53. }
  54. dc.MoveTo(40,270);
  55. dc.TextOut(30,270,"0");
  56. dc.LineTo(544,270);//x轴
  57. //dc.SetTextColor(RGB(255,0,0));
  58. //dc.SetBkColor(dc.GetBkColor());
  59. dc.TextOut(544,270,"灰度级");
  60. dc.LineTo(534,265);
  61.     dc.MoveTo(544,270);
  62. dc.LineTo(534,275);
  63. dc.MoveTo(40,270);
  64. dc.LineTo(40,20);//y轴
  65. dc.TextOut(20,0,"象素数");
  66. char Tmax[5];
  67. dc.TextOut(0,15,"Max:");
  68. dc.TextOut(0,30,itoa(Max, Tmax, 10));
  69. dc.LineTo(35,30);
  70. dc.MoveTo(40,20);
  71. dc.LineTo(45,30);
  72. for(int i=1;i<=8;i++)
  73. for(int j=1;j<=10;j++)
  74. {
  75. orin=orin+6;
  76. dc.MoveTo(orin,270);
  77. if(orin<(40+60*i))
  78. dc.LineTo(orin,280);
  79. if(orin==(40+60*i))
  80. {
  81. dc.LineTo(orin,285);
  82. dc.TextOut(orin-7,290,itoa(32*i,Tmax,10));
  83. }
  84. }
  85.      for(i=1;i<=6;i++)
  86.  {
  87.     dc.MoveTo(40,270-40*i);
  88. dc.LineTo(35,270-40*i);
  89.  }
  90. /////画直方图
  91. CPen NewPen1(PS_SOLID,1,RGB(0,0,128));
  92.     CPen * OldPen= dc.SelectObject(&NewPen1);
  93. for(int k=0;k<256;k++)
  94. {
  95. int ht=hh[k]*240 / Max;
  96. dc.MoveTo(40+k*480/256,270);
  97. dc.LineTo(40+k*480/256,270-ht);
  98. }
  99. dc.SelectObject(OldPen);
  100. // Do not call CDialog::OnPaint() for painting messages
  101. }
  102. int CZhiFangDlg::DoModal(int h[256]) 
  103. {
  104. // TODO: Add your specialized code here and/or call the base class
  105. for(int i=0; i<256; i++)
  106. hh[i] = h[i];
  107. return CDialog::DoModal();
  108. }
  109. void CZhiFangDlg::OnSize(UINT nType, int cx, int cy) 
  110. {
  111. CDialog::OnSize(nType, cx, cy);
  112. // TODO: Add your message handler code here
  113. CWnd * okbutton=GetDlgItem(IDOK);
  114. okbutton->MoveWindow(cx-80,10,70,30);
  115. if(cx <= 620 || cy <= 300)
  116. MoveWindow(200, 150, 620, 350);
  117.    CenterWindow();
  118. Invalidate();
  119. }
  120. void CZhiFangDlg::OnMouseMove(UINT nFlags, CPoint point) 
  121. {
  122. // TODO: Add your message handler code here and/or call default
  123. if((point.x<=520 && point.x>=40) && (point.y<=270 &&point.y>=30))
  124. {
  125. m_staticGreylevel.Format("%d",(point.x-40)*256/480);
  126.     m_staticNumpixel.Format("%d",hh[(point.x-40)*256/480]);
  127.     UpdateData(FALSE);
  128. }
  129. else
  130. {
  131. m_staticGreylevel.Format(_T(""));
  132. m_staticNumpixel.Format(_T(""));
  133. UpdateData(FALSE);
  134. }
  135. CDialog::OnMouseMove(nFlags, point);
  136. }