Advertisement

meet trouble with ps.fErase and Petzold

Started by March 09, 2001 12:58 AM
4 comments, last by ed9er 23 years, 11 months ago
i'm a beginer with win32 gdi, i read "programming windows" now, thus i meet this question: quote from petzold's book : "However, if your program invalidates a rectangle of the client area by calling InvalidateRect, the last argument of the function specifies whether you want the background erased. If this argument is FALSE (that is, 0), Windows will not erase the background and the fErase field of the PAINTSTRUCT structure will be TRUE (nonzero) after you call BeginPaint." my code :
    
case WM_LBUTTONDOWN:
     hdc = GetDC(hwnd);
     TextOut(hdc, 10, 50, "a", 1);
     ReleaseDC(hwnd, hdc);
     InvalidateRect(hwnd, NULL, FALSE);
     return 0;
case WM_PAINT:
     hdc = BeginPaint(hwnd, &ps);
     if (ps.fErase) 
       TextOut(hdc, 10, 10, "b", 1);
     EndPaint(hwnd, &ps);
     return 0;
case WM_DESTROY:
     PostQuitMessage (0) ;
     return 0 ;
default :
     return DefWindowProc (hwnd, message, wParam, lParam) ;
    
the result after i click mouse is there's a 'a' in the window, but no 'b', i think it's make sense that the 'a' is still on the screen since i give FALSE when i call InvalidateRect, but why there's no 'b'? it just means ps.fErase is FALSE, and it means the P - e - t - z - o - l - d is wrong ..... am i miss anything? Edited by - ed9er on March 9, 2001 2:00:51 AM
------------------------------------------------------CCP is fascistic, they even banned www.sourceforge.net
Are you listening to yourself?

quote:

the result after i click mouse is there''s a ''a'' in the window, but no ''b'', i think it''s make sense that the ''a'' is still on the screen since i give FALSE when i call InvalidateRect, but why there''s no ''b''? it just means ps.fErase is FALSE, and it means the P - e - t - z - o - l - d is wrong ..... am i miss anything?



You say that sending in FALSE sets ps.fErase to FALSE, right? And I assume you want ''b'' to draw when you send in false, right? But in your code:

    ...  case WM_PAINT:     ...     if (ps.fErase) // NOTE THIS        TextOut(hdc, 10, 10, "b", 1);     ...  


You draw ''b'' only when TRUE is sent--so it won''t draw when FALSE is sent. Correct me is I''m interpreting your question wrong.

Jinushaun
Advertisement
i'm sure that you have not read the quote at the beginning

or maybe my english sux ...

Edited by - ed9er on March 9, 2001 3:12:18 AM
------------------------------------------------------CCP is fascistic, they even banned www.sourceforge.net
Look up PAINTSTRUCT in the MSDN docs. You''ll see that fErase will be a non-zero value (i.e. TRUE) when the background needs to be erased. It will be FALSE otherwise. It''s probably a printing error in the book. Go email Charles and tell him about it
==========================================In a team, you either lead, follow or GET OUT OF THE WAY.
Actually, the msdn says that the fErase is TRUE when the application is responsible to clear the background. It also says that this is when the window has been created with no background brush. So it''s not just a printing error, it''s a conceptual error on Petzold''s behalf.
ya! these confirms just what i need.... thx guys!
any more comments?
------------------------------------------------------CCP is fascistic, they even banned www.sourceforge.net

This topic is closed to new replies.

Advertisement