Draw text without HDC, possible?
-
Yo guys, I got a lit' problem here with the text drawin', hope y'all can help me out. ;) I've made myself a bitmap class, it can load bitmaps, it can manipulate bitmaps, and things like that, without touchin' HDC. Alright? So I'll be touchin' HDC only at the final stage, that's when I draw out the bitmap to the screen. So the problem now is, I can't draw text onto my bitmap class, before it goes out to the HDC. That means, I have a bitmap, I draw it out to the HDC, THEN only I'm able to draw text with HDC. This causes the text to flicker EVERYTIME when I refresh the bitmap. Just wonderin', if there's any ways to draw those texts, onto the bitmap (without touchin' HDC) before output to the screen (HDC)? I believe there is, like in Flash, I think they use their own bitmap manipulation classes, and draw text on those bitmaps, and FINALLY output the result to the HDC. Hey, thanks dude for your time, hope y'all can help me out ;) Zee ya!! Me, Baling.
-
Yo guys, I got a lit' problem here with the text drawin', hope y'all can help me out. ;) I've made myself a bitmap class, it can load bitmaps, it can manipulate bitmaps, and things like that, without touchin' HDC. Alright? So I'll be touchin' HDC only at the final stage, that's when I draw out the bitmap to the screen. So the problem now is, I can't draw text onto my bitmap class, before it goes out to the HDC. That means, I have a bitmap, I draw it out to the HDC, THEN only I'm able to draw text with HDC. This causes the text to flicker EVERYTIME when I refresh the bitmap. Just wonderin', if there's any ways to draw those texts, onto the bitmap (without touchin' HDC) before output to the screen (HDC)? I believe there is, like in Flash, I think they use their own bitmap manipulation classes, and draw text on those bitmaps, and FINALLY output the result to the HDC. Hey, thanks dude for your time, hope y'all can help me out ;) Zee ya!! Me, Baling.
There are two main things which could cause flickering : 1.) Not using a memory HDC/CDC when updating the bitmap or text. 2.) Not overriding OnEraseBkgnd in your View class. The problem is probably caused by no.1 since otherwise your whole bitmap would flicker upon refresh too. What I think maybe happening is your program is drawing the bitmap directly to the screen, quickly followed by the text. This leaves a very very short period in which you see just the bitmap, thus a flickering effect is caused. What I recommend you do is create a new CDC called SrcDC, and use CreateCompatibleDC(NULL), and select the bitmap into it. I would then create another dc called DestDC (in same way), and BitBlt the SrcDC to the DestDC. I would then draw the text onto the DestDC (this has the effect of drawing onto the class) using DestDC's TextOut() function, before *finally* BitBlt'ing the DestDC to the screens *pDC that is found in your OnDraw routine. Basically *only* the final image should be drawn to the screen in 1 BitBlt, there shouldn`t be any other routines which draw to the same *pDC after this or else flickering may occur. Hope this helped, Alan. "When I left you I was but the learner, now I am the Master" - Darth Vader:mad:
-
There are two main things which could cause flickering : 1.) Not using a memory HDC/CDC when updating the bitmap or text. 2.) Not overriding OnEraseBkgnd in your View class. The problem is probably caused by no.1 since otherwise your whole bitmap would flicker upon refresh too. What I think maybe happening is your program is drawing the bitmap directly to the screen, quickly followed by the text. This leaves a very very short period in which you see just the bitmap, thus a flickering effect is caused. What I recommend you do is create a new CDC called SrcDC, and use CreateCompatibleDC(NULL), and select the bitmap into it. I would then create another dc called DestDC (in same way), and BitBlt the SrcDC to the DestDC. I would then draw the text onto the DestDC (this has the effect of drawing onto the class) using DestDC's TextOut() function, before *finally* BitBlt'ing the DestDC to the screens *pDC that is found in your OnDraw routine. Basically *only* the final image should be drawn to the screen in 1 BitBlt, there shouldn`t be any other routines which draw to the same *pDC after this or else flickering may occur. Hope this helped, Alan. "When I left you I was but the learner, now I am the Master" - Darth Vader:mad:
Alan, thanks for the solution. So it goes like this: SrcDC --> DestDC --> DestDC.DrawText() --> pDC->BitBlt(DestDC) But usin' this approach, the final stage will involve the transferin' of the whole DestDC to pDC, right? pDC->BitBlt(..., &DestDC, ..., SRCCOPY); This will be heavy, because the interface redraws itself quite frequently (i.e. mouse movements makes the button change background, and stuff like that). I know InvalidateRect, but my bitmap class doesn't handle that, it will still draw the whole background all over again. And I'm takin' over the whole dialog's paintin'. That means the background will even go up to the screen size, which might be 1024x768! ;P (The whole window will repain, when resized, even InvalidateRect won't help in this case.) I've tried that approach, but seems slow, maybe I should use InvalidateRect whenever possible. Thanks again for your solution man ;) Me, Baling.