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

📄 selpic.cpp

📁 超声影像工作站系统可与各种型号的B超、彩超连接
💻 CPP
字号:
// SelPic.cpp : implementation file
//

#include "stdafx.h"
#include "bxt.h"
#include "SelPic.h"
#include "Pic.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CSelPic dialog


CSelPic::CSelPic(char *path,bool *databuf,CWnd* pParent /*=NULL*/)
	: CDialog(CSelPic::IDD, pParent)
{
	//{{AFX_DATA_INIT(CSelPic)
	m_piccount = 0;
	m_mode = -1;
	m_firstpicid = 0;
	//}}AFX_DATA_INIT

	int		i;

	m_ifprint	= databuf;
	m_filepath	= path;
	for (i = 0; i < MAX_PIC; i++) m_ifprint[i] = false;

	CString m_filename;
	char	buf[10];
	FILE	*fp;

	for	(i = 1;; i++)
	{
		m_filename	= m_filepath + itoa(i,buf,10);
		m_filename	+= ".jpg";
		fp	= fopen(m_filename.GetBuffer(m_filename.GetLength()),"rb");
		if (!fp) break;
		fclose(fp);
	}

	m_piccount	= i - 1;

	m_firstpicid	= (m_piccount > 0)?1:0;

	m_picperpage	= 9;
	m_picperrow		= 3;
	m_picpercol		= 3;
	m_picwidth		= 187;
	m_picheight		= 130;
	m_spacex		= 197;
	m_spacey		= 150;
	
	m_mode			= 3;
}


void CSelPic::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CSelPic)
	DDX_Control(pDX, IDC_LIST_PRINT_LIST, m_printlist);
	DDX_Text(pDX, IDC_EDIT_PIC_COUNT, m_piccount);
	DDX_Radio(pDX, IDC_RADIO_MODE1, m_mode);
	DDX_Text(pDX, IDC_EDIT_CURRENTPIC, m_firstpicid);
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(CSelPic, CDialog)
	//{{AFX_MSG_MAP(CSelPic)
	ON_WM_PAINT()
	ON_BN_CLICKED(IDC_RADIO_MODE1, OnRadioMode1)
	ON_BN_CLICKED(IDC_RADIO_MODE2, OnRadioMode2)
	ON_BN_CLICKED(IDC_RADIO_MODE3, OnRadioMode3)
	ON_BN_CLICKED(IDC_RADIO_MODE4, OnRadioMode4)
	ON_BN_CLICKED(IDC_BUTTON_TOP, OnButtonTop)
	ON_BN_CLICKED(IDC_BUTTON_PRIOR, OnButtonPrior)
	ON_BN_CLICKED(IDC_BUTTON_NEXT, OnButtonNext)
	ON_BN_CLICKED(IDC_BUTTON_BOTTOM, OnButtonBottom)
	ON_WM_LBUTTONDBLCLK()
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CSelPic message handlers

BOOL CSelPic::OnInitDialog() 
{
	CDialog::OnInitDialog();

	if (m_piccount <= 0)
	{
		this->OnOK();
	}

	UpdateData(false);
	return TRUE; 
}

void CSelPic::OnPaint() 
{
	CPaintDC dc(this); // device context for painting
	ReDrawPic();
}

void CSelPic::ReDrawPic()
{
	int i;

	char	buf[10];
	CString	m_filename,msg;
	FILE	*fp	= NULL;
	CPic	pic;
	CDC		*dc	= GetDC();
	int		thex,they;
	int		basex = 20, basey = 16;

	dc->FillSolidRect(15,13,590,436,RGB(192,192,192));
	for (i = m_firstpicid; i < min(m_firstpicid + m_picperpage, m_piccount + 1); i++)
	{
		m_filename	= m_filepath + itoa(i,buf,10);
		m_filename	+= ".jpg";
		
		fp	= fopen(m_filename.GetBuffer(m_filename.GetLength()),"rb");
		if (!fp) break;
		fclose(fp);

		thex	= basex + (i - m_firstpicid) % m_picperrow * m_spacex;
		they	= basey + (i - m_firstpicid) / m_picperrow * m_spacey;
		pic.loadjpg(m_filename.GetBuffer(m_filename.GetLength()));
		pic.DrawBMP(dc,thex,they,m_picwidth,m_picheight,0);

		HiLight((i - m_firstpicid) % m_picperrow,(i - m_firstpicid) / m_picperrow,m_ifprint[i - 1]);
		msg = m_filename;
		msg += " [ID=";
		msg += itoa(i,buf,10);
		msg += "]";
//		dc->TextOut(thex,they,msg);
	}
	ReleaseDC(dc);
}

void CSelPic::OnRadioMode1() 
{
	UpdateData(true);
//	m_pagecount		= 1 + m_piccount / 1;
	m_picperpage	= 1;
	m_picperrow		= 1;
	m_picpercol		= 1;
	m_picwidth		= 582;
	m_picheight		= 430;
	m_spacex		= 602;
	m_spacey		= 450;
	UpdateData(false);
	ReDrawPic();
}

void CSelPic::OnRadioMode2() 
{
	UpdateData(true);
//	m_pagecount		= 1 + m_piccount / 4;
	m_picperpage	= 4;
	m_picperrow		= 2;
	m_picpercol		= 2;
	m_picwidth		= 280;
	m_picheight		= 206;
	m_spacex		= 300;
	m_spacey		= 226;
	UpdateData(false);
	ReDrawPic();
}

void CSelPic::OnRadioMode3() 
{
	UpdateData(true);
//	m_pagecount		= 1 + m_piccount / 6;
	m_picperpage	= 6;
	m_picperrow		= 3;
	m_picpercol		= 2;
	m_picwidth		= 187;
	m_picheight		= 205;
	m_spacex		= 197;
	m_spacey		= 225;
	UpdateData(false);
	ReDrawPic();
}

void CSelPic::OnRadioMode4() 
{
	UpdateData(true);
//	m_pagecount		= 1 + m_piccount / 9;
	m_picperpage	= 9;
	m_picperrow		= 3;
	m_picpercol		= 3;
	m_picwidth		= 187;
	m_picheight		= 130;
	m_spacex		= 197;
	m_spacey		= 150;
	UpdateData(false);
	ReDrawPic();
}

void CSelPic::OnButtonTop()
{
	if (m_piccount > 0 && m_firstpicid > 1)
	{
		m_firstpicid = 1;
		UpdateData(false);
		ReDrawPic();
	}
}

void CSelPic::OnButtonPrior() 
{
	if (m_piccount > 0 && m_firstpicid > 1)
	{
		if ((m_firstpicid -= m_picperpage) < 1) m_firstpicid = 1;
		UpdateData(false);
		ReDrawPic();
	}
}

void CSelPic::OnButtonNext() 
{
	if (m_piccount > 0 && (m_firstpicid + m_picperpage) < m_piccount + 1)
	{
		if ((m_firstpicid += m_picperpage) >= m_piccount + 1) m_firstpicid = m_piccount - m_picperpage + 1;
		UpdateData(false);
		ReDrawPic();
	}
}

void CSelPic::OnButtonBottom() 
{
	if (m_piccount > 0 && (m_firstpicid + m_picperpage) < m_piccount)
	{
		m_firstpicid = m_piccount - m_picperpage + 1;
		if (m_firstpicid < 1) m_firstpicid = 1;
		UpdateData(false);
		ReDrawPic();
	}
}

void CSelPic::ClearBackGround()
{
	CDC *dc = GetDC();
	ReleaseDC(dc);
}

void CSelPic::OnLButtonDblClk(UINT nFlags, CPoint point) 
{
	CString msg;
	char buf[10];
	int i,j,minx,maxx,miny,maxy,selitem;

	for (selitem = -1,i = 0; i < m_picperrow; i++)
	{
		minx = 20 + i * m_spacex;
		maxx = 20 + i * m_spacex + m_picwidth;
		if (point.x > minx && point.x < maxx)
		{
			for (j = 0; j < m_picpercol; j++)
			{
				miny = 16 + j * m_spacey;
				maxy = 16 + j * m_spacey + m_picheight;
				if (point.y > miny && point.y < maxy) 
				{
					selitem	= j * m_picperrow + i + m_firstpicid - 1;
					if (selitem < m_piccount && selitem >= 0)
					{
						m_ifprint[selitem]	= !m_ifprint[selitem];
						HiLight(i,j,m_ifprint[selitem]);
						msg = m_ifprint[selitem]?"选择第 ":"清除第 ";
						msg += itoa(selitem + 1,buf,10);
						msg += " 幅图像";
						m_printlist.AddString(msg);
					}
					break;
				}
			}
			break;
		}
	}
	CDialog::OnLButtonDblClk(nFlags, point);
}

void CSelPic::HiLight(int x, int y, bool hi)
{
	CDC *dc = GetDC();
	int r,g,b;
	if (hi)
	{
		r	= 255;
		g	= 0;
		b	= 0;
	}
	else
	{
		r	= 0;
		g	= 0;
		b	= 255;
	}

	CPen pen(PS_SOLID,2,RGB(r,g,b));
	CPen *old = dc->SelectObject(&pen);
	

	int minx,miny,maxx,maxy;
	minx = 20 + x * m_spacex;
	maxx = 20 + x * m_spacex + m_picwidth;
	miny = 16 + y * m_spacey;
	maxy = 16 + y * m_spacey + m_picheight;
	
	dc->MoveTo(minx,miny);
	dc->LineTo(maxx,miny);
	dc->LineTo(maxx,maxy);
	dc->LineTo(minx,maxy);
	dc->LineTo(minx,miny);
	
	dc->SelectObject(old);
	DeleteObject(&pen);

	ReleaseDC(dc);
}

⌨️ 快捷键说明

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