Click here to Skip to main content
15,881,793 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello everyone!

I would like to start by saying thanks to everyone who takes some time to view this thread and try to help.

I have made gradient background for main window, using GradientFill( ... ) API.

Everything works fine on Windows 7, but on Windows XP the following problem occurs:

When I drag my window all the way to the left, so half of it disappears from the screen, and then return it back to the screen, so it can be fully visible, my main window's background turns into white ( white is the brush I have assigned in window class creation ) on the portion of the window that was not visible.

After I do minimize and maximize, everything is painted properly.

If I move other window to invalidate portion of my window, everything paints well.

I have tried adding InvalidateRect( hWndMainWindow, NULL, TRUE ); in WM_ERASEBKGND and it solved it, but at the expense of flickering.

I suspect that it has something to do with the updating region or device context, but I don't know what to do to fix it.

That would be all, thanks again to everyone who will try to help.

I work in MS Visual Studio Express 2008, on Windows XP, in C++, using pure WIN32 API.

If any other information is required ( source code or something similar ), please ask for it, I will more than gladly supply it.
Posted
Updated 10-Jun-13 14:27pm
v2
Comments
Sergey Alexandrovich Kryukov 10-Jun-13 19:38pm    
Basically, you really need to Invalidate, and to avoid flicker, you need to use double buffering.
—SA
MyOldAccount 10-Jun-13 23:53pm    
So, instead of painting directly into HDC returned from BeginPaint( .. ), I should treat it as any other bitmap, and use the same method ?
Thank you for the reply.
Sergey Alexandrovich Kryukov 11-Jun-13 0:23am    
I don't quite understand what do you mean, but... The flicker appears when you draw thing one on top of another. If you first draw it all onto some bitmap, and than draw all bitmap at once, it will do it without visible flicker...
—SA
MyOldAccount 11-Jun-13 1:20am    
Well, from your comment I have concluded that I should do it with following steps:

1.) Creating compatible DC;
2.) Creating compatible bitmap;
3.) Drawing everything on bitmap;
4.) StretchBlt bitmap;

If so, I could use some code examples...
The_Inventor 11-Jun-13 0:24am    
There are a couple of ways to color the window background.
http://msdn.microsoft.com/en-US/library/a48eab8d(v=VS.80).aspx is one such way.
Another one can be found -> http://www.codeproject.com/Articles/1378/Drawing-transparent-bitmaps-using-CImage
And this one will show you how to do it flicker free -> http://msdn.microsoft.com/en-us/library/ahd07sdd(v=vs.60).aspx

1 solution

In a header file (*.h)
C++
// Attributes
public:
       CBitmap bmpPlayer;
       CDC*  m_pdcPlayerMem;


Then in the implementation file (*.c, *.cpp)
C++
void CView::OnDraw(CDC* pDC)
{
         bmpPlayer.LoadBitmap(IDBMP_PLAYER1);
         m_pdcPlayerMem->CreateCompatibleDC(NULL);
         m_pdcPlayerMem->SelectObject(&bmpPlayer);
         pDC->BitBlt(600, 300, 150, 200, m_pdcPlayerMem,
         0, 0, SRCCOPY);
}


Or something like that ...
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900