Showing results for Code - The Old New Thing

May 11, 2004
0
0

How do the FILE_SHARE_* bits interact with the desired access bits?

Raymond Chen
Raymond Chen

It's really not that complicated. If you permit, say, , then you're saying, "I'm okay with other people reading this file while I have it open." And if you leave off the flag, then you're saying, "I do not want other people reading this file while I have it open." Now all that's left to do is work out what that means. So suppose you omit ...

Code
May 10, 2004
0
0

There are two types of scrollbars

Raymond Chen
Raymond Chen

Remember that there are two types of scrollbars. One is the standalone scrollbar control. This one has its own window handle, and consequently can be given focus and all those other fun things you can do with window handles. To manipulate them, pass the handle to the scrollbar control to the appropriate scrollbar function (SetScrollInfo, ...

Code
May 7, 2004
0
0

When should your destructor be virtual?

Raymond Chen
Raymond Chen

When should your C++ object's destructor be virtual? First of all, what does it mean to have a virtual destructor? Well, what does it mean to have a virtual method? If a method is virtual, then calling the method on an object always invokes the method as implemented by the most heavily derived class. If the method is not virtual, then the ...

Code
May 3, 2004
0
0

Why does my hard drive light flash every few second?

Raymond Chen
Raymond Chen

Back in Windows 95, people would notice that their hard drive light would blink every few seconds. What's that all about? Actually, it wasn't the hard drive light after all. Windows 95 was polling your CD-ROM drive to see whether you had inserted a new CD. Some computers wired up the "hard drive light" not to the hard drive but ...

Code
Apr 28, 2004
0
0

What is __purecall?

Raymond Chen
Raymond Chen

Both C++ and C# have the concept of virtual functions. These are functions which always invoke the most heavily derived implementation, even if called from a pointer to the base class. However, the two languages differ on the semantics of virtual functions during object construction and destruction. C# objects exist as their final type before ...

Code
Apr 23, 2004
0
0

How to retrieve text under the cursor (mouse pointer)

Raymond Chen
Raymond Chen

Microsoft Active Accessibilty is the technology that exposes information about objects on the screen to accessibility aids such as screen readers. But that doesn't mean that only screen readers can use it. Here's a program that illustrates the use of Active Accessibility at the most rudimentary level: Reading text. There's much more to Active ...

Code
Apr 22, 2004
0
0

Cleaner, more elegant, and wrong

Raymond Chen
Raymond Chen

Just because you can't see the error path doesn't mean it doesn't exist. Here's a snippet from a book on C# programming, taken from the chapter on how great exceptions are. Notice how much cleaner and more elegant [this] solution is. Cleaner, more elegant, and wrong. Suppose an exception is thrown during CreateIndexes(). The ...

Code
Apr 21, 2004
0
0

Why the compiler can’t autoconvert foreach to for

Raymond Chen
Raymond Chen

People have discovered that the "natural" C# loop construct is fractionally slower than the corresponding manual loop: The first thing that needs to be said here is that The performance difference is almost certainly insignificant. Don't go running around changing all your foreach loops into corresponding for loops thinking that your ...

Code
Apr 19, 2004
0
0

WM_KILLFOCUS is the wrong time to do field validation

Raymond Chen
Raymond Chen

"I'll do my field validation when I get a WM_KILLFOCUS message." This is wrong for multiple reasons. First, you may not get your focus loss message until it's too late. Consider a dialog box with an edit control and an OK button. The edit control validates its contents on receipt of the WM_KILLFOCUS message. Suppose the user fills in some ...

Code
Apr 16, 2004
0
0

Mapping all those "strange" digits to "0" through "9"

Raymond Chen
Raymond Chen

In an earlier article, I discussed how the Char.IsDigit() method and its Win32 counterpart, GetStringTypeEx report things to be digits that aren't just "0" through "9". If you really care just about "0" through "9", then you can test for them explicitly. For example, as a regular expression, use [0-9] instead of \d. Alternatively, for a regular ...

Code