Thread: BeginPaint() & EndPaint();

  1. #1
    Registered User
    Join Date
    Feb 2002
    Posts
    93

    BeginPaint() & EndPaint();

    i'm a bit confused on this subject.. can anyone give me a quick explanation of this? so an idiot like myself can understand it....

    in message WM_PAINT:

    i always notice that all code is inside of BeginPaint() & EndPaint();

    but if i remove these functions the program still seems to run the same..... are these necessary? and why are they always used?
    i notice it stores something in a Paintstruct (i don't know what this is) but the paintstruct is never used again... what exactly is stored in the paintstruct?

    thnx in advance...

  2. #2
    Registered User
    Join Date
    Jan 2002
    Posts
    387
    i remember when i didnt have BeginPaint and EndPaint in, it wouldnt allow me to process Keyboard input..
    "There are three kinds of people in the world...
    Those that can count and those that can't."

  3. #3
    tegwin7531
    Guest
    oh ok.. guess i better start using it then.... thnx

  4. #4
    Registered User
    Join Date
    May 2002
    Posts
    317
    PAINSTRUCT is defined as follows:
    Code:
    typedef struct tagPAINTSTRUCT
    {
               HDC hdc;  //handle to device context
               BOOL fErase; //flag to indicate whether the backround was painted
               RECT rcPaint; //rectangle of invalid region
               BOOL fRestore;  /* reserved 
               BOOL fIncUpdate;           for windows
               BYTE rgbReserved[32];      internal use  */
    }PAINTSTRUCT;
    By calling BeginPaint(hdc, &ps) you:
    1) Validate the client area
    2) Windows returns a handle to the device context
    3) Fill in the areas of PAINTSRUCT

    Now if youd don't call BeginPaint on WM_PAINT and you don't validate the client area with ValidateRect windows will keep sending a WM_PAINT message and totally screw up your program flow. EndPaint will release the device context 'hdc' that you created with BeginPaint.

  5. #5
    Registered User
    Join Date
    Feb 2002
    Posts
    93
    Ah much appreciated... i get it now thnx

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Need some more assistance
    By Thantos in forum Windows Programming
    Replies: 6
    Last Post: 08-14-2003, 12:13 PM
  2. BeginPaint and GetDC called in succession
    By JasonD in forum Windows Programming
    Replies: 2
    Last Post: 05-23-2003, 12:06 PM
  3. another question on BeginPaint()
    By nextus in forum Windows Programming
    Replies: 2
    Last Post: 03-09-2003, 01:43 PM
  4. BeginPaint()
    By nextus in forum Windows Programming
    Replies: 4
    Last Post: 03-09-2003, 12:10 AM