Thread: BeginPaint and GetDC called in succession

  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
    Registered User
    Join Date
    May 2003
    Posts
    1,619
    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