Showing tag results for Code

Dec 8, 2006
Post comments count0
Post likes count0

Do not overload the E_NOINTERFACE error

Raymond Chen
Raymond Chen

One of the more subtle ways people mess up is returning when the problem wasn't actually an unsupported interface. The return value has very specific meaning. Do not use it as your generic "gosh, something went wrong" error. (Use an appropriate error such as or .) Recall that the rules for are that (in the absence of catastrophic errors such...

Code
Dec 4, 2006
Post comments count0
Post likes count0

The name WinMain is just a convention

Raymond Chen
Raymond Chen

Although the function is documented in the Platform SDK, it's not really part of the platform. Rather, is the conventional name for the user-provided entry point to a Windows program. The real entry point is in the C runtime library, which initializes the runtime, runs global constructors, and then calls your function (or if you prefer a...

Code
Nov 28, 2006
Post comments count0
Post likes count0

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

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