Showing tag results for Code

Jan 16, 2008
Post comments count0
Post likes count1

Use WM_WINDOWPOSCHANGING to intercept window state changes

Raymond Chen
Raymond Chen

The message is sent early in the window state changing process, unlike , which tells you about what already happened. A crucial difference (aside from the timing) is that you can influence the state change by handling the message and modifying the structure. Here's an example that prevents the window from being resized. Before the message...

Code
Jan 15, 2008
Post comments count0
Post likes count1

Use WM_WINDOWPOSCHANGED to react to window state changes

Raymond Chen
Raymond Chen

The documentation for the message points out that the message is not sent under certain circumstances. But what if you want to know when the window is shown, including in the cases where you don't get ? The message is sent at the end of the window state change process. It sort of combines the other state change notifications, , , and . But it ...

Code
Jan 8, 2008
Post comments count0
Post likes count1

Generating initials from a name is trickier than you think

Raymond Chen
Raymond Chen

Even though I'm signed in, the page claims that anonymous comments are not allowed, so I'm reduced to posting my comment here and generating a trackback. Some time ago, Robert McLaws wrote a function that generates initials from a name. Let's set aside completely the issue of non-U.S. names; the function doesn't even handle U.S. names correctly. ...

Code
Jan 8, 2008
Post comments count0
Post likes count1

Taxes: Files larger than 4GB

Raymond Chen
Raymond Chen

Nowadays, a hard drive less than 20 gigabytes is laughably small, but it used to be that the capacity of a hard drive was measured in megabytes, not gigabytes. Today, video files and databases can run to multiple gigabytes in size, and your programs need be prepared for them. This means that you need to use 64-bit file offsets such as those used b...

Code
Jan 7, 2008
Post comments count0
Post likes count1

Clean-up functions can't fail because, well, how do you clean up from a failed clean-up?

Raymond Chen
Raymond Chen

Commenter Matt asks how you're supposed to handle failures in functions like or . Obviously, you can't. If a clean-up function fails, there's not much you can do because, well, how do you clean up from a failed clean-up? These clean-up functions fall into the category of "Must not fail for reasons beyond the program's control." If a program trie...

Code
Jan 4, 2008
Post comments count0
Post likes count1

What does it mean when a display change is temporary?

Raymond Chen
Raymond Chen

When you call the function, you can pass the flag to indicate that the change is temporary. But if you don't also save the changes in the registry, how can they be permanent? What does temporary mean? A temporary display change is one that your program has entered because it has gone into a fullscreen mode, a change which it will undo when it re...

Code
Jan 2, 2008
Post comments count0
Post likes count1

You know the answer: Window destruction

Raymond Chen
Raymond Chen

The following request for assistance came in from a customer, and given what you know about window destruction, you should eventually be able to figure it out yourself once all the pieces are in place, though it takes some time for all the clues to be revealed. We are hitting this exception in our program. This is urgent; please give it priorit...

Code
Dec 27, 2007
Post comments count0
Post likes count1

If you need anything other than natural alignment, you have to ask for it

Raymond Chen
Raymond Chen

If you need variables to be aligned a particular way, you need to ask for it. Let's say I have the following code: What would the alignment of the starting adresses of a,b,c and d be? What would the alignment be if the memory were allocated on heap? If this alignment varies for different data types within the same translation unit, is th...

Code
Dec 20, 2007
Post comments count0
Post likes count1

Consequences of the scheduling algorithm: Low priority threads can take 100% CPU

Raymond Chen
Raymond Chen

I see variations on this question occasionally. "Why is my low priority thread consuming 100% CPU?" Setting a thread to low priority doesn't mean that it won't consume lots of CPU. It just means that it doesn't get to run as long as there is a higher-priority thread ready to run. But if there is a CPU looking for something to do, and there is no h...

Code
Dec 19, 2007
Post comments count0
Post likes count1

How do I mark a shortcut file as requiring elevation?

Raymond Chen
Raymond Chen

Specifying whether elevation is required is typically something that is the responsibility of the program. This is done by adding a element to your manifest. (Bart De Smet shows you how. Calvin Hsia does the same for your Visual FoxPro programs.) But if the program you're running doesn't have such a manifest—maybe it's an old program that...

Code