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

📄 dabiaoview.cpp

📁 串口 操作 源码 打标机的控制程序
💻 CPP
📖 第 1 页 / 共 4 页
字号:
													CTime::GetCurrentTime().GetYear(),
													CTime::GetCurrentTime().GetMonth(),
													CTime::GetCurrentTime().GetDay());
												}
											}
										if(pSelEntity->m_type==MTEXT)
										{
											 buffer=pSelEntity->m_text;
										}
										if(pSelEntity->m_type==MNO)
										{
											CFile file;
											CFileStatus Status;
											int no;
											char startno[6];
											no = atoi(pSelEntity->m_text);
											no++;
											itoa(no,startno,10);
     										if(!file.GetStatus(_T("backup.txt"),Status))
												{
													file.Open(_T("backup.txt"),CFile::modeCreate|CFile::modeReadWrite);
													file.Close();
													return 1;
												}
										   file.Open(_T("backup.txt"),CFile::modeReadWrite);
										   file.Write(startno,6);
				                           file.Close();
				                           buffer=startno;
										}
	                             	pSelEntity->m_text=buffer;
		                            pSelEntity->Draw(pDC,0);
	                                g_pDoc->m_EntityList.AddTail(pSelEntity);
		                            pSelEntity = NULL;
		                            pos1= g_pDoc->m_EntityList.Find(pSel) ;
		                            g_pDoc->m_EntityList.RemoveAt(pos1) ;
		                            delete pSelEntity ;
		                            pSelEntity = NULL ;
	                                g_pDoc->SetModifiedFlag(TRUE);
							}	                     
						 }
						 
//-----------------------------------------------------------
					  g_pView->OnPrintSend();
					   break;
					 }
			         if (inbuff==0x02)
					 { 		
						g_send=FALSE;	
                        PurgeComm(CommFile,PURGE_RXCLEAR);

				        break;
					 }
				   }
				 }

			}
	} 
  }
//printend:
 	::PostMessage((HWND) pParam, WM_THREADFINISHED, 0, 0);
    return 1; 

}

LPBYTE  Conver(LPBYTE lpimage, DWORD sizeimage,DWORD width,DWORD rwidth)
{ //将图像上下颠倒位置
	LPBYTE  exp1,exp2,exp11,exp22;
	BYTE ex;
	exp1=lpimage;
	exp11=lpimage;
	exp2=lpimage+sizeimage-rwidth;
	exp22=exp2;
	UINT  lines;

	lines=(sizeimage/rwidth)/2;
	
	for(UINT i=0; i<lines;i++)
	{
		for (UINT j=0;j<rwidth;j++)
		{
			ex=*(BYTE*)exp11;
			*(BYTE*)exp11=*(BYTE*)exp22;
			*(BYTE*)exp22=ex;
			exp11++;
			exp22++;
		}
		exp1+=rwidth;
		exp2-=rwidth;
		exp11=exp1;
		exp22=exp2;

	}
	return lpimage;

}
UINT    Search(LPBYTE lpimage,DWORD width,DWORD rwidth,DWORD rows)
{
	//搜索到无空白行为止,并且返回非空白行的第几行
	// 如果xd=0,正方向,lpimage的指针是最左边,如果xd=1,负方向,lpimage的指针是最右边
   LPBYTE  temp;
   temp=lpimage;
   UINT  bytes,off,lines=0;
   char  display[1];
   CString disp;
   bytes=width/8;
   off=width%8;
    
   for(UINT r=1;r<=rows;r++)
   {
    for (UINT i=0;i<bytes; i++)
   {
		sprintf(display,"%02x",*(BYTE*)temp);
		disp=CString(display);
	  if( *(BYTE*)temp!=0xff)

		  return lines;
	  (BYTE*)temp++;
   }
   for(UINT j=0;j<off;j++)
   {
	  if((((*(BYTE*)temp)<<(j)) & 0x80)==0x00)
		  return lines;
   }
   (BYTE*)temp=(BYTE*)lpimage;
   (BYTE*)temp+=r*rwidth;
   lines++;
   }
   	return lines;
}

LPBYTE  Packet(LPBYTE lpimage, BYTE xoff, BYTE xd, DWORD width, DWORD rwidth,ULONG& bytesnum)
{  // 如果针头是正方向,则指针移动到下一行,并产生一个发送包
	//如果针头是负方向,则指针不动,再产生一个发送包
	LPBYTE  orderlines,temporder;
	LPBYTE  sumcheck;
    
	bytesnum=Dist+1;
	orderlines=(BYTE*)new char[bytesnum+4];
	temporder=orderlines;
	*(BYTE*)orderlines++='T';
    *(BYTE*)orderlines++=(BYTE)bytesnum;
	*(BYTE*)orderlines++=xd;

    if (xd==0)
	{
    for(UINT start=1; start <= Dist;start++)
	{     	
		 *(BYTE*)orderlines++=GetArray(hdnum,Dist,start,width,rwidth,lpimage,xd);
	}
	}
	else
	{
    for(UINT start=Dist;start>=1;start--)
	{
	
		*(BYTE*)orderlines++=GetArray(hdnum,Dist,start,width,rwidth,lpimage,xd);
	}
	}
	
     sumcheck=Sumcheck(temporder,bytesnum+2);
	 (BYTE*)sumcheck++;
	 *(BYTE*)orderlines++=*(BYTE*)sumcheck--;
     *(BYTE*)orderlines=*(BYTE*)sumcheck;
//chen 	 writetofile(temporder,Dist+1+4);
	 return temporder;
		
}
LPBYTE  Sumcheck(LPBYTE orderlines, UINT bytesnum)
{
	WORD  sum;
	LPBYTE check,temporderlines;
	temporderlines=orderlines;
	check=(BYTE*)new char[2];
	sum=0;
	for(UINT i=0;i<bytesnum;i++)
	{
		sum+=*(BYTE*)temporderlines;
		temporderlines++;
	}
	*(BYTE*)check++=sum & 0xff;
	*(BYTE*)check--=(sum>>8) & 0xff;
	return check;
}

BYTE  GetArray(UINT hdnum, UINT  Dist, UINT startnum,DWORD width,DWORD rwidth, LPBYTE lpimage, BYTE xd)
{
    BYTE outbyte;
	BYTE header[10];
	LPBYTE image,timage;
	UINT   hder[10], //每个针头的具体位置
	       hderByte[10],//每个针头的偏移的字节数
		   hderOff[10],//每个针头在字节中的偏移量
		   hderpos[10];
	BOOL   hderis[10];
	 
    outbyte=0x00;


	for(UINT k=1;k<=hdnum;k++)
	{
       header[k]=0x00;
       hderpos[k]=k%8;
	  
	}

	for(UINT i=1; i<=hdnum; i++)
    {
		hder[i]=startnum+(i-1)*Dist;
	    hderByte[i]=hder[i]/8;
		hderOff[i]=hder[i]-hderByte[i]*8;
		if(hderOff[i]==0)
		{
			hderByte[i]--;
			hderOff[i]=8;
		}
		if (hder[i]>width)
		{
			hderis[i]=FALSE;

		}
		else
		{
			hderis[i]=TRUE;
		}

	}


	image=lpimage;

    timage=image;
	for(UINT j=1; j<=hdnum;j++)
	{
	
		if (hderis[j]==TRUE)
		{
		    (BYTE*)image+=hderByte[j];
		    header[j]=(((*(BYTE*)image)>>(8-hderOff[j])) & 0x01);
		    if(header[j]==0x01)
			{
			header[j]=0x00;
			hderis[j]=FALSE;
			}
			else
			{
				header[j]=0x01;
			}
					 
		}
        image=timage;
		
	}
        for (UINT n=1; n<=hdnum;n++)
		{
			UINT   poso;
		         
		    poso=n%8;
		    if(poso==0)
			{
			  poso=8;
			}
	     outbyte |= header[n]<<(8-poso);
		}
    	return outbyte; 
}

LPBYTE  Go(BYTE xd, BYTE xoff,BYTE yoff, BYTE yd)
{
  LPBYTE goline,gotemp,sumcheck;
   	goline=(BYTE*)new char[8];
	gotemp=goline;
	*(BYTE*)goline++='M';
	*(BYTE*)goline++=4;
	*(BYTE*)goline++=xd;
	*(BYTE*)goline++=0;
	*(BYTE*)goline++=0;
	*(BYTE*)goline++=yoff;
	
    sumcheck=Sumcheck(gotemp,6);
	 sumcheck++;
	 *(BYTE*)goline++=*(BYTE*)sumcheck--;
     *(BYTE*)goline=*(BYTE*)sumcheck;
//chen  	 writetofile(gotemp,8);


	return gotemp ;

}
BOOL  RecorderData(CDib &filedib)
{

    BYTE   *filestart;
	LPBITMAPINFOHEADER  fileheader;
	DWORD filesize,totalsize;
    ULONG rows,cols,i,j,num,width,rwidth,size;
    char config[40];
	filestart=filedib.m_lpImage;
	fileheader=filedib.m_lpBMIH;

	rows=fileheader->biHeight;
	width=fileheader->biWidth;
    size=fileheader->biSizeImage ;
	filesize=size;
	rwidth=(size/rows);
	cols=(filesize/fileheader->biBitCount)/rows;

	LPCTSTR      filename="Test1.25.txt";
     num=cols*2;
	 totalsize=filesize*3;
     CString         pfile(""),temp,ltemp("");
	if(filetext.Open(filename,CFile::modeCreate|CFile::modeReadWrite)==0)
	 {
		 AfxMessageBox("Error open!");
	 }
	for ( i=0; i<rows; i++ )
		{
		    temp="";

			for ( j=0; j<(cols); j++ )
			{ 
				ltemp.Format ("%02x",*(BYTE*)filestart++);
				temp+=ltemp;
				temp+=" ";
			}
             temp+="\r\n";
			 temp+=pfile;
			 pfile=temp;
		} 
	    pfile+=CString("\r\n\r\n");
		sprintf(config, "width: %d , height: %d ,rwidth: %d", width,rows,rwidth);
		pfile+=CString(config);
        filetext.WriteString (pfile); 
	    filetext.Close ();
	    return TRUE;
}
BOOL    writetofile(LPBYTE ppacket, UINT bytesnum)
{  
   char   bytechar[1];
   CStdioFile  packfile;
   CString     pfname="packetfile.txt",datastring="";
   packfile.Open (pfname,CFile::modeCreate|CFile::modeNoTruncate|CFile::modeReadWrite);
   packfile.SeekToEnd ();
   for(UINT i=0; i<bytesnum;i++)
   {
	   if(i%2)
	   {
    sprintf(bytechar,"%02x ",*(BYTE*)ppacket++);
	   }
	   else
	   {
    sprintf(bytechar,"%02x:",*(BYTE*)ppacket++);
	   }
	datastring+=CString(bytechar);
   }
   datastring+=CString("\r\n");
 //  AfxMessageBox(datastring);
   packfile.WriteString (datastring);
   packfile.Close ();
   
	return 1;
}

BOOL    IsOk(char tag,LPBYTE readdata)
{
	char  data[2];
	data[0]=(char)(*(BYTE*)readdata++);
    data[1]=(char)(*(BYTE*)readdata);
	
	switch (tag)
	{
		case 'M':
			{
				if ((data[0]=='M') && (data[1]=='O'))
                 return TRUE;
				if ((data[0]=='M') && (data[1]=='W'))
				 return FALSE;
                   
			}
		case 'T':
			{
				if ((data[0]=='T') && (data[1]=='O'))
                 return TRUE;
				if ((data[0]=='T') && (data[1]=='W'))
				 return FALSE;
         	}
		case 'A':
			{
				if ((data[0]=='A') && (data[1]=='O'))
                 return TRUE;
				if ((data[0]=='A') && (data[1]=='W'))
				 return FALSE;
         	}
        case 'S':
			{
				if ((data[0]=='S') && (data[1]=='O'))
                 return TRUE;
				if ((data[0]=='S') && (data[1]=='W'))
				 return FALSE;
         	}
        case 'C':
			{
				if ((data[0]=='C') && (data[1]=='O'))
                 return TRUE;
				if ((data[0]=='C') && (data[1]=='W'))
				 return FALSE;
         	}
	    case 'P':
			{
				if ((data[0]=='P') && (data[1]=='O'))
                 return TRUE;
				if ((data[0]=='P') && (data[1]=='W'))
				 return FALSE;
         	}
    	case 'J':
			{
				if ((data[0]=='J') && (data[1]=='O'))
                 return TRUE;
				if ((data[0]=='J') && (data[1]=='W'))
				 return FALSE;
         	}
        case 'L':
			{
				if ((data[0]=='L') && (data[1]=='O'))
                 return TRUE;
				if ((data[0]=='L') && (data[1]=='W'))
				 return FALSE;
         	}
        case 'F':
			{
				if ((data[0]=='F') && (data[1]=='O'))
                 return TRUE;
				if ((data[0]=='F') && (data[1]=='W'))
				 return FALSE;
         	}  

	}

	return FALSE;
}

BOOL    writetag(LPBYTE tag)
{   
	CStdioFile packfile;
	char  filetag[2];
	filetag[0]=(char)(*(BYTE*)tag++);
    filetag[1]=(char)(*(BYTE*)tag);
	CString     pfname="packetfile.txt",datastring="";
    packfile.Open (pfname,CFile::modeCreate|CFile::modeNoTruncate|CFile::modeReadWrite);
    packfile.SeekToEnd ();
    datastring=CString(filetag);
	datastring+="\r\n";
    packfile.WriteString (datastring);
    packfile.Close ();
    return TRUE;
   
}
BOOL    typedata(LPBYTE lpimage, UINT  height, UINT cols)
{
	LPCTSTR      filename="image.txt";
    CStdioFile filetext;
    LPBYTE filestart;
	filestart=lpimage;
     CString         pfile(""),temp,ltemp("");
	if(filetext.Open(filename,CFile::modeCreate|CFile::modeReadWrite)==0)
	 {
		 AfxMessageBox("Error open!");
	 }
	for ( UINT i=0; i<height; i++ )
		{
		    temp="";

			for (UINT j=0; j<(cols); j++ )
			{
			   
				ltemp.Format ("%02x",*(BYTE*)filestart++);
				temp+=ltemp;
				temp+=" ";
				
			}
             
             temp+="\r\n";
			pfile+=temp;
		   
		} 
	    pfile+=CString("\r\n\r\n");
	    filetext.WriteString (pfile);
		  
	        filetext.Close ();
   return TRUE;
}


HANDLE DDBToDIB( CBitmap& bitmap, DWORD dwCompression, CPalette* pPal ) 
{
	BITMAP			bm;
	BITMAPINFOHEADER	bi;
	LPBITMAPINFOHEADER 	lpbi;
	DWORD			dwLen;
	HANDLE			hDIB;
	HANDLE			handle;
	HDC 			hDC;
	HPALETTE		hPal;


	ASSERT( bitmap.GetSafeHandle() );

	// The function has no arg for bitfields
	if( dwCompression == BI_BITFIELDS )
		return NULL;

	// If a palette has not been supplied use defaul palette
	hPal = (HPALETTE) pPal->GetSafeHandle();
	if (hPal==NULL)
		hPal = (HPALETTE) GetStockObject(DEFAULT_PALETTE);

	// Get bitmap information
	bitmap.GetObject(sizeof(bm),(LPSTR)&bm);

	// Initialize the bitmapinfoheader
	bi.biSize		= sizeof(BITMAPINFOHEADER);
	bi.biWidth		= bm.bmWidth;
	bi.biHeight 		= bm.bmHeight;
	bi.biPlanes 		= 1;
	bi.biBitCount		= bm.bmPlanes * bm.bmBitsPixel;
	bi.biCompression	= dwCompression;
	bi.biSizeImage		= 0;
	bi.biXPelsPerMeter	= 0;
	bi.biYPelsPerMeter	= 0;
	bi.biClrUsed		= 0;
	bi.biClrImportant	= 0;

	// Compute the size of the  infoheader and the color table
	int nColors = (1 << bi.biBitCount); if( nColors > 256 ) 
		nColors = 0;
	dwLen  = bi.biSize + nColors * sizeof(RGBQUAD);

	// We need a device context to get the DIB from
	hDC = GetDC(NULL);
	hPal = SelectPalette(hDC,hPal,FALSE);
	RealizePalette(hDC);

	// Allocate enough memory to hold bitmapinfoheader and color table
	hDIB = GlobalAlloc(GMEM_FIXED,dwLen);

	if (!hDIB){

⌨️ 快捷键说明

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