News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

Drawing in an existing window?

Started by knockjoke, February 10, 2011, 07:56:11 PM

Previous topic - Next topic

knockjoke

Hi,

I know this is possible with GDI but that is flickering like hell. Is there a way to draw some text in an existing directx9 window without this flickering issue?
Ive stumbled across DirectDraw but it seems so damn complex.. What would you guys suggest me? Can anyone hook me with a small example?
Thanks in advance.

dedndave

use the forum search tool
look for "CreateCompatibleDC", "BitBlt", "DIB"
you might also try "flicker"

jj2007

   mov hDC, rv(GetDC, hCanvas)  ; canvas can be the main window, or a static child, or an edit window, or ...
   mov memDC, rv(CreateCompatibleDC, eax)   ; prepare for a bitmap
   mov hBmp, rv(CreateCompatibleBitmap, hDC, esi, ebx)   ; hDC, not memDC!
   invoke SelectObject, memDC, eax

CASE WM_PAINT
... do drawing to memDC ...

   lea edi, ps   ; ptr PAINTSTRUCT
   invoke BeginPaint, hCanvas, edi
   invoke BitBlt, eax, 0, 0, rc.right, rc.bottom, memDC, 0, 0, SRCCOPY
   invoke EndPaint, hCanvas, edi

And read Microsoft's view on CS_OWNDC vs Raymond Chen's view

zemtex

There are three things to keep in mind to avvoid flicker.

1: You should avvoid the system of erasing the background of the window, if it does that it will update the window pixels data two times per one time window update, this will produce flicker.
2: You should use double buffering with a compatible dc and bitmap.
3: If your controls flicker you can set WS_CLIPCHILDREN in the style of your window

Beside this you can also look into the the extended window style WS_EX_COMPOSITED, it speaks about double buffering, I havent checked it out though, just recall I've seen it.
I have been puzzling with lego bricks all my life. I know how to do this. When Peter, at age 6 is competing with me, I find it extremely neccessary to show him that I can puzzle bricks better than him, because he is so damn talented that all that is called rational has gone haywire.

jj2007

Quote from: zemtex on February 11, 2011, 08:45:23 AM
WS_EX_COMPOSITED

Can someone explain WS_EX_COMPOSITED
controls implemented as non managed child window's are deprecated. Support to draw them flicker free has been effectively removed

Microsoft at work :lol

dedndave

Quote3: If your controls flicker you can set WS_CLIPCHILDREN in the style of your window

thanks for the tip zemtex
hadn't thought of it, but it makes perfect sense