请问怎样实现文字的水平滚动(要看起来连续滚动,不要一个字一个字的滚动) 做一个对话框,怎样实现某一个位置文字的水平滚动,要看起来连续滚动,不要一个字一个字的滚动,最好用Edit控件,当然其它控件如果有好办法也行 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 class CShowScrollText : public CMyHyperLink{// Constructionpublic: CShowScrollText();// Attributespublic:// Operationspublic: CFont m_font;// Overrides // ClassWizard generated virtual function overrides //{{AFX_VIRTUAL(CShowScrollText) protected: virtual void PreSubclassWindow(); //}}AFX_VIRTUAL// Implementationpublic: virtual ~CShowScrollText(); void Clear();public: // Generated message map functionsprotected: //{{AFX_MSG(CShowScrollText) afx_msg void OnPaint(); afx_msg int OnCreate(LPCREATESTRUCT lpCreateStruct); afx_msg void OnTimer(UINT nIDEvent); afx_msg BOOL OnEraseBkgnd(CDC* pDC); //}}AFX_MSG INT m_iExtend; INT m_iCount; DECLARE_MESSAGE_MAP()protected:};// ShowScrollText.cpp : implementation file//#include "stdafx.h"#include "ShowScrollText.h"#ifdef _DEBUG#define new DEBUG_NEW#undef THIS_FILEstatic char THIS_FILE[] = __FILE__;#endif/////////////////////////////////////////////////////////////////////////////// CShowScrollTextCShowScrollText::CShowScrollText(){ m_iExtend = 0; m_iCount = 0; LOGFONT logfont; ZeroMemory(&logfont, sizeof(LOGFONT)); logfont.lfCharSet = GB2312_CHARSET; logfont.lfHeight = -12; _tcscpy(logfont.lfFaceName, _T("宋体")); m_font.CreateFontIndirect(&logfont);}CShowScrollText::~CShowScrollText(){ m_font.DeleteObject();}BEGIN_MESSAGE_MAP(CShowScrollText, CStatic) //{{AFX_MSG_MAP(CShowScrollText) ON_WM_ERASEBKGND() ON_WM_PAINT() ON_WM_CREATE() ON_WM_TIMER() //}}AFX_MSG_MAPEND_MESSAGE_MAP()/////////////////////////////////////////////////////////////////////////////// CShowScrollText message handlersvoid CShowScrollText::OnPaint() { // TODO: Add your message handler code here CPaintDC dc(this); CRect rc; GetClientRect(rc); CString strText; GetWindowText(strText); CDC memDC; memDC.CreateCompatibleDC(&dc); CBitmap bmp; bmp.CreateCompatibleBitmap(&dc, rc.Width(), rc.Height()); memDC.SelectObject(&bmp); memDC.SelectObject(&m_font); dc.SelectObject(&m_font); CSize size = memDC.GetTextExtent(strText); if (size.cx > rc.Width()) { if (size.cx - m_iExtend > 0) memDC.TextOut(rc.left - m_iExtend, rc.top + (rc.Height() - size.cy)/2, strText); if (rc.left - m_iExtend + 8 +size.cx < rc.right) memDC.TextOut(rc.left - m_iExtend + 8+size.cx , rc.top + (rc.Height() - size.cy)/2, strText); } else memDC.TextOut(rc.left, rc.top + (rc.Height() - size.cy)/2, strText); dc.BitBlt(rc.left, rc.top, rc.Width(), rc.Height(), &memDC, rc.left, rc.top, SRCCOPY); memDC.DeleteDC(); bmp.DeleteObject();}int CShowScrollText::OnCreate(LPCREATESTRUCT lpCreateStruct) { if (CStatic::OnCreate(lpCreateStruct) == -1) return -1; // TODO: Add your specialized creation code here SetTimer(1, 100, NULL); return 0;}void CShowScrollText::PreSubclassWindow() { SetFont(&m_font); SetTimer(1, 100, NULL); CStatic::PreSubclassWindow();}void CShowScrollText::OnTimer(UINT nIDEvent) { // TODO: Add your message handler code here and/or call default CString strText; GetWindowText(strText); if (strText == m_strText) { CDC* pDC = GetDC(); pDC->SelectObject(&m_font); CSize size = pDC->GetTextExtent(strText); ReleaseDC(pDC); CRect rect; GetClientRect(rect); int iWidth = rect.Width(); if (size.cx > iWidth) { Invalidate(); UpdateWindow(); m_iExtend += 2; if (m_iExtend > size.cx) m_iExtend -= size.cx + 8; } } else { m_iExtend = 0; m_strText = strText; } CStatic::OnTimer(nIDEvent);}BOOL CShowScrollText::OnEraseBkgnd(CDC* pDC) { // TODO: Add your message handler code here and/or call default UNUSED_ALWAYS(pDC); return FALSE;} 急!怎样把内存中的数据块显示出来?? [Help]如何判断USB摄相头采集的视频, 是YUV还是RGB格式? 如何实现文件中换行 vc 调用vb.dll,字符串参数传递问题 电子称系统 如何通过键盘定位窗口焦点到菜单栏?请大侠帮忙!100分 帮忙看一下怎么解决这个错误,急得很...... 感谢chenhq(chenhq) 。近来接分 关于在别类--对象--使用Clist显示 想用VC编写一个检测显卡温度的程序,不知从哪入手? 向指定的IP发送自己编写的IP包 如何在DLL中动态创建的IE控件里获取里面播放的flash动画的窗口句柄?急!
{
// Construction
public:
CShowScrollText();// Attributes
public:// Operations
public:
CFont m_font;
// Overrides
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(CShowScrollText)
protected:
virtual void PreSubclassWindow();
//}}AFX_VIRTUAL// Implementation
public:
virtual ~CShowScrollText();
void Clear();public: // Generated message map functions
protected:
//{{AFX_MSG(CShowScrollText)
afx_msg void OnPaint();
afx_msg int OnCreate(LPCREATESTRUCT lpCreateStruct);
afx_msg void OnTimer(UINT nIDEvent); afx_msg BOOL OnEraseBkgnd(CDC* pDC);
//}}AFX_MSG
INT m_iExtend;
INT m_iCount;
DECLARE_MESSAGE_MAP()protected:};
// ShowScrollText.cpp : implementation file
//#include "stdafx.h"
#include "ShowScrollText.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif/////////////////////////////////////////////////////////////////////////////
// CShowScrollTextCShowScrollText::CShowScrollText()
{
m_iExtend = 0;
m_iCount = 0;
LOGFONT logfont;
ZeroMemory(&logfont, sizeof(LOGFONT));
logfont.lfCharSet = GB2312_CHARSET;
logfont.lfHeight = -12;
_tcscpy(logfont.lfFaceName, _T("宋体")); m_font.CreateFontIndirect(&logfont);
}CShowScrollText::~CShowScrollText()
{
m_font.DeleteObject();
}
BEGIN_MESSAGE_MAP(CShowScrollText, CStatic)
//{{AFX_MSG_MAP(CShowScrollText)
ON_WM_ERASEBKGND()
ON_WM_PAINT()
ON_WM_CREATE()
ON_WM_TIMER()
//}}AFX_MSG_MAP
END_MESSAGE_MAP()/////////////////////////////////////////////////////////////////////////////
// CShowScrollText message handlersvoid CShowScrollText::OnPaint()
{
// TODO: Add your message handler code here
CPaintDC dc(this);
CRect rc;
GetClientRect(rc);
CString strText;
GetWindowText(strText);
CDC memDC;
memDC.CreateCompatibleDC(&dc);
CBitmap bmp;
bmp.CreateCompatibleBitmap(&dc, rc.Width(), rc.Height());
memDC.SelectObject(&bmp);
memDC.SelectObject(&m_font);
dc.SelectObject(&m_font);
CSize size = memDC.GetTextExtent(strText);
if (size.cx > rc.Width())
{
if (size.cx - m_iExtend > 0)
memDC.TextOut(rc.left - m_iExtend, rc.top + (rc.Height() - size.cy)/2, strText);
if (rc.left - m_iExtend + 8 +size.cx < rc.right)
memDC.TextOut(rc.left - m_iExtend + 8+size.cx , rc.top + (rc.Height() - size.cy)/2, strText);
}
else
memDC.TextOut(rc.left, rc.top + (rc.Height() - size.cy)/2, strText);
dc.BitBlt(rc.left, rc.top, rc.Width(), rc.Height(), &memDC, rc.left, rc.top, SRCCOPY);
memDC.DeleteDC();
bmp.DeleteObject();
}int CShowScrollText::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
if (CStatic::OnCreate(lpCreateStruct) == -1)
return -1;
// TODO: Add your specialized creation code here
SetTimer(1, 100, NULL);
return 0;
}
void CShowScrollText::PreSubclassWindow()
{
SetFont(&m_font);
SetTimer(1, 100, NULL);
CStatic::PreSubclassWindow();
}void CShowScrollText::OnTimer(UINT nIDEvent)
{
// TODO: Add your message handler code here and/or call default
CString strText;
GetWindowText(strText);
if (strText == m_strText)
{
CDC* pDC = GetDC();
pDC->SelectObject(&m_font);
CSize size = pDC->GetTextExtent(strText);
ReleaseDC(pDC);
CRect rect;
GetClientRect(rect);
int iWidth = rect.Width();
if (size.cx > iWidth)
{ Invalidate();
UpdateWindow();
m_iExtend += 2;
if (m_iExtend > size.cx)
m_iExtend -= size.cx + 8;
}
}
else
{
m_iExtend = 0;
m_strText = strText;
}
CStatic::OnTimer(nIDEvent);
}BOOL CShowScrollText::OnEraseBkgnd(CDC* pDC)
{
// TODO: Add your message handler code here and/or call default
UNUSED_ALWAYS(pDC);
return FALSE;
}