Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8442511
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T08:51:46+00:00 2026-06-10T08:51:46+00:00

MSDN and numerous post have suggested that BeginPaint/EndPaint should used in WM_PAINT. I’ve also

  • 0

MSDN and numerous post have suggested that BeginPaint/EndPaint should used in WM_PAINT. I’ve also seen numerous places suggesting that if double buffering is employed in painting, it makes more sense to initialize the DC and mem allocation in WM_CREATE and reuse those handles in WM_PAINT.

For example, using BeginPaint, I commonly see:

case WM_PAINT:
hdc = BeginPaint(hWnd, &ps);
MemDC = CreateCompatibleDC(hdc);
bmp = CreateCompatibleBitmap(hdc, width, height);
oldbmp = SelectObject(MemDC,bmp);
g = new Graphics(MemDC);

//do paint on bmp
//blt bmp back to hdc

EndPaint(hWnd, &ps);
DeleteObject(bmp);
g->ReleaseHDC(MemDC);
DeleteDC(MemDC);
delete g;

To save the initialization and tearing down, is it possible to do this :

case WM_CREATE:
hdc   = GetDC(hWnd);
//create memDC and graphics object references ...
case WM_DESTROY
//delete memDC and graphics object references...
case WM_PAINT
BeginPaint(hWnd, &ps);
//use previously create mem and graphics object to paint 
EndPaint(hWnd, &ps);

So we only use EndPaint to clear the update region but delegate the drawing to prev created objects.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T08:51:48+00:00Added an answer on June 10, 2026 at 8:51 am

    No, that’s a very poor practice. This goes wrong first by the device context having the wrong clipping region, you cannot properly paint the window when the user resizes the window.

    Second problem is that the update region clipping won’t be in effect, PAINTSTRUCT.rcPaint. Preventing any possible paint optimization that Windows may automatically perform when the update region is just a part of the window.

    Third problem is that you are holding on an operating system resource needlessly. All GDI objects are allocated in a single heap that’s shared by all processes that run on the same desktop.

    Creating a HDC is very cheap, create it when you need it. Not to mention the PAINTSTRUCT.hdc you’ll get served on a platter, ready to use.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

MSDN advises that RegisterWindowMessage() function is only used for registering messages to be sent
MSDN says that you should use structs when you need lightweight objects. Are there
MSDN says that the function SetDllDirectory() can be used to insert a directory into
MSDN says : swap should be used in preference to iter_swap , which was
MSDN states that String.Intern retrieves the system's reference to the specified String and String.IsInterned
MSDN docs say that only value types need boxing, but this does not apply
MSDN says that public static members of System.Windows.Application are thread safe. But when I
From MSDN doc : A delegate is a type that safely encapsulates a method,
According MSDN, FxCop is an application that analyzes managed code assemblies (code that targets
MSDN states of the property TypeId that: As implemented, this identifier is merely the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.