Showing tag results for Code

Nov 20, 2006
Post comments count0
Post likes count0

It takes only one program to foul an upgrade

Raymond Chen
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
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
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
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 count0

What do bitwise operations mean for colors?

Raymond Chen
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 count0

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

Raymond Chen
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 count3

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

Raymond Chen
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
Nov 2, 2006
Post comments count0
Post likes count0

Make sure you disable the correct window for modal UI

Raymond Chen
Raymond Chen

Some time ago, I was asked to look at two independent problems with people trying to do modal UI manually. Well, actually, when the issues were presented to me, they weren't described in quite that way. They were more along the lines of, "Something strange is happening in our UI. Can you help?" Only in the discussion of the scenarios did it become...

Code