www.pudn.com > 医学图像处理示例源代码.rar > ImageLAB.cpp


// ImageLAB.cpp : Defines the class behaviors for the application. 
// 
 
#include "stdafx.h" 
#include "ImageLAB.h" 
 
#include "MainFrm.h" 
#include "ChildFrm.h" 
#include "AllImage.h" 
#include "ImageLABDoc.h" 
#include "ImageLABView.h" 
#include "PreviewDlg.h" 
#include "firewnd.h" 
#include  
#include  
#include  
#include "InputImg.h" 
#include "CommonProc.h" 
 
#ifdef _DEBUG 
#define new DEBUG_NEW 
#undef THIS_FILE 
static char THIS_FILE[] = __FILE__; 
#endif 
int		CImageLABApp::DriveNum     = 0; 
int		CImageLABApp::SorceType    = 0; 
int		CImageLABApp::m_iPrintMode = 0; 
CString	CImageLABApp::SaveFileDir = "ImageLAB Files";  
///////////////////////////////////////////////////////////////////////////// 
// CImageLABApp 
 
BEGIN_MESSAGE_MAP(CImageLABApp, CWinApp) 
	//{{AFX_MSG_MAP(CImageLABApp) 
	ON_COMMAND(ID_APP_ABOUT, OnAppAbout) 
	ON_UPDATE_COMMAND_UI(ID_FILE_OPEN, OnUpdateFileOpen) 
	ON_COMMAND(ID_FILE_OPEN, OnFileOpen) 
	ON_COMMAND(ID_CAPTURE_CCD, OnCaptureCcd) 
	ON_COMMAND(ID_CAPTURE_SCAN, OnCaptureScan) 
	ON_UPDATE_COMMAND_UI(ID_CAPTURE_CCD, OnUpdateCaptureCcd) 
	//}}AFX_MSG_MAP 
	// Standard file based document commands 
	ON_COMMAND(ID_FILE_OPEN, CWinApp::OnFileOpen) 
	// Standard print setup command 
	ON_COMMAND(ID_FILE_PRINT_SETUP, CWinApp::OnFilePrintSetup) 
END_MESSAGE_MAP() 
 
///////////////////////////////////////////////////////////////////////////// 
// CImageLABApp construction 
 
CImageLABApp::CImageLABApp() 
{ 
	// TODO: add construction code here, 
	// Place all significant initialization in InitInstance 
	IsOpen = false; 
	DriveNum = GetDriveCount(); 
	SaveFileDir = "ImageLAB Files";  
	 
	CString FullDir;		 
	FullDir.Format("D:\\%s", SaveFileDir); 
	if(!IsExistFile(FullDir)) 
	{ 
		_mkdir(FullDir); 
	} 
} 
BOOL CImageLABApp::IsCCDCanCapture() 
{ 
	CPaintDC pDC(m_pMainWnd); 
	int Width  = pDC.GetDeviceCaps(HORZRES); 
	int Height = pDC.GetDeviceCaps(VERTRES); 
	return (Width>=1024 && Height>=768); 
} 
///////////////////////////////////////////////////////////////////////////// 
// The one and only CImageLABApp object 
 
CImageLABApp theApp; 
 
///////////////////////////////////////////////////////////////////////////// 
// CImageLABApp initialization 
 
BOOL CImageLABApp::InitInstance() 
{ 
	// CG: The following block was inserted by 'Status Bar' component. 
	{ 
		//Set up date and time defaults so they're the same as system defaults 
		setlocale(LC_ALL, ""); 
	} 
 
	AfxEnableControlContainer(); 
 
	// Standard initialization 
	// If you are not using these features and wish to reduce the size 
	//  of your final executable, you should remove from the following 
	//  the specific initialization routines you do not need. 
 
#ifdef _AFXDLL 
	Enable3dControls();			// Call this when using MFC in a shared DLL 
#else 
	Enable3dControlsStatic();	// Call this when linking to MFC statically 
#endif 
 
	// Change the registry key under which our settings are stored. 
	// You should modify this string to be something appropriate 
	// such as the name of your company or organization. 
	SetRegistryKey(_T("Film System")); 
 
	LoadStdProfileSettings(8);  // Load standard INI file options (including MRU) 
 
	// Register the application's document templates.  Document templates 
	//  serve as the connection between documents, frame windows and views. 
 
	CMultiDocTemplate* pDocTemplate; 
	pDocTemplate = new CMultiDocTemplate( 
		IDR_IMAGELTYPE, 
		RUNTIME_CLASS(CImageLABDoc), 
		RUNTIME_CLASS(CChildFrame), // custom MDI child frame 
		RUNTIME_CLASS(CImageLABView)); 
	AddDocTemplate(pDocTemplate); 
 
	// create main MDI Frame window 
	CMainFrame* pMainFrame = new CMainFrame; 
	if (!pMainFrame->LoadFrame(IDR_MAINFRAME)) 
		return FALSE; 
	m_pMainWnd = pMainFrame; 
 
	// Enable drag/drop open 
	m_pMainWnd->DragAcceptFiles(); 
 
	EnableShellOpen(); 
	//RegisterShellFileTypes(TRUE); 
 
	// Parse command line for standard shell commands, DDE, file open 
	/*CCommandLineInfo cmdInfo; 
	cmdInfo.m_nShellCommand = CCommandLineInfo::FileNothing; 
	ParseCommandLine(cmdInfo); 
	 
	// Dispatch commands specified on the command line 
	if (!ProcessShellCommand(cmdInfo)) 
		return FALSE;  //*/ 
 
	// The main window has been initialized, so show and update it. 
	pMainFrame->ShowWindow(SW_SHOWMAXIMIZED); 
	pMainFrame->UpdateWindow(); 
 
	return TRUE; 
} 
 
///////////////////////////////////////////////////////////////////////////// 
// CAboutDlg dialog used for App About 
 
class CAboutDlg : public CDialog 
{ 
public: 
	CAboutDlg(); 
	CFireWnd	m_FireWnd; 
	UINT        m_uTimerID; 
	CBitmapButton buttonOK; 
// Dialog Data 
	//{{AFX_DATA(CAboutDlg) 
	enum { IDD = IDD_ABOUTBOX }; 
	//}}AFX_DATA 
 
	// ClassWizard generated virtual function overrides 
	//{{AFX_VIRTUAL(CAboutDlg) 
	protected: 
	virtual void DoDataExchange(CDataExchange* pDX);    // DDX/DDV support 
	//}}AFX_VIRTUAL 
 
// Implementation 
protected: 
	virtual BOOL OnInitDialog(); 
	//{{AFX_MSG(CAboutDlg) 
	afx_msg void OnTimer(UINT nIDEvent); 
	virtual void OnOK(); 
	//}}AFX_MSG 
	DECLARE_MESSAGE_MAP() 
}; 
 
CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD) 
{ 
	//{{AFX_DATA_INIT(CAboutDlg) 
	//}}AFX_DATA_INIT 
	if (!buttonOK.LoadBitmaps(IDB_OK_UP, IDB_OK_DOWN, IDB_OK_FOCUS)) 
	{ 
		TRACE0("Failed to load bitmaps for buttons\n"); 
		AfxThrowResourceException(); 
	} 
} 
 
void CAboutDlg::DoDataExchange(CDataExchange* pDX) 
{ 
	CDialog::DoDataExchange(pDX); 
	//{{AFX_DATA_MAP(CAboutDlg) 
	DDX_Control(pDX, IDC_FIRE, m_FireWnd); 
	//}}AFX_DATA_MAP 
} 
 
BEGIN_MESSAGE_MAP(CAboutDlg, CDialog) 
	//{{AFX_MSG_MAP(CAboutDlg) 
	ON_WM_TIMER() 
	//}}AFX_MSG_MAP 
END_MESSAGE_MAP() 
 
// App command to run the dialog 
void CImageLABApp::OnAppAbout() 
{ 
	CAboutDlg aboutDlg; 
	aboutDlg.DoModal(); 
} 
 
///////////////////////////////////////////////////////////////////////////// 
// CImageLABApp commands 
 
BOOL CAboutDlg::OnInitDialog() 
{ 
	CDialog::OnInitDialog();	// CG:  This was added by System Info Component. 
 
	VERIFY(buttonOK.SubclassDlgItem(IDOK, this)); 
	buttonOK.SizeToContent(); 
 
	m_FireWnd.InitFire(rand()%3+1); 
	 
	m_uTimerID = SetTimer(0x451,33,NULL); 
	// CG: Following block was added by System Info Component. 
	{ 
		CString strFreeDiskSpace; 
		CString strFreeMemory; 
		CString strFmt; 
 
		// Fill available memory 
		MEMORYSTATUS MemStat; 
		MemStat.dwLength = sizeof(MEMORYSTATUS); 
		GlobalMemoryStatus(&MemStat); 
		strFmt.LoadString(CG_IDS_PHYSICAL_MEM); 
		strFreeMemory.Format("%lu MB ", MemStat.dwTotalPhys / (1024*1000)); 
 
		//TODO: Add a static control to your About Box to receive the memory 
		//      information.  Initialize the control with code like this: 
		// SetDlgItemText(IDC_PHYSICAL_MEM, strFreeMemory); 
 
		// Fill disk free information 
		struct _diskfree_t diskfree; 
		int nDrive = _getdrive(); // use current default drive 
		if (_getdiskfree(nDrive, &diskfree) == 0) 
		{ 
			strFmt.LoadString(CG_IDS_DISK_SPACE); 
			//TRACE("%s\n",strFmt); 
			strFreeDiskSpace.Format("%lu MB FREE on %c:", 
				(DWORD)diskfree.avail_clusters * 
				(DWORD)diskfree.sectors_per_cluster * 
				(DWORD)diskfree.bytes_per_sector / (DWORD)(1024*1000), 
				nDrive-1 + _T('A')); 
		} 
		else 
			strFreeDiskSpace.LoadString(CG_IDS_DISK_SPACE_UNAVAIL); 
 
        SetDlgItemText(IDC_FREEMEMORY,strFreeMemory);		 
		SetDlgItemText(IDC_FREEDISK,strFreeDiskSpace); 
 
		//TODO: Add a static control to your About Box to receive the memory 
		//      information.  Initialize the control with code like this: 
		// SetDlgItemText(IDC_DISK_SPACE, strFreeDiskSpace); 
	} 
 
	return TRUE;	// CG:  This was added by System Info Component. 
 
} 
 
void CImageLABApp::OnFileOpen()  
{ 
	IsOpen = true; 
	CString filt = "(*.JPG)|*.JPG|(*.BMP)|*.BMP|(*.PCX)|*.PCX|(*.GIF)|*.GIF||"; 
    CPreviewDlg  dlgFile(TRUE,"*.JPG","", OFN_HIDEREADONLY,filt,NULL); 
	dlgFile.m_ofn.Flags |= OFN_HIDEREADONLY|OFN_OVERWRITEPROMPT|OFN_ALLOWMULTISELECT; 
	CString InitDir = "D:\\" + SaveFileDir; 
	dlgFile.m_ofn.lpstrInitialDir = InitDir; 
	if(dlgFile.DoModal()==IDOK) 
	{ 
		POSITION pos = dlgFile.GetStartPosition(); 
		while(pos!=NULL) 
		{ 
			OpenDocumentFile(dlgFile.GetNextPathName(pos)); 
		} 
	} 
	IsOpen = false; 
} 
 
void CImageLABApp::OnUpdateFileOpen(CCmdUI* pCmdUI)  
{ 
	pCmdUI->SetCheck(IsOpen); 
} 
 
void CAboutDlg::OnTimer(UINT nIDEvent)  
{ 
	m_FireWnd.RenderFlame(); 
	m_FireWnd.PaintFlame(); 
	CDialog::OnTimer(nIDEvent); 
} 
 
void CAboutDlg::OnOK()  
{ 
	// TODO: Add extra validation here 
	KillTimer(m_uTimerID); 
	CDialog::OnOK(); 
} 
 
void CImageLABApp::OnCaptureCcd()  
{ 
	//CInputImg dlg; 
	//if(dlg.DoModal() == IDOK) 
	if( IsCCDCanCapture() ) 
	{ 
		SorceType = 1; 
		CWinApp::OnFileNew(); 
		CFrameWnd* pFrameWnd = STATIC_DOWNCAST(CFrameWnd, AfxGetMainWnd()); 
		CImageLABDoc *pDoc=(CImageLABDoc*)pFrameWnd->GetActiveFrame()->GetActiveDocument(); 
		if( pDoc != NULL) 
		{ 
			pDoc->Image.CreateEmpty(MaxImageWidth, MaxImageHeight, 24, 0xffffff); 
			pDoc->Image.BackUp(); 
			pDoc->Image.m_SorceType = 1; 
		} 
		pDoc->UpdateAllViews(NULL); 
		//pDoc->SetModifiedFlag(); 
		pDoc->m_pView->OnCaptureCcd(); 
	} 
	else 
	{ 
		AfxMessageBox("请将分辨率调整到\n至少1024×768才\n可以进行CCD采图!,"); 
	} 
} 
 
void CImageLABApp::OnUpdateCaptureCcd(CCmdUI* pCmdUI)  
{ 
	pCmdUI->SetCheck( SorceType == 1 ); 
} 
 
void CImageLABApp::OnCaptureScan()  
{ 
	TCHAR szTempPath [MAX_PATH]; 
	GetTempPath (MAX_PATH, szTempPath); 
 
	CString TempFile; 
	TempFile = CString(szTempPath) + "NewScanFile.bmp"; 
 
	m_scan.OpenScanner(); 
	m_scan.SetFileType(3); 
	m_scan.SetScanTo(2); 
	m_scan.SetImage(TempFile); 
	m_scan.StartScan(); 
	m_scan.CloseScanner(); 
 
	if(IsExistFile(TempFile)) 
	{ 
		SorceType = 2; 
		OpenDocumentFile(TempFile); 
		CFrameWnd* pFrameWnd = STATIC_DOWNCAST(CFrameWnd, AfxGetMainWnd()); 
		CImageLABDoc *pDoc=(CImageLABDoc*)pFrameWnd->GetActiveFrame()->GetActiveDocument(); 
		if( pDoc != NULL) 
		{ 
			pDoc->Image.m_SorceType = 2; 
			pDoc->ImageFileName   = "未命名图像文件";			 
			remove(TempFile); 
		} 
		pDoc->SetModifiedFlag(); 
	} 
}