BeginPaint and GetDC called in succession

This is a discussion on BeginPaint and GetDC called in succession within the Windows Programming forums, part of the Platform Specific Boards category; I have seen sample code like the following in handling a WM_PAINT message: Code: BeginPaint(hwnd,&ps); hdc = GetDC(hwnd); ....draw stuff... ...

  1. #1
    jasondoucette.com JasonD's Avatar
    Join Date
    Mar 2003
    Posts
    278

    BeginPaint and GetDC called in succession

    I have seen sample code like the following in handling a WM_PAINT message:
    Code:
    	BeginPaint(hwnd,&ps);
    	hdc = GetDC(hwnd);
    
    	....draw stuff...
    
    	ReleaseDC(hwnd,hdc);
    	EndPaint(hwnd,&ps);
    I assume that, although it works, it is not really correct, since BeginPaint gets the DC anyway, and EndPaint releases it. Am I correct?

  2. #2
    Cat
    Cat is offline
    Registered User
    Join Date
    May 2003
    Posts
    1,571
    Yes, you are.

    They should be doing this:

    Code:
    hdc = BeginPaint(hwnd,&ps);
    
    ....draw stuff...
    
    EndPaint(hwnd,&ps);
    Last edited by Cat; 05-23-2003 at 10:15 AM.

  3. #3
    jasondoucette.com JasonD's Avatar
    Join Date
    Mar 2003
    Posts
    278
    Thanks for the reply.

    That's what I thought, and just wanted confirmation. The code you posted above is exactly what I use.

Popular pages Recent additions subscribe to a feed

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21