Showing tag results for Code

Sep 7, 2005
Post comments count0
Post likes count0

Why aren’t low-level hooks injected?

Raymond Chen
Raymond Chen

When I described what the HINSTANCE parameter to the function is for, I neglected to mention why the low-level hooks are not injected. But then again, it should be obvious. The low-level hooks let you see input as it arrives at the window manager. At this low level of processing, the window manager hasn't yet decided what window will receive...

Code
Sep 1, 2005
Post comments count0
Post likes count0

More undocumented behavior and the people who rely on it: Output buffers

Raymond Chen
Raymond Chen

For functions that return data, the contents of the output buffer if the function fails are typically left unspecified. If the function fails, callers should assume nothing about the contents. But that doesn't stop them from assuming it anyway. I was reminded of this topic after reading Michael Kaplan's story of one customer who wanted the ou...

Code
Aug 31, 2005
Post comments count0
Post likes count0

Understanding hash codes

Raymond Chen
Raymond Chen

On more than one occasion, I've seen someone ask a question like this: I have some procedure that generates strings dynamically, and I want a formula that takes a string and produces a small unique identifer for that string (a hash code), such that two identical strings have the same identifier, and that if two strings are different, then they wi...

Code
Aug 30, 2005
Post comments count0
Post likes count0

Program names in file type handlers need to be fully-qualified

Raymond Chen
Raymond Chen

Most people probably haven't noticed this, but there was a change to the requirements for file type handlers that arrived with Windows XP SP 2: Paths to programs now must be fully-qualified if they reside in a directory outside of the Windows directory and the System directory. The reason for this is security with a touch of predictabil...

Code
Aug 17, 2005
Post comments count0
Post likes count0

Why is processor affinity inherited by child processes?

Raymond Chen
Raymond Chen

Consider why a typical program launches child processes. (Shell programs like Explorer aren't typical.) It's because the task at hand is being broken down into sub-tasks which for whatever reason has been placed into a child process. An Example of this would be, say, a multi-pass compiler/linker, where each pass is implemented as a separate proces...

Code
Aug 15, 2005
Post comments count0
Post likes count0

The poor man’s way of identifying memory leaks

Raymond Chen
Raymond Chen

There is a variety of tools available for identifying resource leaks, but there's one method that requires no tools or special compiler switches or support libraries: Just let the leak continue until the source becomes blatantly obvious. Nightly automated stress testing is a regular part of any project. Some teams use screen savers as the trigger...

Code
Aug 12, 2005
Post comments count0
Post likes count0

Adding a lookup control to the dictionary: Searching Pinyin

Raymond Chen
Raymond Chen

Finally we start searching. For now, the search algorithm is going to be very simple: The string you type into the edit control will be treated as the start of a Pinyin word or phrase. We'll make it fancier later. Here is where a lot of the groundwork (some of which I called out explicitly and some of which I slipped in without calling attention...

Code
Aug 11, 2005
Post comments count0
Post likes count0

Adding a lookup control to the dictionary: Just getting it on the screen

Raymond Chen
Raymond Chen

When we last left the dictionary project, we were able to display the dictionary entries but hadn't yet gotten around to searching it. Today, we'll place the lookup control, though we won't hook it up until next time. First, we give the edit control an ID and create some member variables to keep track of it. class RootWindow : public Window { ...

Code
Aug 9, 2005
Post comments count0
Post likes count0

The dangers of messing with activation when handling a WM_ACTIVATE message

Raymond Chen
Raymond Chen

This is basically the same thing as The dangers of playing focus games when handling a WM_KILLFOCUS message, just with activation in place of focus. One developer discovered the hard way that if you mess with activation inside your WM_ACTIVATE handler, things get weird. The author noted that if he posted a message and did the work from the posted...

Code
Aug 8, 2005
Post comments count0
Post likes count0

The dangers of playing focus games when handling a WM_KILLFOCUS message

Raymond Chen
Raymond Chen

I had noted last year that WM_KILLFOCUS is the wrong time to do field validation. Here's another example of how messing with the focus during a WM_KILLFOCUS message can create confusion. Consider an edit control that displays feedback via a balloon tip. For example, password edit controls often warn you if you're typing your password while Caps...

Code