DlgSmooth.cpp
上传用户:gdjinyi
上传日期:2013-02-01
资源大小:1701k
文件大小:6k
源码类别:

源码/资料

开发平台:

Visual C++

  1. // DlgSmooth.cpp : implementation file
  2. //
  3. #include "stdafx.h"
  4. #include "ch1_1.h"
  5. #include "DlgSmooth.h"
  6. #ifdef _DEBUG
  7. #define new DEBUG_NEW
  8. #undef THIS_FILE
  9. static char THIS_FILE[] = __FILE__;
  10. #endif
  11. /////////////////////////////////////////////////////////////////////////////
  12. // CDlgSmooth dialog
  13. CDlgSmooth::CDlgSmooth(CWnd* pParent /*=NULL*/)
  14. : CDialog(CDlgSmooth::IDD, pParent)
  15. {
  16. //{{AFX_DATA_INIT(CDlgSmooth)
  17. m_intType = -1;
  18. m_iTempH = 0;
  19. m_iTempW = 0;
  20. m_iTempMX = 0;
  21. m_iTempMY = 0;
  22. m_fTempC = 0.0f;
  23. //}}AFX_DATA_INIT
  24. }
  25. void CDlgSmooth::DoDataExchange(CDataExchange* pDX)
  26. {
  27. CDialog::DoDataExchange(pDX);
  28. //{{AFX_DATA_MAP(CDlgSmooth)
  29. DDX_Radio(pDX, IDC_RAD1, m_intType);
  30. DDX_Text(pDX, IDC_EDIT_TEMPH, m_iTempH);
  31. DDV_MinMaxInt(pDX, m_iTempH, 2, 5);
  32. DDX_Text(pDX, IDC_EDIT_TEMPW, m_iTempW);
  33. DDV_MinMaxInt(pDX, m_iTempW, 2, 5);
  34. DDX_Text(pDX, IDC_EDIT_MX, m_iTempMX);
  35. DDX_Text(pDX, IDC_EDIT_MY, m_iTempMY);
  36. DDX_Text(pDX, IDC_EDIT_TEMPC, m_fTempC);
  37. DDX_Text(pDX, IDC_EDIT_V0, m_fpArray[0]);
  38. DDX_Text(pDX, IDC_EDIT_V1, m_fpArray[1]);
  39. DDX_Text(pDX, IDC_EDIT_V2, m_fpArray[2]);
  40. DDX_Text(pDX, IDC_EDIT_V3, m_fpArray[3]);
  41. DDX_Text(pDX, IDC_EDIT_V4, m_fpArray[4]);
  42. DDX_Text(pDX, IDC_EDIT_V5, m_fpArray[5]);
  43. DDX_Text(pDX, IDC_EDIT_V6, m_fpArray[6]);
  44. DDX_Text(pDX, IDC_EDIT_V7, m_fpArray[7]);
  45. DDX_Text(pDX, IDC_EDIT_V8, m_fpArray[8]);
  46. DDX_Text(pDX, IDC_EDIT_V9, m_fpArray[9]);
  47. DDX_Text(pDX, IDC_EDIT_V10, m_fpArray[10]);
  48. DDX_Text(pDX, IDC_EDIT_V11, m_fpArray[11]);
  49. DDX_Text(pDX, IDC_EDIT_V12, m_fpArray[12]);
  50. DDX_Text(pDX, IDC_EDIT_V13, m_fpArray[13]);
  51. DDX_Text(pDX, IDC_EDIT_V14, m_fpArray[14]);
  52. DDX_Text(pDX, IDC_EDIT_V15, m_fpArray[15]);
  53. DDX_Text(pDX, IDC_EDIT_V16, m_fpArray[16]);
  54. DDX_Text(pDX, IDC_EDIT_V17, m_fpArray[17]);
  55. DDX_Text(pDX, IDC_EDIT_V18, m_fpArray[18]);
  56. DDX_Text(pDX, IDC_EDIT_V19, m_fpArray[19]);
  57. DDX_Text(pDX, IDC_EDIT_V20, m_fpArray[20]);
  58. DDX_Text(pDX, IDC_EDIT_V21, m_fpArray[21]);
  59. DDX_Text(pDX, IDC_EDIT_V22, m_fpArray[22]);
  60. DDX_Text(pDX, IDC_EDIT_V23, m_fpArray[23]);
  61. DDX_Text(pDX, IDC_EDIT_V24, m_fpArray[24]);
  62. //}}AFX_DATA_MAP
  63. }
  64. BEGIN_MESSAGE_MAP(CDlgSmooth, CDialog)
  65. //{{AFX_MSG_MAP(CDlgSmooth)
  66. ON_BN_CLICKED(IDC_RAD1, OnRad1)
  67. ON_BN_CLICKED(IDC_RAD2, OnRad2)
  68. ON_BN_CLICKED(IDC_RAD3, OnRad3)
  69. ON_EN_KILLFOCUS(IDC_EDIT_TEMPH, OnKillfocusEditTemph)
  70. ON_EN_KILLFOCUS(IDC_EDIT_TEMPW, OnKillfocusEditTempw)
  71. //}}AFX_MSG_MAP
  72. END_MESSAGE_MAP()
  73. /////////////////////////////////////////////////////////////////////////////
  74. // CDlgSmooth message handlers
  75. void CDlgSmooth::OnRad1() 
  76. {
  77. // 3×3平均模板
  78. m_intType = 0;
  79. m_iTempH  = 3;
  80. m_iTempW  = 3;
  81. m_iTempMX = 1;
  82. m_iTempMY = 1;
  83. m_fTempC  = (FLOAT) (1.0 / 9.0);
  84. // 设置模板元素
  85. m_fpArray[0] = 1.0;
  86. m_fpArray[1] = 1.0;
  87. m_fpArray[2] = 1.0;
  88. m_fpArray[3] = 0.0;
  89. m_fpArray[4] = 0.0;
  90. m_fpArray[5] = 1.0;
  91. m_fpArray[6] = 1.0;
  92. m_fpArray[7] = 1.0;
  93. m_fpArray[8] = 0.0;
  94. m_fpArray[9] = 0.0;
  95. m_fpArray[10] = 1.0;
  96. m_fpArray[11] = 1.0;
  97. m_fpArray[12] = 1.0;
  98. m_fpArray[13] = 0.0;
  99. m_fpArray[14] = 0.0;
  100. m_fpArray[15] = 0.0;
  101. m_fpArray[16] = 0.0;
  102. m_fpArray[17] = 0.0;
  103. m_fpArray[18] = 0.0;
  104. m_fpArray[19] = 0.0;
  105. m_fpArray[20] = 0.0;
  106. m_fpArray[21] = 0.0;
  107. m_fpArray[22] = 0.0;
  108. m_fpArray[23] = 0.0;
  109. m_fpArray[24] = 0.0;
  110. // 更新文本框状态
  111. UpdateEdit();
  112. // 更新
  113. UpdateData(FALSE);
  114. }
  115. void CDlgSmooth::OnRad2() 
  116. {
  117. // 3×3高斯模板
  118. m_intType = 1;
  119. m_iTempH  = 3;
  120. m_iTempW  = 3;
  121. m_iTempMX = 1;
  122. m_iTempMY = 1;
  123. m_fTempC  = (FLOAT) (1.0 / 16.0);
  124. // 设置模板元素
  125. m_fpArray[0] = 1.0;
  126. m_fpArray[1] = 2.0;
  127. m_fpArray[2] = 1.0;
  128. m_fpArray[3] = 0.0;
  129. m_fpArray[4] = 0.0;
  130. m_fpArray[5] = 2.0;
  131. m_fpArray[6] = 4.0;
  132. m_fpArray[7] = 2.0;
  133. m_fpArray[8] = 0.0;
  134. m_fpArray[9] = 0.0;
  135. m_fpArray[10] = 1.0;
  136. m_fpArray[11] = 2.0;
  137. m_fpArray[12] = 1.0;
  138. m_fpArray[13] = 0.0;
  139. m_fpArray[14] = 0.0;
  140. m_fpArray[15] = 0.0;
  141. m_fpArray[16] = 0.0;
  142. m_fpArray[17] = 0.0;
  143. m_fpArray[18] = 0.0;
  144. m_fpArray[19] = 0.0;
  145. m_fpArray[20] = 0.0;
  146. m_fpArray[21] = 0.0;
  147. m_fpArray[22] = 0.0;
  148. m_fpArray[23] = 0.0;
  149. m_fpArray[24] = 0.0;
  150. // 更新文本框状态
  151. UpdateEdit();
  152. // 更新
  153. UpdateData(FALSE);
  154. }
  155. void CDlgSmooth::OnRad3() 
  156. {
  157. // 自定义模板
  158. m_intType = 2;
  159. // 更新文本框状态
  160. UpdateEdit();
  161. }
  162. void CDlgSmooth::OnOK() 
  163. {
  164. // 获取用户设置(更新)
  165. UpdateData(TRUE);
  166. // 判断设置是否有效
  167. if ((m_iTempMX < 0) || (m_iTempMX > m_iTempW - 1) ||
  168. (m_iTempMY < 0) || (m_iTempMY > m_iTempH - 1))
  169. {
  170. // 提示用户参数设置错误
  171. MessageBox("中心元素参数设置错误!", "系统提示" , 
  172. MB_ICONINFORMATION | MB_OK);
  173. // 返回
  174. return;
  175. }
  176. // 更新模板元素数组(将有效元素放置在数组的前面)
  177. for (int i = 0; i < m_iTempH; i++)
  178. {
  179. for (int j = 0; j < m_iTempW; j++)
  180. {
  181. m_fpArray[i * m_iTempW + j] = m_fpArray[i * 5 + j];
  182. }
  183. }
  184. // 更新
  185. UpdateData(FALSE);
  186. // 退出
  187. CDialog::OnOK();
  188. }
  189. void CDlgSmooth::UpdateEdit()
  190. {
  191. BOOL bEnable;
  192. // 循环变量
  193. int i;
  194. int j;
  195. // 判断是不是自定义模板
  196. if (m_intType == 2) 
  197. {
  198. bEnable = TRUE;
  199. }
  200. else
  201. {
  202. bEnable = FALSE;
  203. }
  204. // 设置文本框可用状态
  205. (CEdit *) GetDlgItem(IDC_EDIT_TEMPH)->EnableWindow(bEnable);
  206. (CEdit *) GetDlgItem(IDC_EDIT_TEMPW)->EnableWindow(bEnable);
  207. (CEdit *) GetDlgItem(IDC_EDIT_TEMPC)->EnableWindow(bEnable);
  208. (CEdit *) GetDlgItem(IDC_EDIT_MX)->EnableWindow(bEnable);
  209. (CEdit *) GetDlgItem(IDC_EDIT_MY)->EnableWindow(bEnable);
  210. // IDC_EDIT_V0等ID其实是一个整数,它的数值定义在Resource.h中定义。
  211. // 设置模板元素文本框Enable状态
  212. for (i = IDC_EDIT_V0; i <= IDC_EDIT_V24; i++)
  213. {
  214. // 设置文本框不可编辑
  215. (CEdit *) GetDlgItem(i)->EnableWindow(bEnable);
  216. }
  217. // 显示应该可见的模板元素文本框
  218. for (i = 0; i < m_iTempH; i++)
  219. {
  220. for (j = 0; j < m_iTempW; j++)
  221. {
  222. // 设置文本框可见
  223. (CEdit *) GetDlgItem(IDC_EDIT_V0 + i*5 + j)->ShowWindow(SW_SHOW);
  224. }
  225. }
  226. // 隐藏应该不可见的模板元素文本框(前m_iTempH行的后几列)
  227. for (i = 0; i < m_iTempH; i++)
  228. {
  229. for (j = m_iTempW; j < 5; j++)
  230. {
  231. // 设置不可见
  232. (CEdit *) GetDlgItem(IDC_EDIT_V0 + i*5 + j)->ShowWindow(SW_HIDE);
  233. }
  234. }
  235. // 隐藏应该不可见的模板元素文本框(后几行)
  236. for (i = m_iTempH; i < 5; i++)
  237. {
  238. for (j = 0; j < 5; j++)
  239. {
  240. // 设置不可见
  241. (CEdit *) GetDlgItem(IDC_EDIT_V0 + i*5 + j)->ShowWindow(SW_HIDE);
  242. }
  243. }
  244. }
  245. void CDlgSmooth::OnKillfocusEditTemph() 
  246. {
  247. // 更新
  248. UpdateData(TRUE);
  249. // 更新文本框状态
  250. UpdateEdit();
  251. }
  252. void CDlgSmooth::OnKillfocusEditTempw() 
  253. {
  254. // 更新
  255. UpdateData(TRUE);
  256. // 更新文本框状态
  257. UpdateEdit();
  258. }