www.pudn.com > BitmapExample.rar > BitmapExampleDlg.cpp


// BitmapExampleDlg.cpp : implementation file 
// 
 
#include "stdafx.h" 
#include "BitmapExample.h" 
#include "BitmapExampleDlg.h" 
#include "Dib.h" 
#include "ShowDibDlg.h" 
#include "ShowMaskDlg.h" 
#include "ShowResult.h" 
 
 
#include"picture.h" 
#include"fast.h" 
#include"tv.h" 
//#include"tv.h" 
#include 
#include 
#include 
#include 
//#include 
 
 
#ifdef _DEBUG 
#define new DEBUG_NEW 
#undef THIS_FILE 
static char THIS_FILE[] = __FILE__; 
#endif 
 
///////////////////////////////////////////////////////////////////////////// 
// CBitmapExampleDlg dialog 
 
CString dibpath; 
CString maskpath; 
 
 
 
 
//int liter; 
 
CBitmapExampleDlg::CBitmapExampleDlg(CWnd* pParent /*=NULL*/) 
	: CDialog(CBitmapExampleDlg::IDD, pParent) 
{ 
	//{{AFX_DATA_INIT(CBitmapExampleDlg) 
	m_strDibPath = _T(""); 
	m_strMaskPath = _T(""); 
	m_nRunNumber = 0; 
	//}}AFX_DATA_INIT 
	// Note that LoadIcon does not require a subsequent DestroyIcon in Win32 
	m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME); 
} 
 
void CBitmapExampleDlg::DoDataExchange(CDataExchange* pDX) 
{ 
	CDialog::DoDataExchange(pDX); 
	//{{AFX_DATA_MAP(CBitmapExampleDlg) 
	DDX_Control(pDX, IDC_COMBO_IPMETHOD, m_cmbIpmethod); 
	DDX_Text(pDX, IDC_EDIT_DIBPATH, m_strDibPath); 
	DDX_Text(pDX, IDC_EDIT_MASKPATH, m_strMaskPath); 
	DDX_Text(pDX, IDC_EDIT_RUNNUMBER, m_nRunNumber); 
	//}}AFX_DATA_MAP 
} 
 
BEGIN_MESSAGE_MAP(CBitmapExampleDlg, CDialog) 
	//{{AFX_MSG_MAP(CBitmapExampleDlg) 
	ON_WM_PAINT() 
	ON_WM_QUERYDRAGICON() 
	ON_COMMAND(IDM_OPENDIBPIC, OnOpendibpic) 
	ON_COMMAND(IDM_OPENMASK, OnOpenmask) 
	ON_BN_CLICKED(IDC_BUTTON_DIB, OnButtonDib) 
	ON_BN_CLICKED(IDC_BUTTON_MASK, OnButtonMask) 
	ON_BN_CLICKED(IDC_BUTTON_RUN, OnButtonRun) 
	ON_BN_CLICKED(IDC_BUTTON_SAVE, OnButtonSave) 
	ON_WM_CLOSE() 
	//}}AFX_MSG_MAP 
END_MESSAGE_MAP() 
 
///////////////////////////////////////////////////////////////////////////// 
// CBitmapExampleDlg message handlers 
 
BOOL CBitmapExampleDlg::OnInitDialog() 
{ 
	CDialog::OnInitDialog(); 
 
	// Set the icon for this dialog.  The framework does this automatically 
	//  when the application's main window is not a dialog 
	SetIcon(m_hIcon, TRUE);			// Set big icon 
	SetIcon(m_hIcon, FALSE);		// Set small icon 
	 
	// TODO: Add extra initialization here 
 
	((CComboBox*)GetDlgItem(IDC_COMBO_IPMETHOD))->SetCurSel(0); 
	panduan=0; 
	 
	return TRUE;  // return TRUE  unless you set the focus to a control 
} 
 
// If you add a minimize button to your dialog, you will need the code below 
//  to draw the icon.  For MFC applications using the document/view model, 
//  this is automatically done for you by the framework. 
 
void CBitmapExampleDlg::OnPaint()  
{ 
	if (IsIconic()) 
	{ 
		CPaintDC dc(this); // device context for painting 
 
		SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0); 
 
		// Center icon in client rectangle 
		int cxIcon = GetSystemMetrics(SM_CXICON); 
		int cyIcon = GetSystemMetrics(SM_CYICON); 
		CRect rect; 
		GetClientRect(&rect); 
		int x = (rect.Width() - cxIcon + 1) / 2; 
		int y = (rect.Height() - cyIcon + 1) / 2; 
 
		// Draw the icon 
		dc.DrawIcon(x, y, m_hIcon); 
	} 
	else 
	{ 
		CDialog::OnPaint(); 
		 
		 
		 
	} 
} 
 
// The system calls this to obtain the cursor to display while the user drags 
//  the minimized window. 
HCURSOR CBitmapExampleDlg::OnQueryDragIcon() 
{ 
	return (HCURSOR) m_hIcon; 
} 
 
void CBitmapExampleDlg::OnOpendibpic()  
{ 
	// TODO: Add your command handler code here 
UpdateData(true); 
	// 弹出文件对话框,让用户选择位图文件 
	CFileDialog fileDialog(TRUE, "*.BMP", NULL, NULL,"位图文件(*.BMP)|*.bmp;*.BMP|"); 
    if (IDOK == fileDialog.DoModal()) 
	{ 
		CShowDibDlg *pDlg=new CShowDibDlg(); 
        pDlg->Create(IDD_DIALOG_DIB);     //要显示的对话框的ID号    
        pDlg->ShowWindow(SW_SHOW); 
		CDC *pDc=pDlg->GetDC(); 
	 
	//加载位图并显示之 
        CDib dib; 
		dibpath=fileDialog.GetPathName(); 
		m_strDibPath=dibpath; 
		UpdateData(false); 
		if (dib.Load(fileDialog.GetPathName())) 
		{ 
			dib.SetPalette(pDc); 
			dib.Draw(pDc); 
//MoveWindow(0,0,dibwidth,dibheight,TRUE); 
			//UpdateWindow(); 
		} 
	} 
 
} 
 
void CBitmapExampleDlg::OnOpenmask()  
{ 
	// TODO: Add your command handler code here 
UpdateData(true); 
	// 弹出文件对话框,让用户选择位图文件 
	CFileDialog fileDialog(TRUE, "*.BMP", NULL, NULL,"位图文件(*.BMP)|*.bmp;*.BMP|"); 
    if (IDOK == fileDialog.DoModal()) 
	{ 
		CShowMaskDlg *pDlg=new CShowMaskDlg(); 
        pDlg->Create(IDD_DIALOG_MASK);     //要显示的对话框的ID号    
        pDlg->ShowWindow(SW_SHOW); 
        CDC *pDc=pDlg->GetDC(); 
	 
	//加载位图并显示之 
        CDib dib; 
		maskpath=fileDialog.GetPathName(); 
        m_strMaskPath=maskpath; 
		UpdateData(false); 
		if (dib.Load(fileDialog.GetPathName())) 
		{ 
			//CClientDC dc(this); 
			//CDC dc; 
			//dc.m_hDC=::GetDC(NULL); 
            //CClientDC dc(GetDlgItem(IDD_DIALOG_MASK)); 
			dib.SetPalette(pDc); 
			dib.Draw(pDc); 
		} 
	} 
} 
 
void CBitmapExampleDlg::OnButtonDib()  
{ 
	// TODO: Add your control notification handler code here 
	UpdateData(true); 
	// 弹出文件对话框,让用户选择位图文件 
	CFileDialog fileDialog(TRUE, "*.BMP", NULL, NULL,"位图文件(*.BMP)|*.bmp;*.BMP|"); 
    if (IDOK == fileDialog.DoModal()) 
	{ 
		CShowDibDlg *pDlg=new CShowDibDlg(); 
        pDlg->Create(IDD_DIALOG_DIB);     //要显示的对话框的ID号    
        pDlg->ShowWindow(SW_SHOW); 
		CDC *pDc=pDlg->GetDC(); 
	 
	//加载位图并显示之 
        CDib dib; 
		dibpath=fileDialog.GetPathName(); 
		m_strDibPath=dibpath; 
		UpdateData(false); 
		if (dib.Load(fileDialog.GetPathName())) 
		{ 
			//CClientDC dc(this);//显示在主对话框 
			 
			//CDC dc; 
			//dc.m_hDC=::GetDC(NULL);//这两句显示在屏幕左上角 
            //CClientDC dc(GetDlgItem(IDD_DIALOG_DIB));//想用这句显示在子对话框,但是没有实现 
			dib.SetPalette(pDc); 
			dib.Draw(pDc); 
		 
		} 
	} 
} 
 
void CBitmapExampleDlg::OnButtonMask()  
{ 
	// TODO: Add your control notification handler code here 
	UpdateData(true); 
	// 弹出文件对话框,让用户选择位图文件 
	CFileDialog fileDialog(TRUE, "*.BMP", NULL, NULL,"位图文件(*.BMP)|*.bmp;*.BMP|"); 
    if (IDOK == fileDialog.DoModal()) 
	{ 
		CShowMaskDlg *pDlg=new CShowMaskDlg(); 
        pDlg->Create(IDD_DIALOG_MASK);     //要显示的对话框的ID号    
        pDlg->ShowWindow(SW_SHOW); 
        CDC *pDc=pDlg->GetDC(); 
	 
	//加载位图并显示之 
        CDib dib; 
		maskpath=fileDialog.GetPathName(); 
		m_strMaskPath=maskpath; 
		UpdateData(false); 
 
		if (dib.Load(fileDialog.GetPathName())) 
		{ 
			//CClientDC dc(this); 
			//CDC dc; 
			//dc.m_hDC=::GetDC(NULL); 
            //CClientDC dc(GetDlgItem(IDD_DIALOG_MASK)); 
			dib.SetPalette(pDc); 
			dib.Draw(pDc); 
		} 
	} 
} 
 
 
void CBitmapExampleDlg::OnButtonRun()  
{ 
	// TODO: Add your control notification handler code here 
	int nIndex=m_cmbIpmethod.GetCurSel(); 
	m_nRunNumber=GetDlgItemInt(IDC_EDIT_RUNNUMBER); 
	//liter=m_nRunNumber; 
	BMPfile BMP1,BMP2,BMP3; 
	fast fast1; 
	tv tv1; 
	int len1,len2; 
	char *a,*b; 
	len1=dibpath.GetLength(); 
	len2=maskpath.GetLength(); 
	a=new char[len1]; 
	b=new char[len2]; 
	a=dibpath.GetBuffer(0); 
	b=maskpath.GetBuffer(0); 
	BMP1.loadBMP(a);//读原图像 
	BMP2.loadBMP(b);//读模板	 
	BMP3.width=BMP1.bitmapinfo.biWidth; 
	BMP3.height=BMP1.bitmapinfo.biHeight; 
	for(int n=0;nCreate(IDD_DIALOG_RESULT);     //要显示的对话框的ID号    
        pDlg->ShowWindow(SW_SHOW); 
		panduan=1; 
	} 
 
 
 
	 
 
	 	CDC *pDc=pDlg->GetDC(); 
	    CDib dib; 
        if (dib.Load("E:/new77.bmp")) 
		{ 
			 
			dib.SetPalette(pDc); 
			dib.Draw(pDc); 
 
		} 
	 
	 
	 
	//liter=m_nRunNumber; 
} 
 
void CBitmapExampleDlg::OnButtonSave()  
{ 
	// TODO: Add your control notification handler code here 
	CFileDialog fileDialog(FALSE, "*.BMP", NULL, OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT,"位图文件(*.BMP)|*.bmp;*.BMP|"); 
      if   (fileDialog.DoModal()   ==   IDOK)  
	  {  
		  UpdateData(true); 
		  CDib dib; 
		  dib.Load("E:/new77.bmp"); 
		  dib.Save(fileDialog.m_ofn.lpstrFile); 
 
           
		  UpdateData(false); 
	  } 
 
} 
 
void CBitmapExampleDlg::OnClose()  
{ 
	// TODO: Add your message handler code here and/or call default 
	CString StrDestFile="E:/new77.bmp";  
		  DeleteFile(StrDestFile); 
	CDialog::OnClose(); 
}