The Old New Thing
Practical development throughout the evolution of Windows.
Latest posts
The relationship between module resources and resource-derived objects in 16-bit Windows
As we saw last time, in 16-bit Windows, resources attached to an EXE or DLL file (which I called module resources for lack of a better term) were recorded in memory as discardable global memory blocks, and the window manager accessed them directly as needed. For example, if you had an icon or a cursor, the or was really a resource handle, and when the window manager needed to draw the icon or cursor, it would cast the icon or cursor handle to a global handle (since that's what it was under the hood), then call to access the raw resource data in order to copy the pixels onto the screen. Similarly, accelerator...
The management of memory for resources in 16-bit Windows, redux
Some time ago, I briefly ran down how 16-bit Windows managed memory for resources. But there's a detail that I neglected to mention: Ownership. As we saw, a resource handle was really a pointer to the resource directory entry of the resource from the corresponding module. This could be done with a 16-bit pointer because the segment portion of the pointer could be inferred from the module the resource belonged to. In fact, since modules could be relocated in memory at run time due to compaction, you had better not try to remember the segment portion of the pointer since it could change! The function located t...
Sometimes my dreams are entirely uneventful
I dreamed that I was washing dishes with my lovely wife.
Playing a sound every time the foreground window changes
Today's Little Program plays a little sound every time the foreground window changes. One of my colleagues wondered if such a program was possible, "so that I stop accidentally typing the second halves of paragraphs into windows that pop up and steal focus." It's not clear whether this program will actually solve the bigger problem, but it was fun writing the program, and maybe you can use it for something. This program installs an accessibility hook that listens for changes to the system foreground. And when it happens, we play a little sound. I chose the Windows 7 Speech Misrecognition sound because ...
2013 Q3 link clearance: Microsoft blogger edition
It's that time again: Linking to other Microsoft bloggers, and once again, the links are all from the excellent NT Debugging blog.
How can I determine how responsive my application is to input?
A customer was adding diagnostics to their application and wanted to know if there was a way to detect that the application was being slow in processing its input. These sorts of delays manifest themselves to the end user as a sluggish application which is slow to respond to input events. They already had a watchdog timer that was reset every time their call returned a message, so they could capture stack traces if their application stopped processing messages for more than X milliseconds. They wanted to extend this diagnostic information to input delays. Fortunately, there's an easy way to tell. The wil...
Don't forget, Unicode includes formatting characters which can be used to influence output formatting
Consider this simple function: Depending on your screen resolution and font choices, this may end up displaying like this: That line break was awfully unfortunate, stranding the number 2 on a line by itself. (In publishingspeak, this is known as a orphan.) You can't control where the function will insert line breaks, but you can try to influence it with the use of Unicode formatting characters. Here, we can change the space before the 2 to a Unicode non-breaking space, U+00A0. The result is slightly less awful. Unfortunately, I haven't had much luck with the soft hyphen, but the zero-width space...
How can I tell that somebody used the MAKEINTRESOURCE macro to smuggle an integer inside a pointer?
Many functions and interfaces provide the option of passing either a string or an integer. The parameter is formally declared as a string, and if you want to pass an integer, you smuggle the integer inside a pointer by using the macro. For example, the function lets you load an resource specified by integer identifier by passing the identifier in the form . You can tell that it was the resource-loading functions who created the macro in the first place, since the name of the macro is "make integer resource." But other functions use the convention, too. The function lets you obtain a function exported by ord...
Punctuation is becoming increasingly decorative and less functional
The "Blog" of "Unnecessary" Quotation Marks calls out abuse of the quotation mark. For some reason, quotation marks are being increasingly used as a form of emphasis (a usage which remains controversial), by people unaware that such use, when interpreted as scare quotes, serves to undermine their original point. Mind you, the emphasis theory doesn't explain all misuses of quotation marks I've seen. I'm led to believe that some people simply enjoy seeing quotation marks and place them around randomly-selected words. Apostrophes are another commonly-misused punctuation mark. So much so that the city of Birmin...