📄 screenview.cpp
字号:
{
CRect rc;
CListBox* pListBox=NULL;
pListBox=(CListBox*)GetDlgItem(IDC_YJLIST);
if(pListBox==NULL)
return;
GetClientRect(&rc);
pListBox->MoveWindow(0,0,rc.Width(),rc.Height(),1);
/* CFormView::OnSize(nType, cx, cy);
CStatic *pStatic=(CStatic*)GetDlgItem(IDC_PREVIEW);
if(pStatic==NULL)
return;
CRect rc;
GetClientRect(&rc);
CListBox* pListBox=(CListBox*)GetDlgItem(IDC_YJLIST);
pListBox->MoveWindow(-3,-2,rc.Width()/4+3,rc.Height()*4/5+2,1);
pStatic->MoveWindow(rc.Width()/4,0,rc.Width()*3/4,rc.Height()*4/5,1);
CEdit* pEdit=(CEdit*)GetDlgItem(IDC_ZMLIST);
pEdit->MoveWindow(-3,rc.Height()*4/5+1,rc.Width()+3,rc.Height()/5+1,1);
CFormView::ShowScrollBar(SB_VERT,FALSE);//隐藏竖直滚动条
CFormView::ShowScrollBar(SB_HORZ,FALSE);//隐藏水平滚动条
*/
}
void CScreenView::OnCancelMode()
{
CFormView::OnCancelMode();
// TODO: Add your message handler code here
}
int CScreenView::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
if (CFormView::OnCreate(lpCreateStruct) == -1)
return -1;
// TODO: Add your specialized creation code here
return 0;
}
void CScreenView::OnCaptureChanged(CWnd *pWnd)
{
// TODO: Add your message handler code here
CFormView::OnCaptureChanged(pWnd);
}
void CScreenView::OnEditchangeCombo1()
{
// TODO: Add your control notification handler code here
}
void CScreenView::DrawGrid(CDC* tpDC)
{
CWnd* pMainWnd=AfxGetApp()->m_pMainWnd;
CMainFrame* pMainFrame=(CMainFrame*)pMainWnd;
CString str;
pMainFrame->m_wndToolBarDraw.m_screenHeight.GetWindowText(str);
int pingHeight=atoi(str);
pMainFrame->m_wndToolBarDraw.m_screenWidth.GetWindowText(str);
int pingWidth=atoi(str);
// pingHeight=64;
// pingWidth=96;
CBrush brush(RGB(0,121,155));
CStatic* pStatic=(CStatic*)GetDlgItem(IDC_PREVIEW);
CRect mrc;
pStatic->GetClientRect(&mrc);
//CRect mrc(0,0 ,xscreen,yscreen*3/5);
tpDC->FillRect(&mrc,&brush);
if(pingWidth==0 || pingHeight==0)
return;
int tmp1=mrc.Width()/pingWidth;
int tmp2=mrc.Height()/pingHeight;
if(tmp1<=tmp2)
step=tmp1;
else
step=tmp2;
//step=mrc.Width()/pingWidth;
orgx=(mrc.Width()-pingWidth*step)/2;
orgy=(mrc.Height()-pingHeight*step)/2;
//for(int i=(mrc.Height()-pingHeight*step)/2;i<mrc.Height()-pingHeight*step;i+=step)
CBrush brush1(RGB(255,255,255));
CBrush* pOldBrush=tpDC->SelectObject(&brush);
CPen pen;
//pen.CreatePen(1,1,RGB(0,0,0));
//tpDC->SelectObject(&pen);
/*for(int j=0;j<pingHeight;j++)
for(int i=0;i<pingWidth;i++)
{
CRect rc;
rc.left=orgx+i*step;
rc.top=orgy+j*step;
rc.right=orgx+(i+1)*step;
rc.bottom=orgy+(j+1)*step;
tpDC->Ellipse(&rc);
}*/
for(int j=0;j<=pingWidth;j++)
{
tpDC->MoveTo(orgx+j*step,orgy);
tpDC->LineTo(orgx+j*step,orgy+pingHeight*step);
}
//for(i=0;i<xscreen;i+=step)
for(j=0;j<=pingHeight;j++)//(mrc.Height()-pingHeight*step)/2;j<(mrc.Height()-pingHeight*step)/2+pingHeight*step;j+=step)
{
tpDC->MoveTo(orgx,orgy+j*step);
tpDC->LineTo(orgx+pingWidth*step,orgy+j*step);
}
tpDC->SelectObject(pOldBrush);
}
void CScreenView::OnDraw(CDC* pDC)
{
// TODO: Add your specialized code here and/or call the base class
}
void CScreenView::CalcWindowRect(LPRECT lpClientRect, UINT nAdjustType)
{
// TODO: Add your specialized code here and/or call the base class
CFormView::CalcWindowRect(lpClientRect, nAdjustType);
}
void CScreenView::CreateDz(CDC *tpDC, CWordObj *pWordObj, CString str, CString fontstr, int width, int height)
{
CDC memDC1;//内存DC
CDC* pDC=GetDC();
BITMAP bmp;
CBitmap memBitmap, *oldmemBitmap;//建立和屏幕兼容的bitmap
CRect rc;
int trueWidth;
trueWidth=pWordObj->m_width;
if(pWordObj->m_strname!="pic")
{
CFont font;
int ffheight;
if(height<32)
ffheight=height;
else
ffheight=height;
char c=str.GetAt(0);
int fontheight,fontwidth;
fontheight=height;
fontwidth=width/2;
font.CreateFont(
fontheight, //字体高度(旋转后的字体宽度)=10
fontwidth , //字体宽度(旋转后的字体高度)=10
0, //字体显示角度=270°
0, //nOrientation=0
pWordObj->bBold?8000:100, //字体磅数=10
pWordObj->bItalic, //非斜体
FALSE, //无下划线
FALSE, //无删除线
GB2312_CHARSET, //使用缺省字符集
OUT_OUTLINE_PRECIS, //缺省输出精度
CLIP_DEFAULT_PRECIS,//缺省裁减精度
NONANTIALIASED_QUALITY, //nQuality=缺省值
DEFAULT_PITCH, //nPitchAndFamily=缺省值
fontstr ); //字体名=@system*/
if(c>=0 && c<=255)
trueWidth=width/2;
else
trueWidth=width;
trueWidth=(trueWidth==0)?1:trueWidth;
rc.SetRect(0,0,trueWidth,height);
memDC1.CreateCompatibleDC(pDC);
memBitmap.CreateCompatibleBitmap(pDC, rc.Width(), rc.Height());
oldmemBitmap = memDC1.SelectObject(&memBitmap);//将memBitmap选入内存DC
memDC1.SelectObject(&font);
CBrush mybrush(RGB(255,255,255));
memDC1.FillRect(&rc,&mybrush);
memDC1.DrawText(str,strlen(str),&rc,3);
pDC->SelectObject(&font);
/*memBitmap.GetBitmap(&bmp);//获得位图信息
FILE *fp = fopen("c:\\aaa.bmp", "w+b");
BITMAPINFOHEADER bih = {0};//位图信息头
bih.biBitCount = bmp.bmBitsPixel;//每个像素字节大小
bih.biCompression = BI_RGB;
bih.biHeight = bmp.bmHeight;//高度
bih.biPlanes = 1;
bih.biSize = sizeof(BITMAPINFOHEADER);
bih.biSizeImage = bmp.bmWidthBytes * bmp.bmHeight;//图像数据大小
bih.biWidth = bmp.bmWidth;//宽度
BITMAPFILEHEADER bfh = {0};//位图文件头
bfh.bfOffBits = sizeof(BITMAPFILEHEADER) + sizeof(BITMAPINFOHEADER);//到位图数据的偏移量
bfh.bfSize = bfh.bfOffBits + bmp.bmWidthBytes * bmp.bmHeight;//文件总的大小
bfh.bfType = (WORD)0x4d42;
fwrite(&bfh, 1, sizeof(BITMAPFILEHEADER), fp);//写入位图文件头
fwrite(&bih, 1, sizeof(BITMAPINFOHEADER), fp);//写入位图信息头
byte * p = new byte[bmp.bmWidthBytes * bmp.bmHeight];//申请内存保存位图数据
GetDIBits(memDC1.m_hDC, (HBITMAP) memBitmap.m_hObject, 0, bmp.bmHeight , p,
(LPBITMAPINFO) &bih, DIB_RGB_COLORS);//获取位图数据
fwrite(p, 1, bmp.bmWidthBytes * bmp.bmHeight, fp);//写入位图数据
delete []p;
fclose(fp);*/
}
else
{
CDC memDC2;//内存DC
rc.SetRect(0,0,pWordObj->picWidth ,pWordObj->picHeight );
memDC2.CreateCompatibleDC(pDC);
memBitmap.CreateCompatibleBitmap(pDC, rc.Width(), rc.Height());
oldmemBitmap = memDC2.SelectObject(&memBitmap);//将memBitmap选入内存DC
memBitmap.GetBitmap(&bmp);//获得位图信息
BITMAPINFOHEADER bih = {0};//位图信息头
bih.biBitCount = pWordObj->biBitCount ;//每个像素字节大小
bih.biCompression = BI_RGB;
bih.biHeight = pWordObj->picHeight ;//高度
bih.biPlanes = 1;
bih.biSize = sizeof(BITMAPINFOHEADER);
bih.biSizeImage = pWordObj->picWidth* 8 * bmp.bmHeight;//图像数据大小
bih.biWidth = pWordObj->picWidth ;//宽度
BYTE RgbQuad[8]={0x00,0x00,0x00,0x00,0xff,0xff,0xff,0x00};
BITMAPFILEHEADER bfh = {0};//位图文件头
bfh.bfOffBits = sizeof(BITMAPFILEHEADER) + sizeof(BITMAPINFOHEADER)+sizeof(RgbQuad);//到位图数据的偏移量
bfh.bfSize = bfh.bfOffBits + WIDTHBYTES(pWordObj->picWidth)* 8 * pWordObj->picHeight ;//文件总的大小
bfh.bfType = (WORD)0x4d42;
BITMAPINFO bmpInfo;//=new BITMAPINFO;
bmpInfo.bmiColors[0].rgbBlue=0xff;
bmpInfo.bmiColors[0].rgbGreen=0;
bmpInfo.bmiColors[0].rgbRed=0;
bmpInfo.bmiColors[0].rgbReserved=0xff;
bmpInfo.bmiColors[1].rgbBlue=0xff;
bmpInfo.bmiColors[1].rgbGreen=0xff;
bmpInfo.bmiColors[1].rgbRed=0xff;
bmpInfo.bmiColors[1].rgbReserved=0;
memcpy(&bmpInfo.bmiHeader,&bih,sizeof(BITMAPINFOHEADER));;
FILE *fp = fopen("c:\\aaa.bmp", "w+b");
fwrite(&bfh, 1, sizeof(BITMAPFILEHEADER), fp);//写入位图文件头
fwrite(&bih, 1, sizeof(BITMAPINFOHEADER), fp);//写入位图信息头
fwrite(RgbQuad, 1, sizeof(RgbQuad), fp);//写入位图文件头
int kkkkk=WIDTHBYTES(bmp.bmWidthBytes);
// fwrite(pWordObj->imagedata , 1, WIDTHBYTES(bmp.bmWidthBytes) * bmp.bmHeight*8, fp);//写入位图数据
fclose(fp);
SetDIBitsToDevice(memDC2.m_hDC, 0, 0, pWordObj->picWidth , pWordObj->picHeight , 0, 0, 0, pWordObj->picHeight ,
pWordObj->imagedata ,&bmpInfo, DIB_RGB_COLORS);
memDC1.CreateCompatibleDC(pDC);
CBitmap memBitmap1, *oldmemBitmap1;//建立和屏幕兼容的bitmap
memBitmap1.CreateCompatibleBitmap(pDC, width, height);
oldmemBitmap1 = memDC1.SelectObject(&memBitmap1);//将memBitmap选入内存DC
BITMAP bmp1;
memBitmap1.GetBitmap(&bmp1);//获得位图信息
SetStretchBltMode(memDC1.GetSafeHdc(),HALFTONE); //字体平滑
SetStretchBltMode(memDC2.GetSafeHdc(),HALFTONE); //字体平滑
StretchBlt(memDC1.m_hDC , 0, 0, width, height, memDC2.m_hDC, 0, 0, rc.Width() , rc.Height(), SRCCOPY);
// delete bmpInfo;
}
//CDC* pDC2=GetDC();
int i,j;
if (pWordObj->buf!=NULL)
{
delete []pWordObj->buf;
}
pWordObj->buf=new BYTE[trueWidth*height];
COLORREF color;
int bits=0;
int index=0;
pWordObj->buf[index]=0x00;
for(i=0;i<height;i++)
for(j=0;j<trueWidth;j++)
{
color=GetPixel(memDC1.m_hDC,j,i);
if(color<=0xfff000)
pWordObj->buf[index]|=0x80>>bits;
else
pWordObj->buf[index]&=~(0x80>>bits);
bits++;
if(bits>=8)
{
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -