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

📄 dlgpresetwindowing.cpp

📁 3D reconstruction, medical image processing from colons, using intel image processing for based clas
💻 CPP
字号:
// DlgPresetWindowing.cpp : implementation file//#include "stdafx.h"#include "fusion.h"#include "DlgPresetWindowing.h"#include "PresetWindowing.h"#include "PresetWindowingLC.h"#include "Buttons.h"#include "EditInt.h"#ifdef _DEBUG#define new DEBUG_NEW#undef THIS_FILEstatic char THIS_FILE[] = __FILE__;#endif/////////////////////////////////////////////////////////////////////////////// RxDlgPresetWindowing dialogRxDlgPresetWindowing::RxDlgPresetWindowing(CWnd* pParent /*=NULL*/)	: RxDlgCommon(pParent){	//{{AFX_DATA_INIT(RxDlgPresetWindowing)		// NOTE: the ClassWizard will add member initialization here	//}}AFX_DATA_INIT	m_strCaption		= "Windowing Preset";	m_pPresetWindowing	= NULL;	m_iLevelMin			= -1024;	m_iLevelMax			= 4095;	m_iLevel			= 0;	m_iWidth			= 100;	m_pBtnClose			= NULL;	m_pLCWindowing		= NULL;	m_pLCHotKey			= NULL;	m_pEdTitle			= NULL;	m_pEdLevel			= NULL;	m_pEdWidth			= NULL;	m_pBtnAdd			= NULL;	m_pBtnOk			= NULL;}BEGIN_MESSAGE_MAP(RxDlgPresetWindowing, RxDlgCommon)	//{{AFX_MSG_MAP(RxDlgPresetWindowing)	ON_WM_CREATE()	ON_WM_DESTROY()	//}}AFX_MSG_MAP	ON_NOTIFY(LISTCTRL_CHANGED,					ID_LISTCTRL_EDITBOX,		OnListCtrlChanged)	ON_COMMAND(IDD_PREWINDOWING_BTN_ADD,		OnBtnAdd)END_MESSAGE_MAP()/////////////////////////////////////////////////////////////////////////////// RxDlgPresetWindowing message handlersBOOL RxDlgPresetWindowing::OnInitDialog() {	RxDlgCommon::OnInitDialog();		m_pBtnClose->LoadBitmaps(IDB_BTN_CLOSE, CSize(14,14), BM_NORMAL|BM_SELECT);		m_pLCWindowing->SetFont(GetFont(), FALSE);	m_pLCWindowing->SetExtendedStyle(WS_EX_CLIENTEDGE|LVS_EX_FULLROWSELECT|LVS_EX_GRIDLINES);	m_pLCWindowing->InsertColumn(0, _T("Title"), LVCFMT_CENTER, 85);	m_pLCWindowing->InsertColumn(1, _T("Level"), LVCFMT_RIGHT,  50);	m_pLCWindowing->InsertColumn(2, _T("Width"), LVCFMT_RIGHT,  50);	int				iWindowingCount = m_pPresetWindowing->GetPresetWindowingCount();	_PRESET_WINDOWING_PTR	stpPresetWindowing;	int				iHotKey;	CString			strHotKey[12];	CString			strTemp;	for(int i = 0; i < 12; i++)		strHotKey[i].Empty();	for(i = 0; i < iWindowingCount; i++)	{		stpPresetWindowing = (_PRESET_WINDOWING_PTR)m_pPresetWindowing->GetPresetWindowing(i);		m_pLCWindowing->InsertItem(i, stpPresetWindowing->strTitle);		strTemp.Format(_T("%d"), stpPresetWindowing->iLevel);		m_pLCWindowing->SetItemText(i, 1, strTemp);		strTemp.Format(_T("%d"), stpPresetWindowing->iWidth);		m_pLCWindowing->SetItemText(i, 2, strTemp);		iHotKey = stpPresetWindowing->iHotKey;		if(iHotKey > -1 && iHotKey < 12)			strHotKey[iHotKey] = stpPresetWindowing->strTitle;	}	m_pLCHotKey->SetFont(GetFont(), FALSE);	m_pLCHotKey->SetExtendedStyle(WS_EX_CLIENTEDGE|LVS_EX_FULLROWSELECT|LVS_EX_GRIDLINES);	m_pLCHotKey->InsertColumn(0, _T("Hot Key"), LVCFMT_CENTER, 50);	m_pLCHotKey->InsertColumn(1, _T("Title"),   LVCFMT_LEFT,   85);	for(i = 0; i < 12; i++)	{		strTemp.Format(_T("     F%d"), i+1);		m_pLCHotKey->InsertItem(i, strTemp);		m_pLCHotKey->SetItemText(i, 1, strHotKey[i]);	}	m_pEdTitle->SetFont(GetFont(), FALSE);	m_pEdTitle->SetWindowText(_T("Untitled"));	m_pEdLevel->SetFont(GetFont(), FALSE);	m_pEdLevel->SetRange(m_iLevelMin, m_iLevelMax);	m_pEdLevel->SetEdit(m_iLevel);	m_pEdWidth->SetFont(GetFont(), FALSE);	m_pEdWidth->SetRange(2, 2050);	m_pEdWidth->SetEdit(m_iWidth);	m_pBtnAdd->SetFont(GetFont(), FALSE);	m_pBtnOk->SetFont(GetFont(), FALSE);		return TRUE;  // return TRUE unless you set the focus to a control	              // EXCEPTION: OCX Property Pages should return FALSE}int RxDlgPresetWindowing::OnCreate(LPCREATESTRUCT lpCreateStruct) {	if (RxDlgCommon::OnCreate(lpCreateStruct) == -1)		return -1;		CRect		rcClient(0, 0, 400, 350);	// 促捞倔肺弊 冠胶狼 农扁甫 绊沥 矫挪促.	VERIFY(SetWindowPos(NULL, -1, -1, rcClient.Width(), rcClient.Height(), 						SWP_NOMOVE|SWP_NOZORDER|SWP_NOREDRAW|SWP_NOACTIVATE));	// Create Close Button	UINT	nStyle   = WS_CHILD|WS_VISIBLE|BS_PUSHBUTTON;	m_pBtnClose			= new RxBitmapButton;	m_pBtnClose->Create		(NULL, nStyle, CRect(rcClient.right-22, rcClient.top+1, 0, 0), this, IDCANCEL);	nStyle = WS_CHILD|WS_VISIBLE|WS_BORDER|LVS_REPORT;	m_pLCWindowing		= new RxPresetWindowingLC;	m_pLCWindowing->Create	(nStyle,			CRect( 15, 30,220,220), this, IDD_PREWINDOWING_LC_WINDOWING);	m_pLCHotKey			= new CListCtrl;	m_pLCHotKey->Create		(nStyle,			CRect(230, 30,380,220), this, IDD_PREWINDOWING_LC_HOTKEY);	nStyle = WS_CHILD|WS_VISIBLE|WS_BORDER|ES_CENTER;	m_pEdTitle			= new CEdit;	m_pEdTitle->Create		(nStyle,			CRect( 30,270,150,290), this, IDD_PREWINDOWING_ED_TITLE);	m_pEdLevel			= new RxEditInt;	m_pEdLevel->Create		(nStyle,			CRect(160,270,210,290), this, IDD_PREWINDOWING_ED_LEVEL);	m_pEdWidth			= new RxEditInt;	m_pEdWidth->Create		(nStyle,			CRect(220,270,270,290), this, IDD_PREWINDOWING_ED_WIDTH);	nStyle	= WS_CHILD|WS_VISIBLE|BS_PUSHBUTTON;	m_pBtnAdd			= new RxPushButton;	m_pBtnAdd->Create		(_T("Add"), nStyle,	CRect(300,270,360,290), this, IDD_PREWINDOWING_BTN_ADD);	m_pBtnOk			= new RxPushButton;	m_pBtnOk->Create		(_T("Ok"), nStyle,	CRect(170,315,240,335), this, IDOK);		return 0;}void RxDlgPresetWindowing::OnDestroy() {	RxDlgCommon::OnDestroy();		if(m_pBtnClose)				delete m_pBtnClose;	if(m_pLCWindowing)			delete m_pLCWindowing;	if(m_pLCHotKey)				delete m_pLCHotKey;	if(m_pEdTitle)				delete m_pEdTitle;	if(m_pEdLevel)				delete m_pEdLevel;	if(m_pEdWidth)				delete m_pEdWidth;	if(m_pBtnAdd)				delete m_pBtnAdd;	if(m_pBtnOk)				delete m_pBtnOk;}void RxDlgPresetWindowing::OnDraw(CDC *pDC){	RxDlgCommon::OnDraw(pDC);	CFont	*pOldFont = pDC->SelectObject(GetFont());	pDC->SetBkMode(TRANSPARENT);	pDC->SetTextColor(RGB(  0,  0,  0));	pDC->TextOut( 70,254, _T("Title"));	pDC->TextOut(170,254, _T("Level"));	pDC->TextOut(230,254, _T("Width"));	DrawStaticBox(pDC, CRect( 15,240,380,300), _T("Current value"));	pDC->SelectObject(pOldFont);}/////////////////////////////////////////////////////////////////////////////BOOL RxDlgPresetWindowing::PreTranslateMessage(MSG* pMsg) {	if(pMsg->message == WM_KEYDOWN)	{		// Windowing list control		if(m_pLCWindowing->GetSafeHwnd() == ::GetFocus())		{			if(pMsg->wParam >= VK_F1 && pMsg->wParam <= VK_F12)			{				int		iItemCount = m_pLCWindowing->GetItemCount();				int		iOldItem, iHotKey = pMsg->wParam - VK_F1;				for(int i = 0; i < iItemCount; i++)				{					if(m_pLCWindowing->GetItemState(i, LVIS_SELECTED) & LVIS_SELECTED)					{						_PRESET_WINDOWING_PTR	stpPresetWindowing;						iOldItem = m_pPresetWindowing->GetPresetWindowingByHotKey(iHotKey);						if(iOldItem > -1)						{							stpPresetWindowing = m_pPresetWindowing->GetPresetWindowing(iOldItem);							stpPresetWindowing->iHotKey = -1;						}						stpPresetWindowing = m_pPresetWindowing->GetPresetWindowing(i);						if(stpPresetWindowing->iHotKey > -1)							m_pLCHotKey->SetItemText(stpPresetWindowing->iHotKey, 1, _T(""));						stpPresetWindowing->iHotKey = iHotKey;						m_pLCHotKey->SetItemText(iHotKey, 1, stpPresetWindowing->strTitle);						break;					}				}			}			else if(pMsg->wParam == VK_DELETE)			{				int		iItemCount = m_pLCWindowing->GetItemCount();				for(int i = iItemCount-1; i > -1; i--)				{					if(m_pLCWindowing->GetItemState(i, LVIS_SELECTED) & LVIS_SELECTED)					{						m_pLCWindowing->DeleteItem(i);						_PRESET_WINDOWING_PTR	stpPresetWindowing = m_pPresetWindowing->GetPresetWindowing(i);						if(stpPresetWindowing->iHotKey != -1)							m_pLCHotKey->SetItemText(stpPresetWindowing->iHotKey, 1, _T(""));						m_pPresetWindowing->RemovePresetWindowing(i);					}				}			}		}		else if(m_pLCHotKey->GetSafeHwnd() == ::GetFocus())		{			if(pMsg->wParam == VK_DELETE)			{				int		iItemCount = m_pLCHotKey->GetItemCount();				int		iIndex;				for(int i = 0; i < iItemCount; i++)				{					if(m_pLCHotKey->GetItemState(i, LVIS_SELECTED) & LVIS_SELECTED)					{						iIndex = m_pPresetWindowing->GetPresetWindowingByHotKey(i);						if(iIndex > -1)						{							m_pLCHotKey->SetItemText(i, 1, _T(""));							_PRESET_WINDOWING_PTR	stpPresetWindowing = m_pPresetWindowing->GetPresetWindowing(iIndex);							stpPresetWindowing->iHotKey = -1;						}					}				}			}		}	}		return RxDlgCommon::PreTranslateMessage(pMsg);}void RxDlgPresetWindowing::OnListCtrlChanged(NMHDR* pNMHDR, LRESULT* pResult){	NMLCEB_CTRL		*pNMLCEB = (NMLCEB_CTRL *)pNMHDR;	if(pNMLCEB->iCol == 0)	{		BOOL		bExistTitle = FALSE;		CString		strTemp;				// valiate the title name		for(int i = 0; i < m_pLCWindowing->GetItemCount(); i++)		{			strTemp = m_pLCWindowing->GetItemText(i, 0);			if(_tcsicmp(pNMLCEB->lpszText, strTemp) == 0)			{				bExistTitle = TRUE;				AfxMessageBox(_T("This input name already exists."));				m_pLCWindowing->SetItemState(pNMLCEB->iRow, LVIS_FOCUSED|LVIS_SELECTED, 0x0003);				m_pLCWindowing->SetFocus();				break;			}		}		if(!bExistTitle)		{			_PRESET_WINDOWING_PTR	stpPresetWindowing;			stpPresetWindowing = (_PRESET_WINDOWING_PTR)m_pPresetWindowing->GetPresetWindowing(pNMLCEB->iRow);			// configuration new-data 			_PRESET_WINDOWING		stPresetWindowing;			_tcscpy(stPresetWindowing.strTitle, pNMLCEB->lpszText);			stPresetWindowing.iLevel  = stpPresetWindowing->iLevel;			stPresetWindowing.iWidth  = stpPresetWindowing->iWidth;			stPresetWindowing.iHotKey = stpPresetWindowing->iHotKey;			// delete old-data and old-item			m_pPresetWindowing->RemovePresetWindowing(pNMLCEB->iRow);			m_pLCWindowing->DeleteItem(pNMLCEB->iRow);			// insert new-data			int		iInsertIndex = m_pPresetWindowing->AddPresetWindowing(&stPresetWindowing);			m_pLCWindowing->InsertItem(iInsertIndex, stPresetWindowing.strTitle);			strTemp.Format(_T("%d"), stPresetWindowing.iLevel);			m_pLCWindowing->SetItemText(iInsertIndex, 1, strTemp);			strTemp.Format(_T("%d"), stPresetWindowing.iWidth);			m_pLCWindowing->SetItemText(iInsertIndex, 2, strTemp);			// update the hotkey list control, if old-data has a hotkey			if(stPresetWindowing.iHotKey > -1)				m_pLCHotKey->SetItemText(stPresetWindowing.iHotKey, 1, stPresetWindowing.strTitle);			// update the windowing list control status			m_pLCWindowing->SetItemState(iInsertIndex, LVIS_FOCUSED|LVIS_SELECTED, 0x0003);			m_pLCWindowing->EnsureVisible(iInsertIndex, TRUE);			m_pLCWindowing->SetFocus();		}	}	else if(pNMLCEB->iCol == 1)	{		int				iLevel;		_stscanf(pNMLCEB->lpszText, _T("%d"), &iLevel);		if(m_iLevelMin <= iLevel && iLevel <= m_iLevelMax)		{			_PRESET_WINDOWING_PTR	stpPresetWindowing;			stpPresetWindowing = (_PRESET_WINDOWING_PTR)m_pPresetWindowing->GetPresetWindowing(pNMLCEB->iRow);			stpPresetWindowing->iLevel = iLevel;			m_pLCWindowing->SetItemText(pNMLCEB->iRow, pNMLCEB->iCol, pNMLCEB->lpszText);		}		else		{			CString		strTemp;			strTemp.Format(_T("Please check your input value. ( %d … %d )"), m_iLevelMin, m_iLevelMax);			AfxMessageBox(strTemp);		}		m_pLCWindowing->SetItemState(pNMLCEB->iRow, LVIS_FOCUSED|LVIS_SELECTED, 0x0003);		m_pLCWindowing->SetFocus();	}	else if(pNMLCEB->iCol == 2)	{		int				iWidth;		_stscanf(pNMLCEB->lpszText, _T("%d"), &iWidth);		if(2 <= iWidth && iWidth <= 2050)		{			_PRESET_WINDOWING_PTR	stpPresetWindowing;			stpPresetWindowing = (_PRESET_WINDOWING_PTR)m_pPresetWindowing->GetPresetWindowing(pNMLCEB->iRow);			stpPresetWindowing->iWidth = iWidth;			m_pLCWindowing->SetItemText(pNMLCEB->iRow, pNMLCEB->iCol, pNMLCEB->lpszText);		}		else		{			CString		strTemp;			strTemp.Format(_T("Please check your input value. ( 2 … 2050 )"));			AfxMessageBox(strTemp);		}		m_pLCWindowing->SetItemState(pNMLCEB->iRow, LVIS_FOCUSED|LVIS_SELECTED, 0x0003);		m_pLCWindowing->SetFocus();	}	*pResult = 0;}void RxDlgPresetWindowing::OnBtnAdd(){	_PRESET_WINDOWING_PTR	stpPresetWindowing;	int				iWindowingCount = m_pPresetWindowing->GetPresetWindowingCount();	CString			strTitle, strWindowing, strTemp;	m_pEdTitle->GetWindowText(strTitle);	if(strTitle.IsEmpty())	{		AfxMessageBox(_T("Enter content name."));		return;	}	for(int i = 0; i < iWindowingCount; i++)	{		stpPresetWindowing = (_PRESET_WINDOWING_PTR)m_pPresetWindowing->GetPresetWindowing(i);		if(_tcsicmp(strTitle, stpPresetWindowing->strTitle) == 0)		{			strTemp = _T("This input name already exists. Do you want to overwrite it?");			if(AfxMessageBox(strTemp, MB_OKCANCEL|MB_ICONWARNING) != IDOK)				return;			else			{				stpPresetWindowing->iLevel = (int)m_pEdLevel->GetEdit();				stpPresetWindowing->iWidth = (int)m_pEdWidth->GetEdit();				strTemp.Format(_T("%d"), stpPresetWindowing->iLevel);				m_pLCWindowing->SetItemText(i, 1, strTemp);				strTemp.Format(_T("%d"), stpPresetWindowing->iWidth);				m_pLCWindowing->SetItemText(i, 2, strTemp);				return;			}		}	}	int		iInsertIndex;	iInsertIndex = m_pPresetWindowing->AddPresetWindowing(strTitle,											(int)m_pEdLevel->GetEdit(), (int)m_pEdWidth->GetEdit(), -1);	m_pLCWindowing->InsertItem(iInsertIndex, strTitle);	strTemp.Format(_T("%d"), (int)m_pEdLevel->GetEdit());	m_pLCWindowing->SetItemText(iInsertIndex, 1, strTemp);	strTemp.Format(_T("%d"), (int)m_pEdWidth->GetEdit());	m_pLCWindowing->SetItemText(iInsertIndex, 2, strTemp);	// update the windowing list control status	m_pLCWindowing->SetItemState(iInsertIndex, LVIS_FOCUSED|LVIS_SELECTED, 0x0003);	m_pLCWindowing->EnsureVisible(iInsertIndex, TRUE);	m_pLCWindowing->SetFocus();}void RxDlgPresetWindowing::SetPresetWindowing(RxPresetWindowing *pPresetWindowing,										int iLevelMin, int iLevelMax, int iLevel, int iWidth){	m_pPresetWindowing	= pPresetWindowing;	m_iLevelMin			= iLevelMin;	m_iLevelMax			= iLevelMax;	m_iLevel			= iLevel;	m_iWidth			= iWidth;}

⌨️ 快捷键说明

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