📄 dabiaoview.cpp
字号:
SelectPalette(hDC,hPal,FALSE);
ReleaseDC(NULL,hDC);
return NULL;
}
lpbi = (LPBITMAPINFOHEADER)hDIB;
*lpbi = bi;
// Call GetDIBits with a NULL lpBits param, so the device driver
// will calculate the biSizeImage field
GetDIBits(hDC, (HBITMAP)bitmap.GetSafeHandle(), 0L, (DWORD)bi.biHeight,
(LPBYTE)NULL, (LPBITMAPINFO)lpbi, (DWORD)DIB_RGB_COLORS);
bi = *lpbi;
// If the driver did not fill in the biSizeImage field, then compute it
// Each scan line of the image is aligned on a DWORD (32bit) boundary
if (bi.biSizeImage == 0){
bi.biSizeImage = ((((bi.biWidth * bi.biBitCount) + 31) & ~31) / 8)
* bi.biHeight;
// If a compression scheme is used the result may infact be larger
// Increase the size to account for this.
if (dwCompression != BI_RGB)
bi.biSizeImage = (bi.biSizeImage * 3) / 2;
}
// Realloc the buffer so that it can hold all the bits
dwLen += bi.biSizeImage;
if (handle = GlobalReAlloc(hDIB, dwLen, GMEM_MOVEABLE))
hDIB = handle;
else{
GlobalFree(hDIB);
// Reselect the original palette
SelectPalette(hDC,hPal,FALSE);
ReleaseDC(NULL,hDC);
return NULL;
}
// Get the bitmap bits
lpbi = (LPBITMAPINFOHEADER)hDIB;
// FINALLY get the DIB
BOOL bGotBits = GetDIBits( hDC, (HBITMAP)bitmap.GetSafeHandle(),
0L, // Start scan line
(DWORD)bi.biHeight, // # of scan lines
(LPBYTE)lpbi // address for bitmap bits
+ (bi.biSize + nColors * sizeof(RGBQUAD)),
(LPBITMAPINFO)lpbi, // address of bitmapinfo
(DWORD)DIB_RGB_COLORS); // Use RGB for color table
if( !bGotBits )
{
GlobalFree(hDIB);
SelectPalette(hDC,hPal,FALSE);
ReleaseDC(NULL,hDC);
return NULL;
}
SelectPalette(hDC,hPal,FALSE);
ReleaseDC(NULL,hDC);
return hDIB;
}
LPBYTE Converbit(CDib *filedib)
{
LPBYTE nlpimage,tnlpimage,rnlpimage;
LPBYTE lpimage,tlpimage,lpline,tlpline;
DWORD height,width,rwidth1,rwidth2,size,bitcount,bytenum;
UINT bytes;
BYTE exchange=0x00,flag;
BYTE imagebyte;
bitcount=filedib->m_lpBMIH ->biBitCount ;
if (bitcount==1)
{
return filedib->m_lpImage ;
}
height=filedib->m_lpBMIH ->biHeight ;
width=filedib->m_lpBMIH ->biWidth ;
bytenum=(width/8);
if (width%8)
bytenum++;
lpline=(BYTE*) new BYTE[bytenum];
tlpline=lpline;
size=filedib->m_lpBMIH ->biSizeImage ;
bytes=bitcount/8;
lpimage=(LPBYTE)filedib->m_lpImage ;
rwidth1=WIDTHBYTES((size/height));
rwidth2=WIDTHBYTES(width);
nlpimage=(BYTE*) new BYTE[height*rwidth2];
rnlpimage=nlpimage;
tnlpimage=nlpimage;
tlpimage=lpimage;
LPBYTE tylor;
tylor=lpimage;
for(UINT i=0;i<(height*rwidth2);i++)
*(BYTE*)((BYTE*)nlpimage+i)=0x00;
for(UINT j=0;j<height;j++)
{
(BYTE*)nlpimage+=j*rwidth2;
exchange=0x00;
for(UINT m=0;m<width;m++)
{
if(((m%8)==0) && ((m/8)!=0))
{
*(BYTE*)(lpline)=exchange;
(BYTE*)lpline++;
exchange=0x00;
}
imagebyte=*(BYTE*)lpimage;
lpimage+=bytes;
if (imagebyte!=0x00)
flag=0x80;
else
flag=0x00;
exchange |=(flag>>(m%8));
}
*(BYTE*)(lpline)=exchange;
lpline=tlpline;
for(UINT k=0;k<bytenum;k++)
{
*(BYTE*)nlpimage++=*(BYTE*)lpline++;
}
lpline=tlpline;
nlpimage=tnlpimage;
}
LPBYTE yy;
yy=rnlpimage;
CString test="";
return rnlpimage;
}
BOOL RecorderData2(CDib *filedib)
{
CStdioFile filetext;
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;
filesize=filedib->m_lpBMIH ->biSizeImage ;
rows=fileheader->biHeight;
width=fileheader->biWidth;
size=fileheader->biSizeImage ;
rwidth=((size*8/fileheader->biBitCount )/rows);
cols=filesize/rows;
LPCTSTR filename="tylorrecord3.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 Write(LPBYTE writedata,ULONG bytesnum)
{
ULONG byteswrite,bytesread;
BYTE inbuff[2];
PurgeComm(CommFile,PURGE_RXCLEAR);
if(!WriteFile(CommFile,writedata,bytesnum,&byteswrite,NULL))
{
AfxMessageBox("Can't write go out!");
return FALSE;
}
for(UINT readnum=0; readnum < 8; readnum++)
{
if(!ReadFile(CommFile,inbuff,2,&bytesread,NULL))
{
AfxMessageBox("Error Read!");
return FALSE;
}
else
{
if (bytesread)
{
if(IsOk(orderflag,inbuff))
{
//chen writetag(inbuff);
return TRUE;
}
}
}
}
if (readnum==8)
{
// AfxMessageBox("Order have not been traned successfully!");
return FALSE;
}
return TRUE;
}
void CDabiaoView::OnPrintCancel()
{
// TODO: Add your command handler code here
g_eventKill.SetEvent();
g_send=FALSE;
g_pause=FALSE;
orderflag='F';
}
void CDabiaoView::OnPrintContinue()
{
// TODO: Add your command handler code here
orderflag='J';
g_pause=FALSE;
}
void CDabiaoView::OnUpdatePrintContinue(CCmdUI* pCmdUI)
{
// TODO: Add your command update UI handler code here
pCmdUI->Enable (g_start&&g_send&&g_pause);
}
void CDabiaoView::OnPrintLink()
{
// TODO: Add your command handler code here
orderflag = 'L';
}
void CDabiaoView::OnUpdatePrintLink(CCmdUI* pCmdUI)
{
// TODO: Add your command update UI handler code here
pCmdUI->Enable (g_start&&(!g_send));
}
void CDabiaoView::OnPrintPause()
{
// TODO: Add your command handler code here
orderflag='P';
g_pause=TRUE;
}
void CDabiaoView::OnUpdatePrintPause(CCmdUI* pCmdUI)
{
// TODO: Add your command update UI handler code here
pCmdUI->Enable (g_start&&(!g_pause)&&(g_send));
}
void CDabiaoView::OnPrintSend()
{
// TODO: Add your command handler code here
point=this;
orderflag='T';
g_send=TRUE;
}
void CDabiaoView::OnUpdatePrintSend(CCmdUI* pCmdUI)
{
// TODO: Add your command update UI handler code here
pCmdUI->Enable (g_start&&(!g_send));
}
void CDabiaoView::OnUpdatePrintCancel(CCmdUI* pCmdUI)
{
// TODO: Add your command update UI handler code here
pCmdUI->Enable (g_start&&(g_send));
}
void CDabiaoView::OnPrintSet()
{
CSetting setting;
setting.m_dis =Dist;
setting.m_speed =speed;
setting.m_pin =hdnum;
viewwidth=Dist*hdnum;
viewhigh=setting.m_height=height;
g_pDoc->UpdateAllViews(NULL) ;
if (setting.DoModal ()!=IDOK)
{
return;
}
{
Dist = setting.m_dis;
speed = setting.m_speed ;
hdnum = setting.m_pin;
viewwidth=width = Dist*hdnum ;
viewhigh=height = setting.m_height ;
orderflag='S';
}
g_pDoc->UpdateAllViews(NULL) ;
}
void CDabiaoView::OnUpdatePrintSet(CCmdUI* pCmdUI)
{
// TODO: Add your command update UI handler code here
pCmdUI->Enable (g_start&&(!g_send));
}
void CDabiaoView::OnPrintTest()
{
// TODO: Add your command handler code here
CTest testdlg;
if(testdlg.DoModal() ==IDCANCEL)
return;
}
void CDabiaoView::OnUpdatePrintTest(CCmdUI* pCmdUI)
{
// TODO: Add your command update UI handler code here
pCmdUI->Enable (g_start&&(!g_send));
}
void CDabiaoView::OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags)
{
switch(nChar)
{
case 0x13:
if(g_pause==FALSE)
OnPrintPause();
else
OnPrintContinue();
break;
case 0x20:
OnPrintSend();
break;
case 0x1b:
OnPrintCancel();
break;
default:
break;
}
CScrollView::OnKeyDown(nChar, nRepCnt, nFlags);
}
void CDabiaoView::InsertPicture(int x0, int y0, int x1, int y1, CString string)
{
if(string.GetLength())
{
#ifdef MEMORY_MAPPED_FILES
if (filedib.AttachMapFile(string,TRUE) == TRUE)
{
Invalidate();
}
#else
CFile file;
file.Open(dlg.GetPathName(), CFile::modeRead);
if (filedib.Read(&file) == TRUE)
{
}
#endif
CClientDC dc(this);
filedib.SetSystemPalette(&dc);
picx0=x0;
picy0=y0;
picx1=x1;
picy1=y1;;
}
}
void CDabiaoView::OnTimer(UINT nIDEvent)
{
// TODO: Add your message handler code here and/or call default
CText* pSelEntity = NULL ;
CText* pSel =NULL;
POSITION pos1 = NULL ;
CDC* pDC = g_pView->GetDC();
int count=g_pDoc->m_EntityList.GetCount();
POSITION pos = g_pDoc->m_EntityList.GetHeadPosition();
for(int i=0;i<count;i++)
{
pSelEntity = pSel = (CText*)g_pDoc->m_EntityList.GetNext(pos);
CString buffer;
if(pSelEntity->m_type==MTIME)
{
buffer.Format("%02d:%02d",
CTime::GetCurrentTime().GetHour(),
CTime::GetCurrentTime().GetMinute());
}
if(pSelEntity->m_type==MDATA)
{
if(pSelEntity->m_datatype==0)
{
buffer.Format("%04d_%02d_%02d",
CTime::GetCurrentTime().GetYear(),
CTime::GetCurrentTime().GetMonth(),
CTime::GetCurrentTime().GetDay());
goto out;
}
if(pSelEntity->m_datatype==1)
{
buffer.Format("%04d.%02d.%02d",
CTime::GetCurrentTime().GetYear(),
CTime::GetCurrentTime().GetMonth(),
CTime::GetCurrentTime().GetDay());
goto out;
}
if(pSelEntity->m_datatype==2)
{
buffer.Format("%04d/%02d/%02d",
CTime::GetCurrentTime().GetYear(),
CTime::GetCurrentTime().GetMonth(),
CTime::GetCurrentTime().GetDay());
goto out;
}
}
if(pSelEntity->m_type==MTEXT)
{
buffer=pSelEntity->m_text;
}
if(pSelEntity->m_type==MNO)
{
buffer=pSelEntity->m_text;
}
out:
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 ;
}
if(brush)
{
brush=FALSE;
g_pDoc->UpdateAllViews(NULL) ;
}
CScrollView::OnTimer(nIDEvent);
}
void CDabiaoView::OnUpdateModify(CCmdUI* pCmdUI)
{
// TODO: Add your command update UI handler code here
pCmdUI->Enable (!g_start);
}
void CDabiaoView::OnUpdatePicturre(CCmdUI* pCmdUI)
{
// TODO: Add your command update UI handler code here
pCmdUI->Enable (!g_start);
}
void CDabiaoView::OnUpdateSetview(CCmdUI* pCmdUI)
{
// TODO: Add your command update UI handler code here
pCmdUI->Enable (!g_start);
}
void CDabiaoView::OnUpdateClear(CCmdUI* pCmdUI)
{
// TODO: Add your command update UI handler code here
pCmdUI->Enable (!g_start);
}
void CDabiaoView::OnUpdateTtextout(CCmdUI* pCmdUI)
{
pCmdUI->Enable (!g_start);
}
void CDabiaoView::OnUpdateFileNew(CCmdUI* pCmdUI)
{
// TODO: Add your command update UI handler code here
pCmdUI->Enable (!g_start);
}
void CDabiaoView::OnUpdateFileOpen(CCmdUI* pCmdUI)
{
// TODO: Add your command update UI handler code here
pCmdUI->Enable (!g_start);
}
void CDabiaoView::OnUpdateFileSave(CCmdUI* pCmdUI)
{
// TODO: Add your command update UI handler code here
pCmdUI->Enable (!g_start);
}
void CDabiaoView::OnUpdateFileSaveAs(CCmdUI* pCmdUI)
{
// TODO: Add your command update UI handler code here
pCmdUI->Enable (!g_start);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -