Enabling DoubleBuffered?

EDIT:
Edited the title of the topic... Wow, fail... lmao!. It was
Enabling DoubleBurred?


This was an original post which came around to this question, so I thought I'd make a new topic.

I was given this link to enable DoubleBuffered.
http://msdn.microsoft.com/en-us/library/system.windows.forms.control.doublebuffered.aspx#Y0

To be quite honest, when I got to MSDN, most of the time it baffles me, lol.

This is the code I have within my WM_PAINT case:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
case WM_PAINT:
			{
				PAINTSTRUCT ps;
				HDC hdc = GetDC( hWnd );
				HDC memDC = CreateCompatibleDC( hdc );

				memDC = BeginPaint(hWnd, &ps);
				// TODO: Add any drawing code here...

				//get text
				SelectObject (memDC, titleText);
				SetBkMode (memDC, TRANSPARENT);

				//title
				TextOut( memDC, 20, 3, aTitle, _tcslen( aTitle ) );

				//set up a buffer for the charCount
				TCHAR buff[ 5 ];

				//select smaller text
				SelectObject (memDC, text);

				//show copyright info
				TextOut( memDC, 620, ( wHeight - 50 ), copyRight, _tcslen( copyRight ) );

				//show chars left text
				TextOut( memDC, 9, ( eHeight + 50 ), charsLeft, _tcslen( charsLeft ) );
				TextOut( memDC, 100, ( eHeight + 50 ), buff, wsprintf( buff, L"%d", c.getCharCount() ) );

				//draw to the window
				BitBlt( hdc, 0, 0, 0, 0, memDC, 0, 0, SRCCOPY );

				ReleaseDC( hWnd, hdc );
				DeleteDC( memDC );

				EndPaint(hWnd, &ps);
				break;
			}


Assuming this is correct, how do I go about enabling the DoubleBuffered bool to true?
Last edited on
When you process WM_PAINT, you MUST call for BeginPaint() and you use the HDC provided by this function to draw. You must not use GetDC() and instead you must use the HDC returned by BeginPaint().

Then you talk about setting some variable named DoubleBuffered to true? Ah, I see. You are reading a document about .Net, not pure C++. Disregard that document.

But back to the double buffering technique. You are doing it wrong. The memory DC is not the one returned by BeginPaint(). That's the real DC. After you call BeginPaint() (get rid of GetDC() and replace it with BeginPaint()), you can then create a memory DC using CreateCompatibleDC(). At this point you are missing a step: You must create a compatible bitmap with the function CreateCompatibleBitmap(). Make sure the compatible bitmap is the same size as your window's client area (obtain the window's client area with GetClientRect()).

Once the bitmap has been created, you must select this new bitmap into the memory DC. After that you use that memory DC for all drawing instructions, as I see you are doing.

Finally, once all drawing has been done, you blit the results into the real DC (the one provided by BeginPaint()). Your call to BitBlt() is wrong. See MSDN Online for the explanation of each parameter.

http://msdn.microsoft.com/en-us/library/dd183370(VS.85).aspx
Thank you!!!!!! I spent all day yesterday trying to get that to work!

On another note, lol. When the window gets redrawn/painted the mouse cursor disappears, until it's moved.

Is there a solution for that?

Again, thanks a lot for your help!
Well, no, I have no idea why that happens. In any PC? That's weird. The mouse is responsibility of the operating system.

I can only offer a workaournd. Use ShowCursor() to hide the cursor, then paint, then show it.
I'm not sure about any PC. No one else has tried it.

Here's a link for it, if you want to have a look at it:
http://sites.google.com/site/davevisone/home/win32api/win32-api

Edit:
The above workaround doesn't work.
Last edited on
Ran your app and I don't experience any problem with the cursor. Using Windows 7 Enterprise, 32-bit. Any special steps to reproduce the issue?
No real way to repeat it. It just happens every time I enter/delete characters from the edit control.

Well, while I was about to record it happening. It's stopped happening :/ ahaha!

Now the mouse just flashes each keypress.

Edit:
Just restarted Windows to try it again. It makes the mouse disappear. Until, I start screen capture software. Once that's open, the mouse will just 'blink'. Even after the software is closed.

Apparently not. While it's open, the mouse blinks. When closed, the mouse disappears. Could it be something to do with the screen capture refreshing my screen etc?

Another Edit:
I used my phone to record it. The mouse only disappears while over the program.
http://s749.photobucket.com/albums/xx132/Bigdave876/Videos/?action=view&current=video-2011-12-14-16-01-32.mp4
Last edited on
Ah, I see what you mean. That seems to be standard Windows behavior. For example, I just opened a new email message in Outlook and started typing an email address in the To: field. The cursor disappeared.
hmm that seems a bit, for want of a better word, ugly. For Windows.

I've never noticed that before, but I just tried what you said, but in Notepad. It also happens there. I'm sure that's never happened before! ahaha

Maybe I'm in need of new gCard drivers, or another format.
What I don't understand is why the flickering. I guess it has to do with the child windows because you are double buffering.

I just tested a modification: I calculate the rectangle occupied by the count of characters in the WM_PAINT message and I then use this rectangle in the call to InvalidateRect() when you process WM_COMMAND for the edit boxes. This eliminates the flicker. I also pass false as last parameter to InvalidateRect() because the window has no background brush, so it is pointless to request a background erase.

Having said that, I think the flickering will also go away if you make the window clip the siblings children. I'll test....

TESTED: Clipping the children via the windows style WS_CLIPCHILDREN when you create the main window makes the flickering disappear completely.
Last edited on
...thought the topic said DoubleButtered. Very disappointed.
Furniture on a C++ forum, there's no place for that here, sir! lmao!
http://doublebutter.com/
webJose, I could kiss you... LOL

Thanks a lot for the help! It's very much appreciated!!
Topic archived. No new replies allowed.