把\n换成
\r\n 还是 \n\r 我忘了
你试试!
\r\n 还是 \n\r 我忘了
你试试!
解决方案 »
- 双系统Boot.ini
- openssl中libeay32.lib怎么静态链接?
- 如何在CTreeCtrl中嵌套一个CListCtrl
- IDispatch::GetTypeInfo()有何作用?必须实现吗?如果不实现会有何影响?
- 通信数据截获
- VC新手求助,我相做一个类拟Windows资源管理器的程序,只是listView变成其它的?
- 请高手指教,关于WINDOWS下性能数据收集的问题!
- 如何用C++实现读入图片(JPEG、BMP等格式)并将图片信息存入一个像素矩阵?
- vc的初学者,但是遇到了挫折,那些高手可不能袖手旁观阿!
- TeeChart设置图例大小,修改横轴刻度。(MFC)
- 如何在ATL里面使用FileOpen 对话框?
- ●●●●●数据库添加新记录的问题●●●●
程序在OnPaint()中。
GetClientRect(&rect);
DrawText(pDC->m_hDC,pbuf,_tcslen(pbuf),&rect,DT_INTERNAL);
{
CPaintDC dc(this);
CString str("想写什么就写什么,\r\n这不是很简单的事么?");
CRect rc;
GetClientRect(rc);
dc.DrawText(str,rc,DT_LEFT);
}
加分!
vc编程中文本输出的座标是要自己定的
TextOut和DrawText参数中都有表明座标值的参数
没看见啊?
想把新的数据写到后几行。
下面接下来几行,要用DrawText来写。
为什么要那么复杂呢?
其实还可以用 cout 的,你看过essential c++ 了吗?
介意看看就知道怎么做了
{
CRect rect;
CRgn rgn;
CFont* font;
if(m_UseSysFont)
font=GetFont();
else
font=&m_Font; GetClientRect(&rect);
rgn.CreateRectRgnIndirect(&rect);
pDC->SelectClipRgn(&rgn);
CString text;
CMemDC memDC(pDC);
CDC* pdc=&memDC; pdc->FillRect(&rect,&CBrush(m_BkColor));
pdc->SetBkMode(TRANSPARENT);
pdc->SetTextColor(m_FontColor); CFont* OldFont=pdc->SelectObject(font);
if(!m_DisplayInfo){
GetWindowText(text);
pdc->TextOut(m_XPos,m_YPos,text);
}else{//display MP3 info.
UINT xpos,ypos;
long step=GetFontHeight(font);
//draw selected MP3 information.
xpos=ypos=1;
pdc->TextOut(xpos,ypos,"歌手: "+m_Singer);
ypos+=step;
pdc->TextOut(xpos,++ypos,"歌名: "+m_Song);
ypos+=step;
pdc->TextOut(xpos,++ypos,"专辑: "+m_Album);
ypos+=step;
pdc->TextOut(xpos,++ypos,"注释: "+m_Comment);
ypos+=step;
pdc->TextOut(xpos,++ypos,"日期: "+m_Year); m_TextArea.top=4;
m_TextArea.left=4;
m_TextArea.bottom=ypos+step;
m_TextArea.right=rect.Width()-GetFontHeight(font)*4; //draw state text and icon.
CString state="正在播放:";
CBrush brush;
POINT point;
CRgn frgn;
ypos+=rect.Height()/2-ypos; POINT vertex[4]={{xpos,ypos},{xpos+step,ypos+step/2},{xpos,ypos+step},{0,0}};
m_PlayInfo.PlayIconRect.top=ypos;
m_PlayInfo.PlayIconRect.left=xpos;
m_PlayInfo.PlayIconRect.right=xpos+step;
m_PlayInfo.PlayIconRect.bottom=ypos+step;
if(!m_PlayInfo.PlayState){
brush.CreateSolidBrush(RGB(255,0,0));
frgn.CreateRectRgn(xpos,ypos,xpos+step,ypos+step);
pdc->FillRgn(&frgn,&brush);
state="停止.";
}else if(m_PlayInfo.PlayState==PSTATE_PAUSED){
state="暂停.";
brush.CreateSolidBrush(RGB(0,255,255));
frgn.CreateRectRgn(xpos,ypos,xpos+step/2-1,ypos+step);
if((m_PlayInfo.XPos/10)%2==0){
pdc->FillRgn(&frgn,&brush);
frgn.DeleteObject();
frgn.CreateRectRgn(xpos+step/2+1,ypos,xpos+step,ypos+GetFontHeight(font));
pdc->FillRgn(&frgn,&brush);
}
}else{
brush.CreateSolidBrush(RGB(0,255,0));
frgn.CreatePolygonRgn(vertex,3,WINDING);
pdc->FillRgn(&frgn,&brush);
}
brush.DeleteObject();
frgn.DeleteObject();
xpos+=step+2;
pdc->TextOut(xpos,ypos,state); //draw playing MP3 information.
if(!m_PlayInfo.PlayState)
goto out;
//do not display blanks.
m_PlayInfo.Singer.TrimLeft();
m_PlayInfo.Singer.TrimRight();
m_PlayInfo.Song.TrimRight();
m_PlayInfo.Song.TrimLeft();
if(m_PlayInfo.Singer.IsEmpty())
m_PlayInfo.Singer="未知歌手";
if(m_PlayInfo.Song.IsEmpty())
m_PlayInfo.Song="未知歌曲";
CString disp="**"+m_PlayInfo.Singer+" - "+m_PlayInfo.Song+"** <"+m_PlayInfo.Time+"> ";
ypos+=step+5;
pdc->TextOut(m_PlayInfo.XPos,ypos,disp);
if(rect.Width()<=GetFontWidth(font,disp)){
m_PlayInfo.Offset=GetFontWidth(font,disp)-rect.Width()+1;
if(m_PlayInfo.Offset>=rect.Width())
m_PlayInfo.Offset/=2;
}
if(m_PlayInfo.XPos>(rect.Width()-GetFontWidth(font,disp))+m_PlayInfo.Offset)
pdc->TextOut((m_PlayInfo.XPos+GetFontWidth(font,disp)-rect.Width()-m_PlayInfo.Offset)-GetFontWidth(font,disp),ypos,disp); //draw progress line.
ypos+=step+step/2;
CPen pen;
CPen* OldPen;
vertex[0].x=3;vertex[0].y=ypos+2;
vertex[1].x=rect.Width()-3;vertex[1].y=vertex[0].y;
m_PlayInfo.ProgBarRect.top=ypos-3;
m_PlayInfo.ProgBarRect.left=vertex[0].x-2;
m_PlayInfo.ProgBarRect.bottom=vertex[0].y+2+5;
m_PlayInfo.ProgBarRect.right=vertex[1].x+2;
if(m_PlayInfo.IsMovingCube){
pen.CreatePen(PS_SOLID,1,RGB(100,245,120));
OldPen=pdc->SelectObject(&pen);
pdc->FillRect(&m_PlayInfo.ProgBarRect,&CBrush(RGB(85,155,57)));
pdc->DrawFocusRect(&m_PlayInfo.ProgBarRect);
pdc->SelectObject(OldPen);
pen.DeleteObject();
}
pen.CreatePen(PS_SOLID,1,RGB(115,10,25));
OldPen=pdc->SelectObject(&pen);
pdc->MoveTo(vertex[0]);
pdc->LineTo(vertex[1]);
pdc->SelectObject(OldPen);
pen.DeleteObject();
pen.CreatePen(PS_SOLID,1,RGB(151,50,50));
OldPen=pdc->SelectObject(&pen);
vertex[0].y=++vertex[1].y;
pdc->MoveTo(vertex[0]);
pdc->LineTo(vertex[1]);
pdc->SelectObject(OldPen);
pen.DeleteObject();
//draw cube.
point.y=ypos;
if(!m_PlayInfo.IsMovingCube){
m_PlayInfo.CubeRect.top=point.y;
m_PlayInfo.CubeRect.left=GetRelativePos()+2;
m_PlayInfo.CubeRect.bottom=point.y+6;
m_PlayInfo.CubeRect.right=GetRelativePos()+12+2;//Cube length is 12 pixels
}
frgn.CreateRectRgn(m_PlayInfo.CubeRect.left,m_PlayInfo.CubeRect.top,m_PlayInfo.CubeRect.right,m_PlayInfo.CubeRect.bottom);
pdc->FillRgn(&frgn,&CBrush(m_PlayInfo.CubeColor));
frgn.DeleteObject();
//draw current time.
GetDisplayTime();
ypos+=step;
disp="[ "+m_PlayInfo.C_Time+" ]";
pdc->TextOut(rect.Width()/2-GetFontWidth(font,disp)/2,ypos,disp);
m_PlayInfo.TimeRect.top=ypos;
m_PlayInfo.TimeRect.left=rect.Width()/2-GetFontWidth(font,disp)/2;
m_PlayInfo.TimeRect.bottom=ypos+step;
m_PlayInfo.TimeRect.right=m_PlayInfo.TimeRect.left+GetFontWidth(font,disp); //draw mousemove predict time.
if(!m_PlayInfo.PredictTime.IsEmpty()){
GetCursorPos(&point);
ScreenToClient(&point);
if(!IsPointInRect(&rect,&CPoint(point)))
pdc->SetTextColor(RGB(17,179,21));
pdc->TextOut(1,ypos,"跳转到:"+m_PlayInfo.PredictTime);
pdc->SetTextColor(m_FontColor);
}
//draw lyric if any.
ypos=rect.Height()-step-2;
CString ln1,ln2;
GetDispLyric(m_PlayInfo.Lyric,&ln1,&ln2);
int txtlen=GetFontWidth(font,m_PlayInfo.Lyric);
int pos=txtlen-rect.Width();
if(pos>0)
ypos-=step;
pdc->TextOut(1,ypos,ln1);
if(pos>0)
ypos+=step;
//right align the second line lyric.
txtlen=GetFontWidth(font,ln2);
pdc->TextOut(rect.Width()-txtlen-2,ypos,ln2);
}
out:
pdc->SelectObject(OldFont);
rgn.DeleteObject();
return CStatic::OnEraseBkgnd(pDC);
}慢慢啃吧。
long CMovieStatic::GetFontHeight(CFont *font,CString str)
{
CDC* dc=GetDC();
CFont* pOldFont;
CSize size(0,0);
if(font){
pOldFont=dc->SelectObject(font);
TEXTMETRIC ti;
dc->GetTextMetrics(&ti);
size=dc->GetTextExtent(str);
dc->SelectObject(pOldFont);
}
ReleaseDC(dc);
return (LONG)size.cy;
}
(DrawText是不是API啊?我也不是很清楚的)
分行在字符串中是0ah 0dh 把这个添到你要分行的位置在显示这个字符串就行了
好像是不可以的,“\n”会被显示成空格。你可以想个别的办法(我就是这样做的)。
根据当前字体的大小,计算出下一行的起始位置.我想DrawText里面肯
定也是这样实现.为什么不花半个小时来解决这个问题?非常简单,我以
前就写过这样的代码,将textbox中的multiline的文本在一个区域中
显示出来,完全是自己写的代码,连DrawText都没有用.TextOut之会将
/r/n之类的字符显示成奇怪的字符,根本不能够使用.