Showing results for Code - The Old New Thing

Sep 30, 2010
Post comments count0
Post likes count0

Why doesn't the TAB key work on controls I've marked as WS_TABSTOP?

Raymond Chen
Raymond Chen

A customer had a programming problem regarding tab stops: I create a parent window (child of main frame) as below This window hosts 2 toolbar windows. Each toolbar window has the style set using . MSDN states WS_EX_CONTROLPARENT Allows the user to navigate among the child windows of the window by using the TAB key. But I am not able ...

Code
Sep 24, 2010
Post comments count0
Post likes count0

How reliable is the BatteryLifePercent member of the SYSTEM_POWER_STATUS structure?

Raymond Chen
Raymond Chen

A customer was writing a program that called and used the value. The customer wanted to know whether a reported battery life percentage of 38% really means that the remaining battery life is between 37.5% and 38.5%. Although the value is reported to 1% precision, the accuracy in practice is much worse. Similarly, the is reported in seconds, bu...

Code
Sep 23, 2010
Post comments count0
Post likes count0

You must flush GDI operations when switching between direct access and GDI access, and direct access includes other parts of GDI

Raymond Chen
Raymond Chen

A customer was running into problems when accessing the pixels of a DIB section. They used the parameter to and created two bitmaps from the same underlying memory. Those two bitmaps were then selected into corresponding DCs, and the customer found that changes to the pixels performed by writing via one DC were not visible when read from the oth...

Code
Sep 20, 2010
Post comments count0
Post likes count0

How do I get the dropped height of a combo box?

Raymond Chen
Raymond Chen

Via the Suggestion Box, commenter Twisted Combo responds to an old blog entry on why the size of a combo box includes the height of the drop-down by asking, But how do I *get* the dropped down height?" By using the deviously-named message, which the header file wraps inside the macro. Start with the scratch program and make these changes:...

Code
Sep 17, 2010
Post comments count0
Post likes count0

What's up with the strange treatment of quotation marks and backslashes by CommandLineToArgvW

Raymond Chen
Raymond Chen

The way the function treats quotation marks and backslashes has raised eyebrows at times. Let's look at the problem space, and then see what algorithm would work. Here are some sample command lines and what you presumably want them to be parsed as: In the first example, we want quotation marks to protect spaces. In the second example, we want ...

Code
Sep 16, 2010
Post comments count0
Post likes count0

How is the CommandLineToArgvW function intended to be used?

Raymond Chen
Raymond Chen

The function does some basic command line parsing. A customer reported that it was producing strange results when you passed an empty string as the first parameter: Well, okay, yeah, but huh? The first parameter to is supposed to be the value returned by . That's the command line, and that's what was designed to parse. If you pass somethin...

Code
Sep 10, 2010
Post comments count0
Post likes count1

Hey there token, long time no see! (Did you do something with your hair?)

Raymond Chen
Raymond Chen

Consider a system where you have a lot of secured objects, and suppose further that checking whether a user has access to an object is a slow operation. This is not as rare as you might think: Even though a single access check against a security descriptor with a small number of ACEs might be fast, you can have objects with complicated security des...

Code
Sep 9, 2010
Post comments count0
Post likes count0

Flushing your performance down the drain, that is

Raymond Chen
Raymond Chen

Some time ago, Larry Osterman discussed the severe performance consequences of flushing the registry, which is a specific case of the more general performance catch: Flushing anything will cost you dearly. A while back, I discussed the high cost of the "commit" function, and all the flush-type operations turn into a commit at the end of the day...

Code
Sep 3, 2010
Post comments count0
Post likes count0

What happens to a named object when all handles to it are closed?

Raymond Chen
Raymond Chen

A customer had a question about named kernel objects: I understand that handles in a process if leaked will be destroyed by the kernel when the process exits. My question would be around named objects. Would named objects hold their value indefinitely? If I run a small utility app to increment a named counting semaphore, the count of that named...

Code