DlgMosaicRes.cpp
资源名称:FINAL.rar [点击查看]
上传用户:piaozanzhu
上传日期:2008-02-14
资源大小:212k
文件大小:5k
源码类别:
图形图像处理
开发平台:
Visual C++
- // DlgMosaicRes.cpp : implementation file
- //
- #include "stdafx.h"
- #include "ImageProcessing.h"
- #include "DlgMosaicRes.h"
- #ifdef _DEBUG
- #define new DEBUG_NEW
- #undef THIS_FILE
- static char THIS_FILE[] = __FILE__;
- #endif
- /////////////////////////////////////////////////////////////////////////////
- // CDlgMosaicRes dialog
- CDlgMosaicRes::CDlgMosaicRes(CWnd* pParent /*=NULL*/,CDib* pDibShow)
- : CDialog(CDlgMosaicRes::IDD, pParent)
- {
- //{{AFX_DATA_INIT(CDlgMosaicRes)
- // NOTE: the ClassWizard will add member initialization here
- //}}AFX_DATA_INIT
- m_pDib = pDibShow;
- m_bCalImgLoc = FALSE;
- }
- void CDlgMosaicRes::DoDataExchange(CDataExchange* pDX)
- {
- CDialog::DoDataExchange(pDX);
- //{{AFX_DATA_MAP(CDlgMosaicRes)
- // NOTE: the ClassWizard will add DDX and DDV calls here
- //}}AFX_DATA_MAP
- }
- BEGIN_MESSAGE_MAP(CDlgMosaicRes, CDialog)
- //{{AFX_MSG_MAP(CDlgMosaicRes)
- ON_WM_PAINT()
- ON_BN_CLICKED(IDC_SAVE_AS, OnSaveAs)
- //}}AFX_MSG_MAP
- END_MESSAGE_MAP()
- /////////////////////////////////////////////////////////////////////////////
- // CDlgMosaicRes message handlers
- void CDlgMosaicRes::OnPaint()
- {
- // device context for painting
- // TODO: Add your message handler code here
- CPaintDC dc(this);
- if(!m_bCalImgLoc)
- CalImgLocation();
- CSize sizeDisplay;
- CPoint pointDisplay;
- if(m_pDib != NULL){
- if(!m_pDib->IsEmpty()){
- sizeDisplay.cx=m_pDib->m_lpBMIH->biWidth;
- sizeDisplay.cy=m_pDib->m_lpBMIH->biHeight;
- pointDisplay.x = m_rectImage.left;
- pointDisplay.y = m_rectImage.top;
- m_pDib->Draw(&dc,pointDisplay,sizeDisplay);
- }
- }
- // Do not call CDialog::OnPaint() for painting messages
- }
- void CDlgMosaicRes::CalImgLocation()
- {
- CWnd* pWnd=GetDlgItem(IDC_BMP);
- WINDOWPLACEMENT *winPlacement;
- winPlacement=new WINDOWPLACEMENT;
- pWnd->GetWindowPlacement(winPlacement);
- // 图象宽度
- int nImageWidth = 0;
- // 图象高度
- int nImageHeight = 0;
- if(m_pDib != NULL){
- nImageWidth = m_pDib->m_lpBMIH->biWidth;
- nImageHeight = m_pDib->m_lpBMIH->biHeight;
- }
- // 调整控件IDC_REG_INIT_IMAGE的大小位置,并同时设置显示基准图象的位置
- if(nImageHeight > 352){
- winPlacement->rcNormalPosition.bottom = winPlacement->rcNormalPosition.top + nImageHeight;
- m_rectImage.bottom = winPlacement->rcNormalPosition.bottom;
- m_rectImage.top = winPlacement->rcNormalPosition.top;
- }
- else{
- winPlacement->rcNormalPosition.bottom = winPlacement->rcNormalPosition.top + 352;
- m_rectImage.bottom = winPlacement->rcNormalPosition.top + 176 + nImageHeight/2;
- m_rectImage.top = winPlacement->rcNormalPosition.top + 176 - nImageHeight/2;
- }
- if(nImageWidth > 288){
- winPlacement->rcNormalPosition.right = winPlacement->rcNormalPosition.left + nImageWidth;
- m_rectImage.right = winPlacement->rcNormalPosition.right;
- m_rectImage.left = winPlacement->rcNormalPosition.left;
- }
- else{
- winPlacement->rcNormalPosition.right = winPlacement->rcNormalPosition.left + 288;
- m_rectImage.right = winPlacement->rcNormalPosition.left + 144 + nImageWidth/2;
- m_rectImage.left = winPlacement->rcNormalPosition.left + 144 - nImageWidth/2;
- }
- // 设置IDC_DlgAftReg_IMAGE控件的大小位置
- pWnd->SetWindowPlacement(winPlacement);
- // 获得IDC_DlgAftReg_IMAGE控件的下边位置,以便调整其他控件的位置
- int nIniImgBottom, nIniImgRight,nIniImgLeft;
- nIniImgBottom = winPlacement->rcNormalPosition.bottom;
- nIniImgLeft = winPlacement->rcNormalPosition.left;
- nIniImgRight = winPlacement->rcNormalPosition.right;
- // 设置控件IDOK的位置大小
- pWnd=GetDlgItem(IDOK);
- pWnd->GetWindowPlacement(winPlacement);
- winPlacement->rcNormalPosition.top = nIniImgBottom +15;
- winPlacement->rcNormalPosition.bottom = nIniImgBottom + 60;
- pWnd->SetWindowPlacement(winPlacement);
- // 设置控件IDCANCEL的位置大小
- pWnd=GetDlgItem(IDC_SAVE_AS);
- pWnd->GetWindowPlacement(winPlacement);
- winPlacement->rcNormalPosition.top = nIniImgBottom +15;
- winPlacement->rcNormalPosition.bottom = nIniImgBottom + 60;
- pWnd->SetWindowPlacement(winPlacement);
- this->GetWindowPlacement(winPlacement);
- winPlacement->rcNormalPosition.bottom = nIniImgBottom + 60+ 70;
- winPlacement->rcNormalPosition.left = nIniImgLeft - 20;
- winPlacement->rcNormalPosition.right = nIniImgRight + 20;
- this->SetWindowPlacement(winPlacement);
- m_bCalImgLoc = TRUE;
- // 释放已分配内存
- delete winPlacement;
- }
- void CDlgMosaicRes::OnSaveAs()
- {
- // TODO: Add your control notification handler code here
- CString strSaveFileType = "位图文件 (*.bmp;*.dib)|*.bmp; *.dib|All Files (*.*)|*.*||";
- CFileDialog FileDlg(FALSE, "*.bmp", NULL, OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT, strSaveFileType);
- CFile fileOpen ;
- if( FileDlg.DoModal() == IDOK ) {
- if(!fileOpen.Open( FileDlg.GetPathName() , CFile::modeCreate|CFile::modeWrite )){
- AfxMessageBox("cannot create the file to save");
- return;
- }
- if( !m_pDib->Write( &fileOpen ) ){
- return;
- }
- fileOpen.Close();
- }
- }