Showing tag results for Code

Nov 28, 2006
Post comments count0
Post likes count1

What went wrong in Windows 95 if you use a system color brush as your background brush?

Raymond Chen

If you want to register a window class and use a system color as its background color, you set the member to the desired color, plus one, cast to an : Windows 95 introduced "system color brushes", which are a magic type of brush which always paint in the corresponding system color, even if the system color changes. The brush will alwa...

CodeHistory
Nov 20, 2006
Post comments count0
Post likes count1

It takes only one program to foul an upgrade

Raymond Chen

"Worst software ever." That was Aaron Zupancic's cousin's reaction to the fact that Windows XP was incompatible with one program originally designed for Windows 98. Then again, commenter Aargh! says "The bad code should be fixed, period. If it can't be fixed, it breaks, too bad." Perhaps Aargh! can send a message to Aaron's cousin sa...

Code
Nov 16, 2006
Post comments count0
Post likes count0

Using DIB sections to perform bulk color mapping

Raymond Chen

When doing dithering, one operation you have to do for every pixel is map it (more accurately, map a modified version of it) to the nearest color in your available palette. Since this is part of the dithering inner loop, you need this operation to be as fast as possible.¹ A common technique for this is to precompute the nearest palette index ...

Code
Nov 15, 2006
Post comments count0
Post likes count1

Manipulating the DIB color table for fun and profit

Raymond Chen

If you create a DIB section at 8bpp or lower, then it will come with a color table. Pixels in the bitmap are represented not by their red/blue/green component values, but are instead indices into the color table. For example, a 4bpp DIB section can have up to sixteen colors in its color table. Although displays that use 8bpp or lower are conside...

Code
Nov 14, 2006
Post comments count0
Post likes count1

Blitting between color and monochrome DCs

Raymond Chen

When blitting between color and monochrome DCs, The text foreground and background colors play a role. We saw earlier that when blitting from a monochrome DC to a color DC, the color black in the source turns into the destination's text color, and the color white in the source turns into the destination's background color. This came in handy when...

Code
Nov 13, 2006
Post comments count0
Post likes count1

What do bitwise operations mean for colors?

Raymond Chen

Someday, you're going to pass a raster operation to the function that entails bit manipulation. Something like perhaps, or possibly the dreaded . These bitwise operations make perfect sense for monochrome bitmaps, since those are one bit per pixel anyway. But what does it mean for color bitmaps? What do you get when you "and" together forest gree...

Code
Nov 10, 2006
Post comments count0
Post likes count1

Converting an HRESULT to a Win32 error code: Diagram and answer to exercise

Raymond Chen

Here's the diagram from How do I convert an HRESULT to a Win32 error code?. If you are offended by VML, cover your ears and hum for a while. The little sliver at the top is the mapping of zero to zero. The big white box at the bottom is the mapping of all negative numbers to corresponding negative numbers. And the rainbow represents the mapp...

Code
Nov 3, 2006
Post comments count0
Post likes count4

How do I convert an HRESULT to a Win32 error code?

Raymond Chen

Everybody knows that you can use the macro to convert a Win32 error code to an , but how do you do the reverse? Let's look at the definition of : If the value is less than or equal to zero, then the macro returns the value unchanged. Otherwise, it takes the lower sixteen bits and combines them with and . How do you reverse this process? H...

Code