Problem with a windowed DirectX program
Hello everyone. I''m having a bit of trouble getting my program to process the WM_PAINT Message correctly. Whenever another application is moved onto the program''s window and then moved elsewhere over the program''s window, the program will draw over the window on top of it when trying to revalidate the invalid rectangle. I''m not sure how I could make it so it only redraws what it needs to redraw. Here''s my code example:
--------------------------------------------------------
case WM_PAINT:
{
hdc = BeginPaint(hWnd, &ps);
RECT rcWindow;
RECT rcSrcWindow;
RECT rcDstWindow;
GetWindowRect(hWnd,&rcWindow);
rcDstWindow.top = (rcWindow.top + ps.rcPaint.top);
rcDstWindow.left = (rcWindow.left + ps.rcPaint.left);
rcDstWindow.bottom = (rcWindow.top + ps.rcPaint.bottom);
rcDstWindow.right = (rcWindow.left + ps.rcPaint.right);
rcSrcWindow.top = (ps.rcPaint.top);
rcSrcWindow.left = (ps.rcPaint.left);
rcSrcWindow.bottom = (ps.rcPaint.bottom);
rcSrcWindow.right = (ps.rcPaint.right);
lpddsPrimary->Blt(&rcDstWindow,lpddsSurface,&rcSrcWindow,DDBLT_WAIT,NULL);
EndPaint(hWnd, &ps);
return(0);
} break;
--------------------------------------------------------
It''s only drawing over the invalid rectangle, but it''s still drawing over the window(s) on top of the program. Is there a way to tell my program not to redraw over the applications on top of it? This is the last bug to my program to fix before I move on to my next project, but I can''t leave a problem like this alone if it can be helped.
It''s been a while since I''ve worked with DX, but I think WM_PAINT is called even if your window is deactivated. You can fix this by tracking your window''s active state like so:
Of course, I could also be FOS
// Global variablebool g_active = false;// In your window procedure''s message switchcase WM_ACTIVATE: g_active = (LOWORD(wParam) == WA_INACTIVE) ? (false) : (true); break;case WM_PAINT: if (g_active) { // Draw stuff... } return 0;
Of course, I could also be FOS
The problem isn't that the program is writing to the window, it's that it's writing to the window even if it means overwriting other applications. If I do not have my program process the WM_PAINT message then each time a window is moved over it and then moved off it, there will be a blank area of the window.
Why? Because Windows isn't recognizing the graphics placed upon my window (using a Primary Surface) and draws with only the background brush.
There are three options I can think of doing, but I'm not sure how to implememnt them. I can either use GDI for all my graphics (ick), make Windows recognize the graphics I use on the Primary Surface, or lastly, I can find out the Window Rectangular coordinates of the window moved just before my program receives the WM_PAINT message.
[edited by - Obsidian Kindragon on September 29, 2002 8:14:14 AM]
Why? Because Windows isn't recognizing the graphics placed upon my window (using a Primary Surface) and draws with only the background brush.
There are three options I can think of doing, but I'm not sure how to implememnt them. I can either use GDI for all my graphics (ick), make Windows recognize the graphics I use on the Primary Surface, or lastly, I can find out the Window Rectangular coordinates of the window moved just before my program receives the WM_PAINT message.
[edited by - Obsidian Kindragon on September 29, 2002 8:14:14 AM]
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement