Managing the Device Context

In 16-bit Windows, it was important to conserve the use of drawing objects. In Windows NT, there are richer data structures to hold a new wealth of data. That can mean it takes longer to look things up.

The old limitations gave rise to a coding style in which you created, selected, used, and destroyed objects (like pens and brushes) constantly. This limited the number of objects in the system and kept the application from running into the limits of the address space. Because of the transition to a client-server architecture in Windows NT, object creation and destruction are more expensive. Because of the new capacity for large numbers of objects, selecting objects is also a bit slower. For example, the old coding style

select(grey); 
patblt(...); 
select(black); 
patblt(...); 
select(grey); 
patblt(...); 
select(black); 
patblt(...); 
 

is slower on Windows NT than

select(grey); 
patblt(...); 
patblt(...); 
patblt(...); 
select(black); 
patblt(...); 
patblt(...); 
patblt(...); 
 

In Windows NT, create all your objects when you first need them. Do not destroy the objects until you are done with them.

If you were programming for 16-bit Windows, you were told to avoid the use of your own DC’s because the system could only support a few. This is not true on Windows NT. Use the creation style CS_OWNDC as much as you can when you call the RegisterClass function. This avoids repeated calling of the relatively expensive GetDC and ReleaseDC functions every time you have to draw. It also preserves the selected objects in your own DC in between calls, eliminating the need to select them again after each call to GetDC.