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

📄 dianzhendlg.cpp

📁 点阵汉字显示软件, 源码 当前针式打印机采用24针进行字符打印
💻 CPP
📖 第 1 页 / 共 3 页
字号:
	if(m_numPage == m_input / PAGENUM)
	{
		SmallFontDislpay(m_xpos, m_ypos, m_buf,GetDC(),1,m_dotColor,m_ndotColor,m_scanType);
	}
	else
	{
		m_numPage = m_input / PAGENUM;
		PrintPage(m_numPage);
	}		
	UpdateData(false);	
	SelByIndex(m_ndotColor,m_dotColor);
	SendDlgItemMessage(IDC_EDIT_CODE,EM_SETSEL,0,-1);
}

void CDianzhenDlg::OnBtnFp() //处理首页
{
	// TODO: Add your control notification handler code here
	if(m_numPage !=0){
		m_numPage = 0;
		m_input = m_input % PAGENUM;
		UpdateData(false);
		PrintPage(m_numPage);
		SelByIndex(m_ndotColor,m_dotColor);
	}
	else
	{
		MessageBox("已经是首页了!");
	}
}

void CDianzhenDlg::OnBtnLp() //处理末页
{
	// TODO: Add your control notification handler code here
	if(m_numPage != m_maxPage){
		m_numPage = m_maxPage;
		m_input = m_input%PAGENUM +m_numPage*PAGENUM;
		if(m_input > m_maxIndex)
		{
			m_input = m_maxIndex;
		}
		UpdateData(false);
		PrintPage(m_numPage);
		SelByIndex(m_ndotColor,m_dotColor);
	}
	else
	{
		MessageBox("已经是末页了!");
	}
}

void CDianzhenDlg::OnBtnPp() //处理前一页
{
	// TODO: Add your control notification handler code here
	if(m_numPage == 0)
	{	
		MessageBox("已经是首页了!");
	}
	else
	{
		m_numPage--;
		m_input -= PAGENUM;
		UpdateData(false);
		PrintPage(m_numPage);
		SelByIndex(m_ndotColor,m_dotColor);
	}
}

void CDianzhenDlg::OnBtnNp() //处理后一页
{
	// TODO: Add your control notification handler code here
	if(m_numPage ==m_maxPage)
	{
		MessageBox("已经是末页了!");
	}
	else
	{
		m_numPage++;
		m_input += PAGENUM;
		if(m_input>m_maxIndex){
			m_input = m_maxIndex;
		}
		UpdateData(false);
		PrintPage(m_numPage);
		SelByIndex(m_ndotColor,m_dotColor);
	}	
}

void CDianzhenDlg::OnBtnPage() //根据用户输入的页数进行处理
{
	// TODO: Add your control notification handler code here
	
	UpdateData(true);
	
	if(m_numPage<0 || m_numPage > m_maxPage) 
	{
		CString str;
		str.Format("页数超出范围(0-%d)!",m_maxPage);
		MessageBox(str);
		SendDlgItemMessage(IDC_EDIT_PAGE,EM_SETSEL,0,-1);
	}
	else
	{		
		m_input = m_input%PAGENUM +m_numPage*PAGENUM;
		if(m_input > m_maxIndex)
		{
			m_input = m_maxIndex;
		}
		UpdateData(false);
		PrintPage(m_numPage);
		SelByIndex(m_ndotColor,m_dotColor);
		SendDlgItemMessage(IDC_EDIT_PAGE,EM_SETSEL,0,-1);
	}
}

//窗口销毁使用应用程序保存的窗口句柄失效
void CDianzhenDlg::OnDestroy() 
{
	CDialog::OnDestroy();
	((CDianzhenApp *)AfxGetApp())->m_hwndDlg = NULL;
	// TODO: Add your message handler code here
	
}

//根据索引号来选择页面上的字
void CDianzhenDlg::SelByIndex(COLORREF &firstColor,COLORREF &secondColor)
{	
	//定位到相应的字上
	int num = m_input % PAGENUM;
	int row = num / ROWNUM; 
	int col = num % ROWNUM;	
	
	m_xpos = X_PAGE_START + row * 25;
	m_ypos = Y_PAGE_START + col * 25;
	
	memset(m_buf,0,sizeof(m_buf));
	fseek(m_pFile,m_input*DZ_NUM,SEEK_SET);
	fread(m_buf,1,DZ_NUM,m_pFile);
	
	//选定当前字
	
	/*定位相应页上的字,即将字符的前景与背景颜色互换,在同一位置上重新显示一遍,覆盖原来的字符*/
	SmallFontDislpay(m_xpos, m_ypos, m_buf,GetDC(),1,firstColor,secondColor,m_scanType);
	
	/*在点阵显示区放大显示当前字符点阵*/
	FontDisPlay(X_START, Y_START, m_buf,GetDC(),m_dotSize,m_dotBrush,m_notDotBrush,m_scanType);
	
	/************************************************************/
	CString str1;
	GetStr16FromByteArr(m_buf,str1);
	m_dzHexV.SetWindowText(str1);
	
	memset(m_destBuf,0,DZ_NUM);
	FromColtoRow(m_buf,m_destBuf);//行列转置
	//将以字节保存的字符点阵以十六进制的格式输出到文本框m_dzHexX中
	CString str2;
	GetStr16FromByteArr(m_destBuf,str2);
	m_dzHexH.SetWindowText(str2);	
	
	/************************************************************/
	
	/*设置字符编码
	char buf[10];
	GetCodeByIndex(m_input,buf);
	SetDlgItemText(IDC_EDIT_GBCODE,buf);*/

	//设置字符偏移量
	CString str;
	str.Format("0x%06x",m_input*DZ_NUM);
	SetDlgItemText(IDC_EDIT_GBCODE,str);
}

//利用鼠标点击来选择页面上的字符
void CDianzhenDlg::OnLButtonDown(UINT nFlags, CPoint point) 
{
	// TODO: Add your message handler code here and/or call default
	
	/*无效鼠标点击位置叛断*/
	if(point.x < X_PAGE_START || point.x > (X_PAGE_START + ROWNUM * 25) ||
		point.y < Y_PAGE_START || point.y > (Y_PAGE_START + COLNUM * 25))
	{
		return;
	}
	
	//末页鼠标位置判断
	if(m_numPage == m_maxPage)
	{
		int remain = m_maxIndex - m_maxPage*PAGENUM;
		int row = remain / ROWNUM;
		int col = remain - row * ROWNUM;
		
		if((point.y > (Y_PAGE_START + 25 * row)) && (point.y < (Y_PAGE_START + 25 * (row+1)))
			&& (point.x >(X_PAGE_START + 25 * (col+1))))
			return;
		if((point.y > (Y_PAGE_START + 25 * (row+1))))
			return;
	}
	
	//取消开始选择的字符
	SmallFontDislpay(m_xpos, m_ypos, m_buf,GetDC(),1,m_dotColor,m_ndotColor,m_scanType);
	
	//取得新的字符位置
	int row = (point.y - Y_PAGE_START) / 25;	/*取得行位置*/
	int col = (point.x - X_PAGE_START) / 25;	/*取得列位置*/
	
	m_xpos = X_PAGE_START + col* 25;
	m_ypos = Y_PAGE_START + row * 25;
	
	m_input = m_numPage * PAGENUM + row * ROWNUM + col; /*计算字符索引位置*/
	UpdateData(false);
	SelByIndex(m_ndotColor,m_dotColor);
}

HBRUSH CDianzhenDlg::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor) 
{
	HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor);
	
	// TODO: Change any attributes of the DC here
	if(pWnd -> GetDlgCtrlID() == IDC_DOTCOLOR)
	{
		return m_dotBrush;	/*有点颜色标识*/
	}
	if(pWnd -> GetDlgCtrlID() == IDC_NDOTCOLOR)
	{
		return m_notDotBrush;	/*无点颜色标识*/
	}
	// TODO: Return a different brush if the default is not desired  

	return hbr;
}

//处理滑动条以放大与缩小点阵字
void CDianzhenDlg::OnCustomdrawSlidEnlarge(NMHDR* pNMHDR, LRESULT* pResult) 
{
	// TODO: Add your control notification handler code here
	CRect rect;
	GetDlgItem(IDC_DZSHOW)->GetWindowRect(&rect);
	ScreenToClient(&rect);

	if(m_numEnlarge.GetPos() <= m_dotSize)
	{
		int len = 4;
		CRect temp(rect.left+len,rect.top+3*len,rect.right-len,rect.bottom-len);
		GetDC()->FillSolidRect(&temp,RGB(228,228,228));
	}

	m_dotSize = m_numEnlarge.GetPos();
	
	//重新设置点阵显示起始位置
	X_START = rect.top + (rect.Width()/2-12*m_dotSize);
	Y_START = rect.left + (rect.Height()/2-12*m_dotSize);
	
	//重新显示当前字符
	FontDisPlay(X_START,Y_START,m_buf,GetDC(),m_dotSize,m_dotBrush,m_notDotBrush,m_scanType);
	
	*pResult = 0;
}

//利用‘+’‘-’按键来放大缩小点阵字符
void CDianzhenDlg::DoSlidEnlarge(bool isLarge)
{
	if(isLarge)
	{
		if(++m_dotSize>MAX_FONT)
			m_dotSize = MAX_FONT;
	}
	else
	{
		if(--m_dotSize<MIN_FONT)
			m_dotSize = MIN_FONT;
	}
	m_numEnlarge.SetPos(m_dotSize);
}

//处理前一页
void CDianzhenDlg::DoPrePage()
{
	OnBtnPp();
}

//处理后一页
void CDianzhenDlg::DoNextPage()
{
	OnBtnNp();
}

//处理首页
void CDianzhenDlg::DoFirstPage()
{
	OnBtnFp();
}

//处理末页
void CDianzhenDlg::DoLastPage()
{
	OnBtnLp();
}

//处理向左箭头
void CDianzhenDlg::DoBtnPrevious()
{
	OnBtnPrevious();
}

//处理向右箭头
void CDianzhenDlg::DoBtnNext()
{
	OnBtnNext();
}

//根据索引号来获取字符通讯码(deprecated)
void CDianzhenDlg::GetCodeByIndex(int index,char* buf)
{
	int code1,code2,code3,code4;
	if(index < 10408)//一定是双字节
	{
		code1 = index / 192 + 0x81;
		code2 = index % 192 + 0x40;
		sprintf(buf,"%02x%02x",code1,code2);
		return;
	}
	
	//优先处理双字节
	if(((index/192)<=(0xFE-0x81)) && ((index%192)<=(0xFE-0x40)) && ((index%192)!=(0x7F-0x40)))
	{
		code1 = index/192 + 0x81;
		code2 = index%192 + 0x40;
		sprintf(buf,"%02x%02x",code1,code2);
		return;
	}
	
	//剩下都作四字节处理
	int temp1 = index - 10408;
	if(temp1 <12600) 
	{
		code1 = 0x81;
	}
	else
	{
		code1 = temp1/12600 + 0x81;
	}
	
	int temp2 = temp1-(code1-0x81)*12600;
	if(temp2 <1260) 
	{
		code2 = 0x30;
	}
	else
	{
		code2 = temp2/1260 + 0x30;
	}
	
	int temp3= temp2-(code2-0x30)*1260;
	if(temp3 <10) 
	{
		code3 = 0x81;
	}
	else
	{
		code3 = temp3/10 + 0x81;
	}
	
	code4 = temp3 - (code3-0x81)*10 + 0x30;
	sprintf(buf,"%02x%02x%02x%02x",code1,code2,code3,code4);
	
	return;
}

//选择有点颜色
void CDianzhenDlg::OnBtnDcolor() 
{
	CColorDialog dlg;
	
	dlg.m_cc.Flags |= CC_RGBINIT;
	dlg.m_cc.rgbResult = m_dotColor;
	
	if(IDOK == dlg.DoModal())
	{
		m_dotColor = dlg.m_cc.rgbResult;
		m_dotBrush.CreateSolidBrush(m_dotColor);		
		
		PrintPage(m_numPage);
		SmallFontDislpay(m_xpos, m_ypos, m_buf,GetDC(),1,m_ndotColor,m_dotColor,m_scanType);
		FontDisPlay(X_START, Y_START, m_buf,GetDC(),m_dotSize,m_dotBrush,m_notDotBrush,m_scanType);
		
		GetDlgItem(IDC_DOTCOLOR)->Invalidate();
		GetDlgItem(IDC_DOTCOLOR)->UpdateWindow();
	}
}

//选择无点颜色
void CDianzhenDlg::OnBtnNdcolor() 
{
	CColorDialog dlg;
	
	dlg.m_cc.Flags |= CC_RGBINIT;
	dlg.m_cc.rgbResult = m_ndotColor;
	
	if(IDOK == dlg.DoModal())
	{
		m_ndotColor = dlg.m_cc.rgbResult;
		m_notDotBrush.CreateSolidBrush(m_ndotColor);
		
		PrintPage(m_numPage);
		SmallFontDislpay(m_xpos, m_ypos, m_buf,GetDC(),1,m_ndotColor,m_dotColor,m_scanType);
		FontDisPlay(X_START, Y_START, m_buf,GetDC(),m_dotSize,m_dotBrush,m_notDotBrush,m_scanType);
		
		GetDlgItem(IDC_NDOTCOLOR)->Invalidate();
		GetDlgItem(IDC_NDOTCOLOR)->UpdateWindow();
	}
	
	
}

//选择文件
void CDianzhenDlg::OnBtnFile() 
{
	CFileDialog dlg(true);

	/**********start设定对话框风格**************/
	int structsize = 0;
	DWORD dwVersion;
	dwVersion = GetVersion();
	if(dwVersion < 0x80000000)
		structsize = 88;//xp风格
	else 
		structsize = 76;//老式风格
	dlg.m_ofn.lStructSize = structsize;
	/***********end*************/
	
	if(IDOK == dlg.DoModal())
	{
		FILE *ptemp;
		CString strFile;
		
		strFile = dlg.GetFileName();
		ptemp= fopen(strFile,"rb");//打开新文件
		
		if(!ptemp){
			MessageBox("文件打开失败!");
		}
		else
		{
			if(m_pFile)	fclose(m_pFile);//关闭原有打开文件
			m_pFile = ptemp;
			m_fileName = dlg.GetFileName();
			SetDlgItemText(IDC_EDIT_FILENAME,m_fileName);
			
			m_input = 0;
			m_numPage = 0;
			UpdateData(false);
			fseek(m_pFile,0,SEEK_END);
			m_maxIndex = ftell(m_pFile)/72;
			m_maxPage = m_maxIndex/PAGENUM;
			
			PrintPage(m_numPage);
			SelByIndex(m_ndotColor,m_dotColor);
		}
	}
}

void CDianzhenDlg::OnGb() 
{
	// TODO: Add your control notification handler code here
	m_codeType = 0;
	if(!GetDlgItem(IDC_RADIO1)->IsWindowEnabled())
		GetDlgItem(IDC_RADIO1)->EnableWindow();

	if(!GetDlgItem(IDC_RADIO2)->IsWindowEnabled())
		GetDlgItem(IDC_RADIO2)->EnableWindow();
}

void CDianzhenDlg::OnBig() 
{
	// TODO: Add your control notification handler code here
	m_codeType = 1;
	if(GetDlgItem(IDC_RADIO1)->IsWindowEnabled())
		GetDlgItem(IDC_RADIO1)->EnableWindow(false);

	if(GetDlgItem(IDC_RADIO2)->IsWindowEnabled())
		GetDlgItem(IDC_RADIO2)->EnableWindow(false);

	//((CButton *)GetDlgItem(IDC_RADIO3))->SetCheck(BST_CHECKED);
	OnRadio3();
	UpdateData(false);
}

void CDianzhenDlg::OnUnicode() 
{
	// TODO: Add your control notification handler code here
	m_codeType = 2;
	if(GetDlgItem(IDC_RADIO1)->IsWindowEnabled())
		GetDlgItem(IDC_RADIO1)->EnableWindow(false);

	if(GetDlgItem(IDC_RADIO2)->IsWindowEnabled())
		GetDlgItem(IDC_RADIO2)->EnableWindow(false);

	OnRadio3();
	UpdateData(false);
}

void CDianzhenDlg::OnRadio1() //选择编码输入
{
	m_inputKind = 0;
}

void CDianzhenDlg::OnRadio2() //选择中文输入
{
	m_inputKind = 1;
}

void CDianzhenDlg::OnRadio3() //选择索引输入
{
	m_inputKind = 2;
}

⌨️ 快捷键说明

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