Showing tag results for Code

May 10, 2004
Post comments count0
Post likes count0

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, fo...

Code
May 7, 2004
Post comments count0
Post likes count0

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 implem...

Code
May 3, 2004
Post comments count0
Post likes count0

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 r...

Code
Apr 28, 2004
Post comments count0
Post likes count0

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 co...

Code
Apr 23, 2004
Post comments count0
Post likes count0

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
Post comments count0
Post likes count0

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 GenerateDatab...

Code
Apr 21, 2004
Post comments count0
Post likes count0

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 progra...

Code
Apr 19, 2004
Post comments count0
Post likes count0

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
Post comments count0
Post likes count0

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 exp...

Code
Apr 14, 2004
Post comments count0
Post likes count1

Not all short filenames contain a tilde

Raymond Chen
Raymond Chen

I'm sure everybody has seen the autogenerated short names for long file names. For the long name "Long name for file.txt", you might get "LONGNA~1.TXT" or possibly "LO18C9~1.TXT" if there are a lot of collisions. What you may not know is that sometimes there is no tilde at all! Each filesystem decides how it wants to implement short filenam...

Code