hi folks
i have this code wich generates at a rich edit box a line count ....

DesenhaLinhas proc
LOCAL primeiralinha:DWORD
LOCAL tbuffer[32]:BYTE
invoke GetDC, hEdit
mov hdc,eax
invoke SelectObject,hdc,hFont
push eax
invoke SendMessage,hEdit,EM_GETFIRSTVISIBLELINE,0,0
mov primeiralinha,eax
invoke SendMessage,hEdit,EM_LINEINDEX,eax,0
invoke SendMessage,hEdit,EM_POSFROMCHAR,addr pt,eax
invoke GetClientRect,hEdit,ADDR rect
mov rect.right,19
RGB 100,110,100
invoke CreateSolidBrush,eax
invoke FillRect, hdc, ADDR rect,eax
mov eax,pt.y
mov rect.top,eax
invoke wsprintfA,addr tbuffer,txt("%li"),primeiralinha
invoke SetBkMode,hdc,TRANSPARENT
RGB 255,255,255
invoke SetTextColor,hdc,eax
invoke DrawText,hdc,addr tbuffer,-1,addr rect,DT_RIGHT
mov eax,altura
add rect.top,eax
mov eax,rect.top
inc primeiralinha
.break .if eax > rect.bottom
pop eax
invoke SelectObject,hdc,eax
invoke ReleaseDC, hEdit,hdc

DesenhaLinhas endp

the code is ok !
but when i type something the just drawned keeps blinking :(
its some kind of WM_PAINT over and over after each letter typed..
so the line count is drawned again and again..
is there any way to prevent the updated area from blinking ?
Posted on 2005-01-16 15:08:00 by GR33d
anyone ?!?!
Posted on 2005-01-17 14:55:56 by GR33d

Where do you call this procedure (what message in your messageprocedure) ?
Posted on 2005-01-17 15:46:36 by Jurgen
this code is inside the WM_PAINT message in the RichEdit Proc :

NewRichProc proc hWin:HWND, uMsg:UINT, wParam:WPARAM, lParam:LPARAM

mov eax,uMsg
.if eax==WM_KEYDOWN
.if wParam == VK_DELETE || wParam == VK_BACK || wParam == VK_RETURN || wParam == VK_SPACE
invoke SendMessage,hEdit,EM_STOPGROUPTYPING,0,0
.elseif eax==WM_TIMER
call GetInfo
.elseif eax==WM_PAINT
invoke CallWindowProc,OldRichProc,hWin,uMsg,wParam,lParam
call DesenhaLinhas
xor eax,eax
invoke CallWindowProc,OldRichProc,hWin,uMsg,wParam,lParam
NewRichProc endp

it calls the last posted proc to draw the lines(DesenhaLinhas)
Posted on 2005-01-17 17:15:55 by GR33d
I made a little test program from the riched example in the masm folder and added your code. I don't get any blinking text on my XP computer. :?
Posted on 2005-01-17 20:21:10 by Jurgen
the code is incomplete
did the lines and the NUMBERS on the left showed up ?
because when i type something the NUMBERS blink....
(i have a XP too :P )
Posted on 2005-01-17 20:24:40 by GR33d
Yes, the numbers showed up (i don't have any lines).
Posted on 2005-01-17 20:27:47 by Jurgen
and the NUMBERS ? did they show ?

isnt there any API call wich prevents a area from update ?
Posted on 2005-01-17 20:30:53 by GR33d
I edited my previous post.
Posted on 2005-01-17 20:32:59 by Jurgen
just remember, the code is incomplete
the drawned sidebar is a representation for the selection bar from richedit box
and some other properties were applyed to the richedit too :!:
may act diff from your test
Posted on 2005-01-17 20:37:04 by GR33d
I'm thinking the richedit box redraws itself internally and if you have graphics overlaying it, it becomes more noticeable.

I would say try making a backbuffer and blit your text and graphics there. On every keystroke or update needed, blit it to the front dc (hdc).
The flicker will disappear.

Also check for any stray updates to your window via InvalidateRect or UpdateWindow.
Posted on 2005-01-18 09:17:25 by drarem
when you say blit, means BitBlt api call ?
and a seconday buffer would be created with a CreateCompatibleDC right ?

Posted on 2005-01-18 09:22:52 by GR33d
yes, here's my backbuffer function:

the SetDC calls the same as SelectObject. I have my dc's set up in a structure, they can easily be this tho:

hDC dd ?
memDC dd ?

BackBuffer Proc w:DWORD, h:DWORD

invoke CreateCompatibleDC,WND.hDC
mov WND.memDC,eax

invoke CreateCompatibleDC,WND.hDC
mov WND.backDC,eax
invoke CreateCompatibleBitmap,WND.hDC,w,h
mov WND.backBMP,eax
invoke SetDC,WND.backDC,WND.backBMP
mov WND.backOBMP,eax ;save old one to restore later

invoke CreateCompatibleDC,0
mov WND.maskDC, eax

BackBuffer endp
Posted on 2005-01-18 10:16:31 by drarem
that should be useful
can i do the changes before i set the new hdc with :
invoke SetDC,WND.backDC,WND.backBMP

edit:i really hate these hdc stuff :roll:
Posted on 2005-01-18 12:01:33 by GR33d
I would set the dc in the WM_INITDIALOG or WM_CREATE portion of the wndproc. Don't release/change back/destroy the dc until the WM_CLOSE message.

like this:

.elseif uMsg == WM_CREATE
invoke GetDC,hWin
mov WND.hDC,eax

you can replace the setdc with this to alleviate confusion:

invoke SelectObject, WND.backDC,WND.backBMP
mov WND.oldbackBMP,eax ;<== store original DC's bitmap

Then you write to the DC instead of writing to the screen:

invoke SetTextColor, WND.backDC, eax
invoke DrawText, Wnd.backDC,addr tbuffer, ....

in your WM_PAINT or your main procedure:

invoke BitBlt, WND.hDC, 0,0, xrez,yrez, WND.backDC,0,0, SRCCOPY
;copies backbuffer to front

Let me know if it helps, hope I'm not leading you astray.
Posted on 2005-01-18 12:42:30 by drarem
Okay, I using 'TextOut' API and the 'UpdateWindow' API to draw text onto another window. (A DirectX game window)

I get a bad flicker in the text, and drarem, will this BackBuffer method prevent the text from flicker even when it's on a DirectX window?

If so, can you show me the code that I would need to implement.

When it comes to backbuffering I am new to it, I am pretty lost. So help for this problem would be much appreciated.
Posted on 2005-01-18 20:51:03 by BBS
It has been awhile since I played with directx2d and dev-c++, I used the directdrawsurface to store the bitmaps:

IDirectDrawSurface7* primary; // this is the main 'hDC' to blit to
IDirectDrawSurface7* bckgnd; // background 'dc' to blit to
IDirectDrawSurface7* bgstrip; // for scrolling

here was the function to create an offscreen bitmap to draw text or blit sprites to, then blit from this and/or other 'back buffer' for multiple levels to the main one.

IDirectDrawSurface7 * DDCreateBitmap(IDirectDraw7* dd, DDSURFACEDESC2 ddsd, int bx, int by) {
// Usage: DDCreateBitmap
// IDirectDraw7* dd
// int bitmap width
// int bitmap height
IDirectDrawSurface7* bufferA;
memset(&ddsd, sizeof(ddsd), 0);
ddsd.dwSize = sizeof(ddsd);

ddsd.dwHeight = by; // Our ball is 32 pixels high
ddsd.dwWidth = bx; // and 32 pixels wide

r = dd->CreateSurface(&ddsd, &bufferA, 0);
return bufferA;
Posted on 2005-01-18 21:16:13 by drarem