DlgMosaicRes.cpp
上传用户:piaozanzhu
上传日期:2008-02-14
资源大小:212k
文件大小:5k
源码类别:

图形图像处理

开发平台:

Visual C++

  1. // DlgMosaicRes.cpp : implementation file
  2. //
  3. #include "stdafx.h"
  4. #include "ImageProcessing.h"
  5. #include "DlgMosaicRes.h"
  6. #ifdef _DEBUG
  7. #define new DEBUG_NEW
  8. #undef THIS_FILE
  9. static char THIS_FILE[] = __FILE__;
  10. #endif
  11. /////////////////////////////////////////////////////////////////////////////
  12. // CDlgMosaicRes dialog
  13. CDlgMosaicRes::CDlgMosaicRes(CWnd* pParent /*=NULL*/,CDib* pDibShow)
  14. : CDialog(CDlgMosaicRes::IDD, pParent)
  15. {
  16. //{{AFX_DATA_INIT(CDlgMosaicRes)
  17. // NOTE: the ClassWizard will add member initialization here
  18. //}}AFX_DATA_INIT
  19. m_pDib = pDibShow;
  20. m_bCalImgLoc = FALSE;
  21. }
  22. void CDlgMosaicRes::DoDataExchange(CDataExchange* pDX)
  23. {
  24. CDialog::DoDataExchange(pDX);
  25. //{{AFX_DATA_MAP(CDlgMosaicRes)
  26. // NOTE: the ClassWizard will add DDX and DDV calls here
  27. //}}AFX_DATA_MAP
  28. }
  29. BEGIN_MESSAGE_MAP(CDlgMosaicRes, CDialog)
  30. //{{AFX_MSG_MAP(CDlgMosaicRes)
  31. ON_WM_PAINT()
  32. ON_BN_CLICKED(IDC_SAVE_AS, OnSaveAs)
  33. //}}AFX_MSG_MAP
  34. END_MESSAGE_MAP()
  35. /////////////////////////////////////////////////////////////////////////////
  36. // CDlgMosaicRes message handlers
  37. void CDlgMosaicRes::OnPaint() 
  38. {
  39.  // device context for painting
  40. // TODO: Add your message handler code here
  41.     CPaintDC dc(this);
  42. if(!m_bCalImgLoc)
  43. CalImgLocation();
  44. CSize sizeDisplay;
  45. CPoint pointDisplay;
  46. if(m_pDib != NULL){
  47. if(!m_pDib->IsEmpty()){
  48. sizeDisplay.cx=m_pDib->m_lpBMIH->biWidth;
  49. sizeDisplay.cy=m_pDib->m_lpBMIH->biHeight;
  50. pointDisplay.x = m_rectImage.left;
  51. pointDisplay.y = m_rectImage.top;
  52. m_pDib->Draw(&dc,pointDisplay,sizeDisplay);
  53. }
  54. }
  55. // Do not call CDialog::OnPaint() for painting messages
  56. }
  57. void CDlgMosaicRes::CalImgLocation()
  58. {
  59. CWnd* pWnd=GetDlgItem(IDC_BMP);
  60. WINDOWPLACEMENT *winPlacement;
  61. winPlacement=new WINDOWPLACEMENT;
  62. pWnd->GetWindowPlacement(winPlacement);
  63. // 图象宽度
  64. int nImageWidth = 0;
  65. // 图象高度
  66. int nImageHeight = 0;
  67. if(m_pDib != NULL){
  68. nImageWidth = m_pDib->m_lpBMIH->biWidth;
  69. nImageHeight = m_pDib->m_lpBMIH->biHeight;
  70. }
  71. // 调整控件IDC_REG_INIT_IMAGE的大小位置,并同时设置显示基准图象的位置
  72. if(nImageHeight > 352){
  73. winPlacement->rcNormalPosition.bottom = winPlacement->rcNormalPosition.top + nImageHeight;
  74. m_rectImage.bottom = winPlacement->rcNormalPosition.bottom;
  75. m_rectImage.top    = winPlacement->rcNormalPosition.top;
  76. }
  77. else{
  78. winPlacement->rcNormalPosition.bottom = winPlacement->rcNormalPosition.top + 352;
  79. m_rectImage.bottom = winPlacement->rcNormalPosition.top + 176 + nImageHeight/2;
  80. m_rectImage.top    = winPlacement->rcNormalPosition.top + 176 - nImageHeight/2;
  81. }
  82. if(nImageWidth > 288){
  83. winPlacement->rcNormalPosition.right = winPlacement->rcNormalPosition.left + nImageWidth;
  84. m_rectImage.right = winPlacement->rcNormalPosition.right;
  85. m_rectImage.left  = winPlacement->rcNormalPosition.left;
  86. }
  87. else{
  88. winPlacement->rcNormalPosition.right = winPlacement->rcNormalPosition.left + 288;
  89. m_rectImage.right = winPlacement->rcNormalPosition.left + 144 + nImageWidth/2;
  90. m_rectImage.left  = winPlacement->rcNormalPosition.left + 144 - nImageWidth/2;
  91. }
  92. // 设置IDC_DlgAftReg_IMAGE控件的大小位置
  93. pWnd->SetWindowPlacement(winPlacement);
  94. // 获得IDC_DlgAftReg_IMAGE控件的下边位置,以便调整其他控件的位置
  95. int nIniImgBottom, nIniImgRight,nIniImgLeft;
  96. nIniImgBottom = winPlacement->rcNormalPosition.bottom;
  97. nIniImgLeft   = winPlacement->rcNormalPosition.left;
  98. nIniImgRight  = winPlacement->rcNormalPosition.right;
  99. // 设置控件IDOK的位置大小
  100. pWnd=GetDlgItem(IDOK);
  101. pWnd->GetWindowPlacement(winPlacement);
  102. winPlacement->rcNormalPosition.top = nIniImgBottom +15;
  103. winPlacement->rcNormalPosition.bottom = nIniImgBottom + 60;
  104. pWnd->SetWindowPlacement(winPlacement);
  105. // 设置控件IDCANCEL的位置大小
  106. pWnd=GetDlgItem(IDC_SAVE_AS);
  107. pWnd->GetWindowPlacement(winPlacement);
  108. winPlacement->rcNormalPosition.top = nIniImgBottom +15;
  109. winPlacement->rcNormalPosition.bottom = nIniImgBottom + 60;
  110. pWnd->SetWindowPlacement(winPlacement);
  111. this->GetWindowPlacement(winPlacement);
  112. winPlacement->rcNormalPosition.bottom = nIniImgBottom + 60+ 70;
  113. winPlacement->rcNormalPosition.left   = nIniImgLeft   - 20;
  114. winPlacement->rcNormalPosition.right  = nIniImgRight  + 20;
  115. this->SetWindowPlacement(winPlacement);
  116. m_bCalImgLoc = TRUE;
  117. // 释放已分配内存
  118. delete winPlacement;
  119. }
  120. void CDlgMosaicRes::OnSaveAs() 
  121. {
  122. // TODO: Add your control notification handler code here
  123. CString strSaveFileType = "位图文件 (*.bmp;*.dib)|*.bmp; *.dib|All Files (*.*)|*.*||";
  124. CFileDialog FileDlg(FALSE, "*.bmp", NULL, OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT, strSaveFileType);
  125. CFile fileOpen ;
  126. if( FileDlg.DoModal() == IDOK ) {
  127. if(!fileOpen.Open( FileDlg.GetPathName() , CFile::modeCreate|CFile::modeWrite )){
  128. AfxMessageBox("cannot create the file to save");
  129. return;
  130. }
  131. if( !m_pDib->Write( &fileOpen ) ){
  132. return;
  133. }
  134. fileOpen.Close();
  135. }
  136. }