请问透明窗体的滚动字幕闪烁的解决方案!(分太少了,只要解决一定另送分!)
请教透明窗体的滚动字幕闪烁的解决方案!!(分太少了,只要解决一定另送分!!)
本人水平非常一般,但本人诚心请教,诚心送分!!
透明窗体的实现是通过SetLayeredWindowAttributes实现的,相信做过透明的窗体的朋友们都应该知道这个函数,我是这样实现的:
SetLayeredWindowAttributes(GetSafeHwnd(),0, 0, LWA_COLORKEY);
透明窗体实现的没有任何问题.
滚动字幕我是在网上找了一个叫做CTicker的滚动字幕类,它是通过copy画布而不是简单的TextOut来实现的,如果不是在透明窗体上跑字幕那效果非常不错,我贴几段它的核心代码:
BOOL CTicker::Start( int iMilliseconds, int iPixelStep )
{
TICKERSTRUCT scr;
SIZE s;
//
// Make sure user didn 't do something dumb
//
if( iMilliseconds <= 0 )
return false;
//
// Begin timer
//
if( SetTimer( NULL, 0, iMilliseconds, (TIMERPROC)TimerProc ) == 0 )
return false;
//
// Find width of outputted text
//
GetTextExtentPoint( m_dcMemoryDC, m_buffer, m_bufferlen, &s );
m_iTextOutWidth = s.cx;
//
// Copy address of rectangle, handle to window drawn on, and pixels to step to TimerProc
//
scr.hHandle = m_hWindow;
scr.iPixelStep = iPixelStep;
scr.iTextOutWidth = m_iTextOutWidth;
scr.iTextOutX = &m_iTextOutX;
scr.pRect = &m_rectangle;
TimerProc( NULL, WM_COPYDATA, 0, (DWORD)&scr );
return true;
}
VOID CALLBACK CTicker::TimerProc( HWND hwnd, UINT uMsg, UINT_PTR idEvent, DWORD dwTime )
{
static HWND hWnd;
static int iPixelStep = 0;
static int iTextOutWidth = 0;
static int *pTextOutX = NULL;
static RECT *pRect = NULL;
int iMinX = 0;
if( uMsg == WM_COPYDATA )
{
hWnd = ((PTICKERSTRUCT)dwTime)-> hHandle;
iPixelStep = ((PTICKERSTRUCT)dwTime)-> iPixelStep;
iTextOutWidth = ((PTICKERSTRUCT)dwTime)-> iTextOutWidth;
pTextOutX = ((PTICKERSTRUCT)dwTime)-> iTextOutX;
pRect = ((PTICKERSTRUCT)dwTime)-> pRect;
}
iMinX = (0 - iTextOutWidth);
if( *pTextOutX <= iMinX )
{
*pTextOutX = pRect-> right;
//此处应为滚动结束时
}
*pTextOutX -= iPixelStep;
InvalidateRect( hWnd, pRect, FALSE );
UpdateWindow( hWnd );
}
BOOL CTicker::TextToScreen( void )
{
DWORD dwRead = 0;
RECT rectangle;
FillRect( m_dcMemoryDC, &m_rectangle, m_hBrushBackground );
if( m_bBorder )
FrameRect( m_dcMemoryDC, &m_rectangle, m_hBrushBorder );
rectangle.top = 0;
rectangle.left = m_iTextOutX;
本人水平非常一般,但本人诚心请教,诚心送分!!
透明窗体的实现是通过SetLayeredWindowAttributes实现的,相信做过透明的窗体的朋友们都应该知道这个函数,我是这样实现的:
SetLayeredWindowAttributes(GetSafeHwnd(),0, 0, LWA_COLORKEY);
透明窗体实现的没有任何问题.
滚动字幕我是在网上找了一个叫做CTicker的滚动字幕类,它是通过copy画布而不是简单的TextOut来实现的,如果不是在透明窗体上跑字幕那效果非常不错,我贴几段它的核心代码:
BOOL CTicker::Start( int iMilliseconds, int iPixelStep )
{
TICKERSTRUCT scr;
SIZE s;
//
// Make sure user didn 't do something dumb
//
if( iMilliseconds <= 0 )
return false;
//
// Begin timer
//
if( SetTimer( NULL, 0, iMilliseconds, (TIMERPROC)TimerProc ) == 0 )
return false;
//
// Find width of outputted text
//
GetTextExtentPoint( m_dcMemoryDC, m_buffer, m_bufferlen, &s );
m_iTextOutWidth = s.cx;
//
// Copy address of rectangle, handle to window drawn on, and pixels to step to TimerProc
//
scr.hHandle = m_hWindow;
scr.iPixelStep = iPixelStep;
scr.iTextOutWidth = m_iTextOutWidth;
scr.iTextOutX = &m_iTextOutX;
scr.pRect = &m_rectangle;
TimerProc( NULL, WM_COPYDATA, 0, (DWORD)&scr );
return true;
}
VOID CALLBACK CTicker::TimerProc( HWND hwnd, UINT uMsg, UINT_PTR idEvent, DWORD dwTime )
{
static HWND hWnd;
static int iPixelStep = 0;
static int iTextOutWidth = 0;
static int *pTextOutX = NULL;
static RECT *pRect = NULL;
int iMinX = 0;
if( uMsg == WM_COPYDATA )
{
hWnd = ((PTICKERSTRUCT)dwTime)-> hHandle;
iPixelStep = ((PTICKERSTRUCT)dwTime)-> iPixelStep;
iTextOutWidth = ((PTICKERSTRUCT)dwTime)-> iTextOutWidth;
pTextOutX = ((PTICKERSTRUCT)dwTime)-> iTextOutX;
pRect = ((PTICKERSTRUCT)dwTime)-> pRect;
}
iMinX = (0 - iTextOutWidth);
if( *pTextOutX <= iMinX )
{
*pTextOutX = pRect-> right;
//此处应为滚动结束时
}
*pTextOutX -= iPixelStep;
InvalidateRect( hWnd, pRect, FALSE );
UpdateWindow( hWnd );
}
BOOL CTicker::TextToScreen( void )
{
DWORD dwRead = 0;
RECT rectangle;
FillRect( m_dcMemoryDC, &m_rectangle, m_hBrushBackground );
if( m_bBorder )
FrameRect( m_dcMemoryDC, &m_rectangle, m_hBrushBorder );
rectangle.top = 0;
rectangle.left = m_iTextOutX;