I coded an textscrollengine. it works fine on usual windows. but when i use it on windows with WS_EX_LAYERED style the scroller is very slow and flickers.

Any ideas?

i attached the sourcecode.
Posted on 2008-02-20 19:51:17 by diablo2oo2
clear the question.

i don't know how to figure out.
Attachments:
Posted on 2008-02-22 00:56:31 by dcskm4200
problem is solved. if you use the textscroller with a transparent window, you should add SetLayeredWindowAttributes inside the scrollerloop:

	@loop:

.if .scroll_pause==0

invoke BitBlt,local_hdc_text,0,0,.scroll_width,local_scroll_height,local_hdc_window_copy,.scroll_x,.scroll_y,SRCCOPY

invoke TextOut,local_hdc_text,ebx,0,.scroll_text,local_text_len

invoke BlendBitmap,local_hdc_text,local_hdc_window_copy,local_scroll_height,.scroll_width,.scroll_x,.scroll_y,.scroll_textcolor

invoke BitBlt,local_hdc_window,.scroll_x,.scroll_y,.scroll_width,local_scroll_height,local_hdc_text,0,0,SRCCOPY

dec ebx

.if ebx==local_text_endpos
;---reset text position to begining---
mov ebx,.scroll_width
.endif

;---important for transparent window---
movzx eax,.scroll_alpha
.if al!=0 && al!=255
invoke SetLayeredWindowAttributes,.scroll_hwnd,0,eax,LWA_ALPHA
.endif
.endif

invoke Sleep,30

jmp @loop
Posted on 2008-02-25 10:52:44 by diablo2oo2
Thanks.
Posted on 2008-02-25 23:09:09 by dcskm4200
thanks diablo2oo2  :D
Posted on 2008-02-26 09:46:15 by Ahmed18
Very pretty
Posted on 2008-02-26 11:25:18 by JimmyClif
Here is my final version of TextScroll engine with example sourcecode

Download here
http://diablo2oo2.di.funpic.de/downloads/textscroller.rar
http://free.pages.at/d2k2/downloads/textscroller.rar
Attachments:
Posted on 2008-02-26 18:44:39 by diablo2oo2
I updated the code. Now the scrolltext engine doesnt use GetPixel & SetPixel API.

Download here
http://diablo2oo2.di.funpic.de/downloads/textscroller.rar
http://free.pages.at/d2k2/downloads/textscroller.rar




;******************************************************************************
;* STRUCTURE                                                                  *
;******************************************************************************

SCROLLER_STRUCT struct
scroll_hwnd dd ? ;handle of window where to draw
scroll_text dd ? ;pointer scrolltext
scroll_x dd ? ;x position
scroll_y dd ? ;y position
scroll_width dd ? ;width of scroller
scroll_hFont dd ? ;Handle of Font
scroll_textcolor dd ? ;example: 00F7DDCCh (00BBGGRR)
scroll_alpha db ? ;value for transparency (if using it on WS_EX_LAYERED window)
scroll_wait dd ? ;wait time (milliseconds) before draw scrolltext
scroll_pause db ? ;dont modify this! Use PauseScroller function!
SCROLLER_STRUCT ends



;******************************************************************************
;* PROTOTYPES                                                                *
;******************************************************************************

;---public functions---
CreateScroller PROTO :DWORD
PauseScroller PROTO :DWORD



;******************************************************************************
;* diablo2oo2's Textscroller Engine                                          *
;******************************************************************************


include Textscroller.inc


;---private functions of scroller engine---
ScrollThread PROTO :DWORD
BlendBitmap PROTO :DWORD,:DWORD,:DWORD,:DWORD
BlendPixel PROTO :DWORD,:DWORD,:DWORD
PercentValue PROTO :DWORD,:DWORD
PercentColor PROTO :DWORD,:DWORD
GetDIBPixel PROTO :DWORD,:DWORD,:DWORD,:DWORD,:DWORD
SetDIBPixel PROTO :DWORD,:DWORD,:DWORD,:DWORD,:DWORD,:DWORD


;******************************************************************************
;* CODE                                                                      *
;******************************************************************************

.code
;---public---
CreateScroller proc _scrollstruct:dword

LOCAL ThreadID :DWORD

fn CreateThread,0,0,addr ScrollThread,_scrollstruct,0,addr ThreadID
fn CloseHandle,eax

ret
CreateScroller endp


PauseScroller proc _scrollstruct:dword

mov eax,_scrollstruct
assume eax:ptr SCROLLER_STRUCT

mov cl,.scroll_pause

.if cl==0
inc cl
.else
dec cl
.endif

mov .scroll_pause,cl

assume eax:nothing

ret
PauseScroller endp


;---private---
ScrollThread proc _scrollstruct:dword

LOCAL local_hdc_window :DWORD
LOCAL local_hdc_window_copy :DWORD
LOCAL local_hdc_text :DWORD

LOCAL local_scroll_height :DWORD

LOCAL local_text_len :DWORD
LOCAL local_text_width :DWORD
LOCAL local_text_endpos :DWORD

LOCAL local_pbmi :BITMAPINFO
LOCAL local_pixels_window_copy :DWORD
LOCAL local_pixels_text :DWORD

LOCAL local_sz :SIZEL


;---scroller structure---
mov esi,_scrollstruct
assume esi:ptr SCROLLER_STRUCT


;---wait before draw---
mov eax,.scroll_wait
.if eax<500
mov eax,500
.endif
fn Sleep,eax ;important!


;---Textlen---
fn lstrlen,.scroll_text
mov local_text_len,eax



;---get window dc---
fn GetDC,.scroll_hwnd
mov local_hdc_window,eax



;---HDC for text---
fn GetDC,0
fn CreateCompatibleDC,eax
mov local_hdc_text,eax

;---use custom font---
fn SelectObject,eax,.scroll_hFont

;---get Textheight and width---
fn GetTextExtentPoint,local_hdc_text,.scroll_text,local_text_len,addr local_sz
.if eax==TRUE

m2m local_scroll_height,local_sz.y
m2m local_text_width,local_sz.x


;---..hdc for text---
fn CreateCompatibleBitmap,local_hdc_window,.scroll_width,local_scroll_height
fn SelectObject,local_hdc_text,eax


lea edi,local_pbmi
assume edi:ptr BITMAPINFO

fn RtlZeroMemory,edi,sizeof BITMAPINFO

mov .bmiHeader.biSize , sizeof BITMAPINFOHEADER
m2m .bmiHeader.biWidth , .scroll_width
m2m .bmiHeader.biHeight , local_scroll_height
mov .bmiHeader.biPlanes , 1
mov .bmiHeader.biBitCount , 32
mov .bmiHeader.biCompression , BI_RGB


fn CreateDIBSection,local_hdc_text,edi,DIB_RGB_COLORS,addr local_pixels_text,0,0
fn SelectObject,local_hdc_text,eax
assume edi:nothing


;---HDC for windowcopy---
fn GetDC,0
fn CreateCompatibleDC,eax
mov local_hdc_window_copy,eax



;---window dib & window copy---
lea edi,local_pbmi

fn CreateDIBSection,local_hdc_window_copy,edi,DIB_RGB_COLORS,addr local_pixels_window_copy,0,0
fn SelectObject,local_hdc_window_copy,eax

fn BitBlt,local_hdc_window_copy,0,0,.scroll_width,local_scroll_height,local_hdc_window,.scroll_x,.scroll_y,SRCCOPY


;---Set Text Color---
fn SetBkMode,local_hdc_text,TRANSPARENT
fn SetTextColor,local_hdc_text,.scroll_textcolor


;---for transparent windows---
fn GetModuleHandle,"user32.dll"
fn GetProcAddress,eax,"SetLayeredWindowAttributes"
mov edi,eax

;---calc endposition of text---
xor eax,eax
sub eax,local_text_width
sub eax,8
mov local_text_endpos,eax


;---prepare loop---
mov ebx,.scroll_width ;ebx=text position
add ebx,4


;---loop---
@loop:

.if .scroll_pause==0

;---draw background for scroll gfx---
fn BitBlt,local_hdc_text,0,0,.scroll_width,local_scroll_height,local_hdc_window_copy,0,0,SRCCOPY

;---draw scrolltext on background---
fn TextOut,local_hdc_text,ebx,0,.scroll_text,local_text_len

;---fade text in and out---
fn BlendBitmap,local_pixels_text,local_pixels_window_copy,local_scroll_height,.scroll_width

;---draw scrolltext on window---
fn BitBlt,local_hdc_window,.scroll_x,.scroll_y,.scroll_width,local_scroll_height,local_hdc_text,0,0,SRCCOPY

dec ebx

.if ebx==local_text_endpos
;---reset text position to begining---
mov ebx,.scroll_width
.endif


;---important for transparent window---
.if edi!=0
movzx eax,.scroll_alpha
.if al!=0 && al!=255
Scall edi,.scroll_hwnd,0,eax,LWA_ALPHA
.endif
.endif
.endif

fn Sleep,30

jmp @loop

.endif

assume esi:nothing

ret
ScrollThread endp


;---Blend Routine---
align 16
BlendBitmap proc uses esi edi ebx _text_dib, _window_copy_dib, _height, _width

LOCAL local_blendvalue :DWORD
LOCAL local_fadeout_pos :DWORD

.const
FADE_WIDTH equ 25
FADE_STEP equ 4

.code
mov eax,_width

.if eax>=2*FADE_WIDTH ;only works with minimum width


;---calc x-coordinate where to start fade out---
sub eax,FADE_WIDTH
mov local_fadeout_pos,eax


;---prepare loop--
xor esi,esi ;x=width
mov local_blendvalue,0


;---blend loop---
.while esi!=_width

xor edi,edi ;y=height

.while edi!=_height

;---get pixel of scrolltext hdc---
fn GetDIBPixel,esi,edi,_text_dib,_width,_height
mov ebx,eax

fn GetDIBPixel,esi,edi,_window_copy_dib,_width,_height

fn BlendPixel,eax,ebx,local_blendvalue

fn SetDIBPixel,esi,edi,_text_dib,_width,_height,eax

inc edi
.endw


;---for fading---
.if esi<FADE_WIDTH
add local_blendvalue,FADE_STEP ;4 * 25pixel = 100 %

.elseif esi==FADE_WIDTH
;---skip non fading area and jump zo fadeout area---
mov esi,local_fadeout_pos

.elseif esi>local_fadeout_pos
sub local_blendvalue,FADE_STEP ;4 * 25pixel = 100 %

.endif

inc esi
.endw
.endif

ret
BlendBitmap endp



align 16
GetDIBPixel proc _x,_y,_pDIBits,_width,_height

mov eax,_width
mov ecx,_height

sub ecx,_y
dec ecx
mul ecx
shl eax,2 ; adjust for DWORD size
push eax ; push the result onto the stack

mov eax,_x
shl eax,2 ; adjust for DWORD size
pop ecx ; pop the scan line offset off the stack
add eax,ecx

add eax,_pDIBits ; add the offset to the DIB bit
mov eax,

RET
GetDIBPixel endp


align 16
SetDIBPixel proc _x,_y,_pDIBits,_width,_height,_color

mov eax,_width
mov ecx,_height

cmp _x,eax
jae @exit

cmp _y,ecx
jae @exit

sub ecx,_y
dec ecx
mul ecx
shl eax,2 ; adjust for DWORD size
mov edx,eax

mov eax,_x
shl eax,2 ; adjust for DWORD size
add eax,edx

add eax,_pDIBits ; add the offset to the DIB bit
mov ecx,_color
mov ,ecx

@exit:
RET
SetDIBPixel endp


align 16
BlendPixel proc uses esi edi ebx _sourcepixel:dword,_overpixel:dword,_transparency:dword

;---parameters---
;_sourcepixel  : Pixel of Backgroundimage
;_overpixel    : Pixel which overlaps the sourcepixel
;_transparency : 5 - 90 %  (using 100 % is stupid)

;---Color Format---
; 00 00 00 00
; xx BB GG RR

.if _transparency<100

mov eax,_overpixel
.if eax!=_sourcepixel

;---calc new colors of _sourcepixel---
mov eax,100
sub eax,_transparency

fn PercentColor,_sourcepixel,eax
mov ebx,eax


;---calc new colors of _overpixel---
fn PercentColor,_overpixel,_transparency


;---add each color---
xor esi,esi

.while esi!=3

movzx edx,al
movzx ecx,bl

add edx,ecx
.if edx>255
mov dl,255
.endif

mov al,dl

ror eax,8
ror ebx,8

inc esi
.endw

rol eax,3*8
.else
mov eax,_overpixel
.endif
.else
mov eax,_overpixel

.endif

ret
BlendPixel endp


align 16
PercentValue proc _value:dword,_percent:dword

mov eax,_value

mul _percent

mov ecx,100

xor edx,edx
div ecx

ret
PercentValue endp


align 16
PercentColor proc uses esi edi ebx _color:dword,_percent:dword

;---reduce color by certain percent---

mov ebx,_color

;---Red--
movzx eax,bl

fn PercentValue,eax,_percent
mov edi,eax


;---Green---
ror ebx,8
movzx eax,bl
fn PercentValue,eax,_percent

ror edi,8
mov edx,edi
mov dl,al
mov edi,edx


;---Blue---
ror ebx,8
movzx eax,bl
fn PercentValue,eax,_percent

ror edi,8
mov edx,edi
mov dl,al
mov edi,edx


;---return new color value---
rol edi,16
mov eax,edi

ret
PercentColor endp


------------------

usage:
...
.if eax==WM_INITDIALOG

;---make dialog transparent---
fn MakeDialogTransparentValue,hwnd,TRANSPARENT_VALUE


;---fill scroll structure---
m2m scr.scroll_hwnd,hwnd

mov scr.scroll_text,chr$("Test 123 ... This is a scrolltext")

mov scr.scroll_x,10
mov scr.scroll_y,20

mov scr.scroll_width,280

fn lstrcpy,addr lf.lfFaceName,"MS SANS SERIF"
mov lf.lfHeight,40
mov lf.lfCharSet,DEFAULT_CHARSET
mov lf.lfQuality,ANTIALIASED_QUALITY
fn CreateFontIndirect,addr lf ;returns handle of Font
mov scr.scroll_hFont,eax

mov scr.scroll_alpha,TRANSPARENT_VALUE
mov scr.scroll_textcolor,00040302h

fn CreateScroller,addr scr
...
Posted on 2008-11-24 14:59:39 by diablo2oo2