The Old New Thing

Practical development throughout the evolution of Windows.

Latest posts

Jan 11, 2007
Post comments count 0
Post likes count 1

How do I put more than 32,000 characters into a rich text control?

Raymond Chen

Last time we looked at loading an entire file into a rich text control. The code runs great, until you try to use it to display a license agreement provided by your legal department, and then some paranoid user reports that they can't read past page seven. (What, somebody reads those things?) What's going on? If you don't specify otherwise, the maximum number of characters in a rich edit control is 32,767 charaters. (This limit exists for compatibility with the original rich edit control.) You can raise the limit with the message. Therefore, we need to slip the line into the program before it calls . Ne...

Jan 10, 2007
Post comments count 0
Post likes count 0

Ken Levine teaches us about television script writing

Raymond Chen

Ken Levine has written for some of the most well-known television programs of the past few decades. M*A*S*H, Cheers (for which he won an Emmy), Frasier. And that's not counting his second (third? fourth?) career as a baseball announcer. He writes about whatever is on his mind, be it Barry Bonds' 715th home run, what not to put into your television script, more Cheers trivia than you know what to do with, or Thanksgiving travel tips, and every single one is filled with his personality and attitude. It's a joy to read.

Jan 10, 2007
Post comments count 0
Post likes count 1

How do I load an entire file into a rich text control?

Raymond Chen

To load an entire file into a rich text control, you can use the message, which accepts an of data all at once. Once you find the message, it's pretty straightforward how to use it, but I'll write out the code anyway; You pretty much follow your nose. The message wants you to tell it the format of the stream () and provide a pointer to an structure that controls the input. Since we want to read from a file, we open a file for reading and use it as the for our . The only tricky part is getting the return value correct for the callback. For some reason, the rich edit control wants zero on success and nonze...

Jan 9, 2007
Post comments count 0
Post likes count 0

Article of clothing or tasty dessert?

Raymond Chen

Balaclava or baklava? I always get the two confused, and I have to stop and think. "Why were the bank robbers covered in a tasty dessert?" "Who wants to eat a hooded knit cap?"

Jan 9, 2007
Post comments count 0
Post likes count 1

What triggers the recall of an offline file?

Raymond Chen

Hierarchical storage management is one of the taxes software developers have to pay. What can you safely do to an offline file? What will trigger its recall? (First, a note on terminology: Recalling a file means to restore it from remote storage to local storage. A file that has been recalled is online; a file that has been placed on remote storage is offline.) Merely opening the file will not recall it. Therefore, you can still open the file and use the handle in functions like , , and without triggering a recall. But if you read from or write to the file (or map the file, which is the moral equivalent of re...

Jan 8, 2007
Post comments count 0
Post likes count 1

Why do property sheets sometimes take a first-chance exception?

Raymond Chen

Reader cmonachan asked why can cause a first-chance exception. This is mentioned in Knowledge Base article 158552. But why take the exception in the first place? First off, let's take MFC out of the picture. The first-chance exception is coming from the property sheet manager. MFC is just the middle-man. Okay, so why the first-chance exception? It's not obviously backwards compatibility, since property sheets were new for Windows 95; there was no old property sheet manager to be compatible with. But yes, it was for compatibility. Not with an imaginary "earlier version" of the property sheet manager, bu...

Jan 5, 2007
Post comments count 0
Post likes count 1

What('s) a character!

Raymond Chen

Norman Diamond seems to have made a side career of harping on this topic on a fairly regular basis, although he never comes out and says that this is what he's complaining about. He just assumes everybody knows. (This usually leads to confusion, as you can see from the follow-ups.) Back in the ANSI days, terminology was simpler. Windows operated on s, which are one byte in size. Buffer sizes were documented as specified in bytes, even for textual information. For example, here's a snippet from the 16-bit documentation for the function: The return value specifies the text length, in bytes, not including an...

Jan 4, 2007
Post comments count 0
Post likes count 1

How a bullet turns into a beep

Raymond Chen

Bangs or bells.

Jan 3, 2007
Post comments count 0
Post likes count 1

Wait, but why can I GetProcAddress for IsDialogMessage?

Raymond Chen

Okay, so I explained that a lot of so-called functions are really redirecting macros, function-like macros, intrinsic functions, and inline functions, and consequently, won't actually get anything since the function doesn't exist in the form of an exported function. But why, then, can you for ? Let's take a closer look at the exports from . Here's the relevant excerpt. Notice that this function is exported three ways. The last two are the ones you expect, for ANSI callers and for UNICODE callers. That first one is the one you didn't expect: with no A or W suffix. But notice that its entry point addres...