Showing tag results for Code

Jun 14, 2006
Post comments count0
Post likes count0

Pitfalls of transparent rendering of anti-aliased fonts

Raymond Chen
Raymond Chen

Windows provides a variety of technologies for rendering monochrome text on color displays, taking advantage of display characteristics to provide smoother results. These include grayscale anti-aliasing as well as the more advanced ClearType technique. Both of these methods read from the background pixels to decide what pixels to draw in the fore...

Code
Jun 12, 2006
Post comments count0
Post likes count0

Remember what happens when you broadcast a message

Raymond Chen
Raymond Chen

Occasionally I catch people doing things like broadcasting a message to all top-level windows. This is one of those things that is so obviously wrong I don't see how people even thought to try it in the first place. Suppose you broadcast the message What happens? Every top-level window receives the message with the same parameters, and eve...

Code
Jun 8, 2006
Post comments count0
Post likes count0

The forgotten common controls: The MenuHelp function

Raymond Chen
Raymond Chen

The function is one of the more confusing ones in the common controls library. Fortunately, you will almost certainly never had need to use it, and once you learn the history of the function, you won't want to use it anyway. Our story begins with 16-bit Windows. The message is sent to notify a window of changes in the selection state of a men...

Code
Jun 7, 2006
Post comments count0
Post likes count0

If you're going to try to simulate user actions, make sure the user can do them

Raymond Chen
Raymond Chen

Many people like to simulate user actions programmatically. I'm not going to comment here on whether that's a good idea to begin with; what I want to point out is that if you're going to do it, you have to make sure you're simulating things the user can actually do. For example, if you want to act as if the user clicked the "close" button in the ...

Code
Jun 5, 2006
Post comments count0
Post likes count0

Why can't you say </script> in a script block?

Raymond Chen
Raymond Chen

Because it ends the script block, of course. Duh, what's so hard about that? Because if you have script that generates script, you'll find yourself caught out if you're not careful. For example, you can't say in a script block because the HTML parser will see the and conclude that your script block is over. In other words, the script block ...

Code
Jun 2, 2006
Post comments count0
Post likes count0

What does the CS_CLASSDC class style do?

Raymond Chen
Raymond Chen

Last time, I talked about the historical background for the class style and why it starts out sounding like a good idea but when you think about it some more turns out to be an awful idea. The class style is the same thing, but worse, for it takes all the problems of and magnifies them. Recall that the class style instructs the window manage...

CodeHistory
Jun 1, 2006
Post comments count0
Post likes count1

What does the CS_OWNDC class style do?

Raymond Chen
Raymond Chen

Recall that window DCs are most commonly used only temporarily. If you need to draw into a window, you call or, if outside of a paint cycle, , although painting outside of a paint cycle is generally to be avoided. The window manager produces a DC for the window and returns it. You use the DC, then restore it to its original state and return it to...

CodeHistory
May 24, 2006
Post comments count0
Post likes count0

Beware the C++ implicit conversion

Raymond Chen
Raymond Chen

Today's topic was inspired by a question from a customer: I am working on a stack overflow bug. To reduce the size of the stack frame, I removed as many local variables as I could, but there's still a a lot of stack space that I can't account for. What else lives on the stack aside from local variables, parameters, saved registers, and the retur...

Code
May 22, 2006
Post comments count0
Post likes count1

How do I write a regular expression that matches an IPv4 dotted address?

Raymond Chen
Raymond Chen

Writing a regular expression that matches an IPv4 dotted address is either easy or hard, depending on how good a job you want to do. In fact, to make things easier, let's match only the decimal dotted notation, leaving out the hexadecimal variant, as well as the non-dotted variants. For the purpose of this discussion, I'll restrict myself to the...

Code
May 19, 2006
Post comments count0
Post likes count0

Redirecting output can result in altered program behavior

Raymond Chen
Raymond Chen

Consider a program whose output to the console goes like this. (I've prefixed each line with the output stream.) You want to capture both the normal and error streams, so you run the program and append "" to capture both streams into a single file. But when you look at the resulting output file, you get this: What happened? Most programs c...

Code