The Old New Thing

Practical development throughout the evolution of Windows.

Latest posts

The posted message queue vs the input queue vs the message queue
May 30, 2013
Post comments count 0
Post likes count 0

The posted message queue vs the input queue vs the message queue

Raymond Chen
Raymond Chen

There are multiple ways of viewing the interaction between posted messages and input messages. MSDN prefers to view posted messages and input messages as part of one giant pool of messages in a message queue, with rules about which ones get processed first. I, on the other hand, prefer to think of posted messages and input messages as residing in different queues that are processed in sequence. By analogy, consider a business with a policy that loyalty program members are served ahead of regular customers. One way of organizing this is to form a single queue, but sorting them so members go to the front. To c...

What’s the point of SecureZeroMemory?
May 29, 2013
Post comments count 0
Post likes count 0

What’s the point of SecureZeroMemory?

Raymond Chen
Raymond Chen

The function zeroes out memory in a way that the compiler will not optimize out. But what's the point of doing that? Does it really make the application more secure? I mean, sure the data could go into the swap file or hibernation file, but you need to have Administrator access to access those files anyway, and you can't protect yourself against a rogue Administrator. And if the memory got swapped out before it got zeroed, then the values went into the swap file anyway. Others say that it's to prevent other applications from reading my process memory, but they could always have read the memory before I called . ...

Why don’t hotkeys for items on my Start menu work when I am in a fullscreen application?
May 28, 2013
Post comments count 0
Post likes count 0

Why don’t hotkeys for items on my Start menu work when I am in a fullscreen application?

Raymond Chen
Raymond Chen

You can set a hotkey on the shortcuts in your Start menu, and Explorer will launch that shortcut when you press the hotkey, but not if you are in a fullscreen application, like when you set Paint into fullscreen mode, or when you are displaying a PowerPoint presentation. Why are shortcut hotkeys ignored when a fullscreen application is running? This feature was added by customer request. The issue is that you're playing a game like World of Warcraft or Unreal Tournament, and you're mashing your keys like crazy, and whoops you slip and hit Ctrl+Alt+C instead of Ctrl+Shift+C, and now you inadvertently launched...

What are the scoping rules for variables in nested courtyards?
May 27, 2013
Post comments count 0
Post likes count 0

What are the scoping rules for variables in nested courtyards?

Raymond Chen
Raymond Chen

I dreamed that I had to fix a bug caused by variable redeclaration inside a nested courtyard. Had to move the horses out of the way first. And then it got weird. I won't go into the orchestra rehearsal that turned out to be just a recording played on a loudspeaker in an empty concert hall. Because you wouldn't believe that part.

How do I customize the console properties for a shortcut to a console application?
May 27, 2013
Post comments count 0
Post likes count 0

How do I customize the console properties for a shortcut to a console application?

Raymond Chen
Raymond Chen

You already know how to create a shortcut: #include <windows.h> #include <tchar.h> #include <shlobj.h> #include <atlbase.h> // class CCoInitialize incorporated here by reference int __cdecl _tmain(int argc, TCHAR **argv) { // error checking elided for expository purposes CCoInitialize init; CComPtr<IShellLink> spsl; spsl.CoCreateInstance(CLSID_ShellLink); spsl->SetPath(TEXT("C:\\Windows\\system32\\cmd.exe")); CComQIPtr<IPersistFile>(spsl)->Save(L"Here.lnk", TRUE); return 0; } If you double-click the resulting shortcut from Explorer, it will run the command p...

What happens if I manually post an auto-generated message into my message queue?
May 24, 2013
Post comments count 0
Post likes count 0

What happens if I manually post an auto-generated message into my message queue?

Raymond Chen
Raymond Chen

As we well know, the window manager generates various messages on-demand rather than posting them into the queue at the time the event occurs. But what happens if you manually post one of these messages, like ? Does that clear the internal flag that says "This window needs a paint message?" Nope. The window manager does not have a prank call detector. If you post a fake message, then a fake message shows up in the message queue. The part of the window manager which manages the "Does this window need to be repainted?" does not wiretap every telephone call to see if somebody is prank-calling a window with ...

Even though mouse-move, paint, and timer messages are generated on demand, it’s still possible for one to end up in your queue
May 23, 2013
Post comments count 0
Post likes count 0

Even though mouse-move, paint, and timer messages are generated on demand, it’s still possible for one to end up in your queue

Raymond Chen
Raymond Chen

We all know that the generated-on-demand messages like , , and messages are not posted into the queue when the corresponding event occurs, but rather are generated by or when they detect that they are about to conclude that there is no message to return and the generated-on-demand message can be returned. When this happens, the window manager creates the message on the fly, posts it into the queue, and hey, how about that, the or function now has a message to return! Note that this auto-generate can happen even though the queue is not empty, because the message filters control what messages in the queue ...

How do I get a window back on the screen when it moved far, far away? Windows 7 (and 8) edition
May 22, 2013
Post comments count 0
Post likes count 0

How do I get a window back on the screen when it moved far, far away? Windows 7 (and 8) edition

Raymond Chen
Raymond Chen

Some time ago, I showed how to get a window back on the screen when it moved far, far away. That technique still works in Windows 7 and 8, but there's an easier shortcut that takes advantage of window arrangement features added in Windows 7. First, you switch to the application by whatever means. Then hit Win+UpArrow to maximize the window. That should put the window on-screen, albeit at the wrong size. Now you just grab the title bar of the window with the mouse and drag it off the top edge of the screen. Bingo, the window returns to its original position, and you can use the mouse to put it wh...

A question about proper disposal of unwanted items with an unhelpful answer
May 21, 2013
Post comments count 0
Post likes count 0

A question about proper disposal of unwanted items with an unhelpful answer

Raymond Chen
Raymond Chen

On an internal mailing list about home maintenance and ownership, somebody asked: I have a handful of items that I need to get rid of and probably should not toss into the regular garbage. Any thoughts? The best reply was an unhelpful one. You've pretty much got all the components you need to build a bomb. Why dispose of them?