⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 mainfrm.cpp

📁 医学图象处理系统
💻 CPP
字号:
// MainFrm.cpp : implementation of the CMainFrame class
//

#include "stdafx.h"
#include "ImageLAB.h"

#include "MainFrm.h"
#include "AllImage.h"
#include "ImageLABDoc.h"
#include "ImageLABView.h"

#include "ChildFrm.h"


#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CMainFrame
IMPLEMENT_DYNAMIC(CMainFrame, CMDIFrameWnd)

BEGIN_MESSAGE_MAP(CMainFrame, CMDIFrameWnd)	
	ON_COMMAND_EX(CG_ID_VIEW_MYDIALOGBAR, OnBarCheck)
	ON_UPDATE_COMMAND_UI(CG_ID_VIEW_MYDIALOGBAR, OnUpdateControlBarMenu)
	ON_COMMAND_EX(IDW_MYTOOLBAR1, OnBarCheck)
	ON_UPDATE_COMMAND_UI(IDW_MYTOOLBAR1, OnUpdateControlBarMenu)

	ON_WM_INITMENUPOPUP()                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   
	ON_WM_MENUSELECT()
	ON_UPDATE_COMMAND_UI(ID_INDICATOR_DATE, OnUpdateDate)
	ON_UPDATE_COMMAND_UI(ID_INDICATOR_TIME, OnUpdateTime)
	//{{AFX_MSG_MAP(CMainFrame)
	ON_WM_CREATE()
	ON_COMMAND(ID_VIEW_STATUS_CHANGEFONT, OnViewStatusChangefont)
	ON_COMMAND(ID_WINDOW_CLOSEALL, OnWindowCloseall)
	ON_UPDATE_COMMAND_UI(ID_WINDOW_CLOSEALL, OnUpdateWindowCloseall)
	ON_WM_SIZE()
	ON_COMMAND(ID_BUTTONRESET, OnBCReset)
	ON_UPDATE_COMMAND_UI(ID_BUTTONRESET, OnUpdateBCReset)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/*int      CMainFrame::iSHospitalLength = 3;
CString  CMainFrame::lpHospital[] = {"湘雅医院",
										 "附二医院",
										 "附三医院" };*/

static UINT indicators[] =
{
	ID_SEPARATOR,           // status line indicator
	ID_INDICATOR_CAPS,
	ID_INDICATOR_NUM,
	ID_INDICATOR_SCRL,
};

/////////////////////////////////////////////////////////////////////////////
// CMainFrame construction/destruction

CMainFrame::CMainFrame()
{
	// CG: The following block was inserted by 'Status Bar' component.
	{
		m_nStatusPane1Width = -1;
		m_bMenuSelect = FALSE;
	}
}

CMainFrame::~CMainFrame()
{
}

int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
	CTime  tmpTime = CTime::GetCurrentTime();
	int year  = tmpTime.GetYear();
	int month = tmpTime.GetMonth();
	int day   = tmpTime.GetDay();

	if (CMDIFrameWnd::OnCreate(lpCreateStruct) == -1)
		return -1;
	
	if (!m_wndToolBar.Create(this) ||
		!m_wndToolBar.LoadToolBar(IDR_MAINFRAME))
	{
		TRACE0("Failed to create toolbar\n");
		return -1;      // fail to create
	}

	if (!m_wndStatusBar.Create(this) ||
		!m_wndStatusBar.SetIndicators(indicators,
		  sizeof(indicators)/sizeof(UINT)))
	{
		TRACE0("Failed to create status bar\n");
		return -1;      // fail to create
	}

	// TODO: Remove this if you don't want tool tips or a resizeable toolbar
	//m_wndToolBar.SetBarStyle(m_wndToolBar.GetBarStyle() |
	//	CBRS_TOOLTIPS | CBRS_FLYBY | CBRS_SIZE_DYNAMIC);
	m_wndToolBar.SetBarStyle(m_wndToolBar.GetBarStyle() |
		CBRS_GRIPPER | CBRS_BORDER_3D | CBRS_TOOLTIPS | CBRS_FLYBY | CBRS_SIZE_DYNAMIC);

	// TODO: Delete these three lines if you don't want the toolbar to
	//  be dockable
	m_wndToolBar.EnableDocking(CBRS_ALIGN_ANY);
	EnableDocking(CBRS_ALIGN_ANY);
	DockControlBar(&m_wndToolBar);
	m_wndToolBar.ModifyStyle(0, TBSTYLE_FLAT);


	// TODO: Delete these three lines if you don't want the toolbar to be dockable

	// CG: The following block was inserted by 'Status Bar' component.
	{
		// Find out the size of the static variable 'indicators' defined
		// by AppWizard and copy it
		int nOrigSize = sizeof(indicators) / sizeof(UINT);

		UINT* pIndicators = new UINT[nOrigSize + 2];
		memcpy(pIndicators, indicators, sizeof(indicators));

		// Call the Status Bar Component's status bar creation function
		if (!InitStatusBar(pIndicators, nOrigSize, 60))
		{
			TRACE0("Failed to initialize Status Bar\n");
			return -1;
		}
		delete[] pIndicators;
	}

	// TODO: Add a menu item that will toggle the visibility of the	// dialog bar named "My Dialog Bar":	//   1. In ResourceView, open the menu resource that is used by	//      the CMainFrame class	//   2. Select the View submenu	//   3. Double-click on the blank item at the bottom of the submenu	//   4. Assign the new item an ID: CG_ID_VIEW_MYDIALOGBAR	//   5. Assign the item a Caption: My Dialog Bar	// TODO: Change the value of CG_ID_VIEW_MYDIALOGBAR to an appropriate value:	//   1. Open the file resource.h	// CG: The following block was inserted by the 'Dialog Bar' component	{
		// Initialize dialog bar m_wndMyDialogBar
		if (!m_wndMyDialogBar.Create(this, CG_IDD_RIGHTBAR,
			CBRS_RIGHT | CBRS_TOOLTIPS | CBRS_FLYBY | CBRS_HIDE_INPLACE,
			CG_ID_VIEW_MYDIALOGBAR))
		{
			TRACE0("Failed to create dialog bar m_wndMyDialogBar\n");
			return -1;		// fail to create
		}

		//m_wndMyDialogBar.EnableDocking(CBRS_ALIGN_RIGHT | CBRS_ALIGN_LEFT);
		m_wndMyDialogBar.EnableDocking(CBRS_ALIGN_ANY);
		EnableDocking(CBRS_ALIGN_ANY);
		DockControlBar(&m_wndMyDialogBar);
	}
/*	if( !(year == 2000 && (month == 4 || month == 5)))
	{
		AfxMessageBox("对不起,使用期限已过!");
		return -1;
	}
//*/
	
	CPoint FloatPt;
	CSize DialogBarSize = m_wndMyDialogBar.CalcFixedLayout( false, false);
	CSize ToolBarSize = m_wndToolBar.CalcFixedLayout( false, false);
	FloatPt.x = ::GetSystemMetrics(SM_CXSCREEN) - DialogBarSize.cx - 8;
	FloatPt.y = ::GetSystemMetrics(SM_CYMENU) + ::GetSystemMetrics(SM_CYCAPTION)+
		        ToolBarSize.cx;	FloatControlBar(&m_wndMyDialogBar,  FloatPt); 

	// 改变状态行的字体的部分
    memset(&m_lf,0,sizeof(LOGFONT));
	m_lf.lfHeight=18;
	m_lf.lfWeight=18;
	strcpy(m_lf.lfFaceName,"宋体");
	VERIFY(m_font.CreateFontIndirect(&m_lf));
	m_wndStatusBar.SetFont(&m_font);

    UINT nID,nStyle;
	int cxWidth;
    m_wndStatusBar.GetPaneInfo(0, nID, nStyle, cxWidth);
    m_wndStatusBar.SetPaneInfo(0, nID, SBPS_STRETCH | SBPS_NORMAL, cxWidth);

	CRect rect(0, 0, 100, 100);
	CImageLABApp *lpApp = (CImageLABApp *)AfxGetApp();
	lpApp->m_scan.Create("scan",  "scan", WS_VISIBLE|WS_CHILD, rect, this, ID_SCAN);
	return 0;
}

BOOL CMainFrame::PreCreateWindow(CREATESTRUCT& cs)
{
	// TODO: Modify the Window class or styles here by modifying
	//  the CREATESTRUCT cs

	return CMDIFrameWnd::PreCreateWindow(cs);
}

/////////////////////////////////////////////////////////////////////////////
// CMainFrame diagnostics

#ifdef _DEBUG
void CMainFrame::AssertValid() const
{
	CMDIFrameWnd::AssertValid();
}

void CMainFrame::Dump(CDumpContext& dc) const
{
	CMDIFrameWnd::Dump(dc);
}

#endif //_DEBUG

/////////////////////////////////////////////////////////////////////////////
// CMainFrame message handlers

void CMainFrame::OnMenuSelect(UINT nItemID, UINT nFlags, HMENU hSysMenu)
{
  	CMDIFrameWnd::OnMenuSelect(nItemID, nFlags, hSysMenu);
  
	// CG: The following block was inserted by 'Status Bar' component.
	{
		// Restore first pane of the statusbar?
		if (nFlags == 0xFFFF && hSysMenu == 0 && m_nStatusPane1Width != -1)
		{
			m_bMenuSelect = FALSE;
			m_wndStatusBar.SetPaneInfo(0, 
				m_nStatusPane1ID, m_nStatusPane1Style, m_nStatusPane1Width);
			m_nStatusPane1Width = -1;   // Set it to illegal value
		}
		else 
		{
			m_bMenuSelect = TRUE;
		}
	}
}

void CMainFrame::OnInitMenuPopup(CMenu* pPopupMenu, UINT nIndex, BOOL bSysMenu)
{
  	CMDIFrameWnd::OnInitMenuPopup(pPopupMenu, nIndex, bSysMenu);
  
	// CG: The following block was inserted by 'Status Bar' component.
	{
		// store width of first pane and its style
		if (m_nStatusPane1Width == -1 && m_bMenuSelect)
		{
			m_wndStatusBar.GetPaneInfo(0, m_nStatusPane1ID, 
				m_nStatusPane1Style, m_nStatusPane1Width);
			m_wndStatusBar.SetPaneInfo(0, m_nStatusPane1ID, 
				SBPS_NOBORDERS|SBPS_STRETCH, 16384);
		}
	}

}

void CMainFrame::OnUpdateDate(CCmdUI* pCmdUI)
{
	// CG: This function was inserted by 'Status Bar' component.
	if(!m_wndStatusBar.IsWindowVisible()) 
		return;
	// Get current date and format it
	CTime time = CTime::GetCurrentTime();
	//CString strDate = time.Format(_T("%x"));
	CString strDate = time.Format(_T("%d/%m/%Y")); 

	// BLOCK: compute the width of the date string
	CSize size;
	{
		HGDIOBJ hOldFont = NULL;
		HFONT hFont = (HFONT)m_wndStatusBar.SendMessage(WM_GETFONT);
		CClientDC dc(NULL);
		if (hFont != NULL) 
			hOldFont = dc.SelectObject(hFont);
		size = dc.GetTextExtent(strDate);
		if (hOldFont != NULL) 
			dc.SelectObject(hOldFont);
	}

	// Update the pane to reflect the current date
	UINT nID, nStyle;
	int nWidth;
	m_wndStatusBar.GetPaneInfo(m_nDatePaneNo, nID, nStyle, nWidth);
	m_wndStatusBar.SetPaneInfo(m_nDatePaneNo, nID, nStyle, size.cx);
	pCmdUI->SetText(strDate);
	pCmdUI->Enable(TRUE);

}

void CMainFrame::OnUpdateTime(CCmdUI* pCmdUI)
{
	// CG: This function was inserted by 'Status Bar' component.
	if(!m_wndStatusBar.IsWindowVisible()) 
		return;
	
	// Get current date and format it
	CTime time = CTime::GetCurrentTime();
	CString strTime = time.Format(_T("%X"));

	// BLOCK: compute the width of the date string
	CSize size;
	{
		HGDIOBJ hOldFont = NULL;
		HFONT hFont = (HFONT)m_wndStatusBar.SendMessage(WM_GETFONT);
		CClientDC dc(NULL);
		if (hFont != NULL) 
			hOldFont = dc.SelectObject(hFont);
		size = dc.GetTextExtent(strTime);
		if (hOldFont != NULL) 
			dc.SelectObject(hOldFont);
	}

	// Update the pane to reflect the current time
	UINT nID, nStyle;
	int nWidth;
	m_wndStatusBar.GetPaneInfo(m_nTimePaneNo, nID, nStyle, nWidth);
	m_wndStatusBar.SetPaneInfo(m_nTimePaneNo, nID, nStyle, size.cx);
	pCmdUI->SetText(strTime);
	pCmdUI->Enable(TRUE);
}

BOOL CMainFrame::InitStatusBar(UINT *pIndicators, int nSize, int nSeconds)
{
	// CG: This function was inserted by 'Status Bar' component.

	// Create an index for the DATE pane
	m_nDatePaneNo = nSize++;
	pIndicators[m_nDatePaneNo] = ID_INDICATOR_DATE;
	// Create an index for the TIME pane
	m_nTimePaneNo = nSize++;
	nSeconds = 1;
	pIndicators[m_nTimePaneNo] = ID_INDICATOR_TIME;

	// TODO: Select an appropriate time interval for updating
	// the status bar when idling.
	m_wndStatusBar.SetTimer(0x1000, nSeconds * 1000, NULL);

	return m_wndStatusBar.SetIndicators(pIndicators, nSize);
}

void CMainFrame::OnViewStatusChangefont() 
{
	CFontDialog dlg(&m_lf,CF_SCREENFONTS);
	if(dlg.DoModal()==IDOK)
	{
		m_font.DeleteObject();
		if(m_font.CreateFontIndirect(&m_lf))
		{
			m_wndStatusBar.SetFont(&m_font);
			RecalcLayout();
		}					   
	}    
}

BOOL CMainFrame::PreTranslateMessage(MSG* pMsg) 
{
	// TODO: Add your specialized code here and/or call the base class
	if (pMsg->message == WM_RBUTTONDOWN)
	{
		CWnd* pWnd = CWnd::FromHandlePermanent(pMsg->hwnd);
		CControlBar* pBar = DYNAMIC_DOWNCAST(CControlBar, pWnd);

		if (pBar != NULL)
		 {
			CMenu Menu;
			CPoint pt;

			pt.x = LOWORD(pMsg->lParam);
			pt.y = HIWORD(pMsg->lParam);
			pBar->ClientToScreen(&pt);

			if (Menu.LoadMenu(IDR_MENU_TOOLBAR))
			{
				CMenu* pSubMenu = Menu.GetSubMenu(0);

				if (pSubMenu!=NULL)
				{
					pSubMenu->TrackPopupMenu(TPM_LEFTALIGN | TPM_RIGHTBUTTON,pt.x,pt.y,this);
				}
			}
		}
	}
	return CMDIFrameWnd::PreTranslateMessage(pMsg);
}

BOOL CMainFrame::OnCreateClient(LPCREATESTRUCT lpcs, CCreateContext* pContext) 
{
	// TODO: Add your specialized code here and/or call the base class
	if (CMDIFrameWnd::OnCreateClient(lpcs, pContext))
	{
		m_wndMdiClient.SubclassWindow(m_hWndMDIClient);
		m_wndMdiClient.SetBitmap(IDB_BGBMP);
		return TRUE;
	}
	else
		return FALSE;
}

void CMainFrame::OnWindowCloseall() 
{
	CChildFrame *pChild, *pPrevChild = NULL;
	while((pChild = (CChildFrame *) MDIGetActive()) != NULL)
	{
		if (pChild == pPrevChild)
			return ;
		pPrevChild = pChild;
		pChild->SendMessage(WM_CLOSE);
	};	
}
void CMainFrame::OnUpdateWindowCloseall(CCmdUI* pCmdUI) 
{
	pCmdUI->Enable(MDIGetActive() != NULL);
}
// For mainframe client bachground pattern
CMdiClient::CMdiClient()
{
	m_pBmp = NULL;
	m_nBackColor = CLR_INVALID;
}

CMdiClient::~CMdiClient()
{
	if (m_pBmp)
	{
		m_pBmp->DeleteObject();
		delete m_pBmp;
		m_pBmp = NULL;
	}
}

IMPLEMENT_DYNCREATE(CMdiClient, CWnd)

BEGIN_MESSAGE_MAP(CMdiClient, CWnd)
	//{{AFX_MSG_MAP(CMdiClient)
	ON_WM_ERASEBKGND()
	ON_WM_SIZE()
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()


BOOL CMdiClient::OnEraseBkgnd(CDC* pDC) 
{
	CRect rect;
	GetClientRect(&rect);

	if (m_nBackColor != CLR_INVALID)
		pDC->FillSolidRect(&rect, m_nBackColor);
	else
		if (m_pBmp != NULL)
		{
			BITMAP bm;
			CDC dcMem;
			VERIFY(m_pBmp->GetObject(sizeof(BITMAP), (LPVOID)&bm));
			dcMem.CreateCompatibleDC(NULL);
			CBitmap* pOldBitmap = dcMem.SelectObject(m_pBmp);

			for (register int nX = 0; nX < rect.Width(); nX += bm.bmWidth)
				for (register int nY = 0; nY < rect.Height(); nY += bm.bmHeight)
					pDC->BitBlt(nX, nY, bm.bmWidth, bm.bmHeight, &dcMem, 0, 0, SRCCOPY);

			dcMem.SelectObject(pOldBitmap);
		}
		else
			CWnd::OnEraseBkgnd(pDC);

	return TRUE;
}

COLORREF CMdiClient::SetBackColor(COLORREF nBackColor)
{
	LockWindowUpdate();

	COLORREF cr = m_nBackColor;
	m_nBackColor = nBackColor;

	UnlockWindowUpdate();

	return cr;
}

BOOL CMdiClient::SetBitmap(UINT nID)
{
	BOOL bResult = true;

	LockWindowUpdate();

	if (m_pBmp)
	{
		m_pBmp->DeleteObject();
		delete m_pBmp;
		m_pBmp = NULL;
	}

	m_pBmp = new CBitmap();
	bResult = m_pBmp->LoadBitmap(nID);

	UnlockWindowUpdate();

	return bResult;
}

void CMdiClient::OnSize(UINT nType, int cx, int cy) 
{
	CWnd::OnSize(nType, cx, cy);
	
	if (m_pBmp != NULL)
		Invalidate();
}

void CMainFrame::OnSize(UINT nType, int cx, int cy) 
{
	CMDIFrameWnd::OnSize(nType, cx, cy);
	
	CImageLABView *pView = (CImageLABView*)GetActiveFrame()->GetActiveView( );
	if(pView!=NULL)
	{
		if(!pView->bFreeze)
		{
			pView->CG200Show(false);
			pView->ReSetDisplayPos();
			pView->CG200Show();
		}
		else
		{
			pView->ReSetDisplayPos();
		}	
	}
}
void CMainFrame::OnBCReset()
{
	m_wndMyDialogBar.ButtonReset();
}

void CMainFrame::OnUpdateBCReset(CCmdUI* pCmdUI)
{
	pCmdUI->Enable(m_wndMyDialogBar.IsButtonReset);
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -