Showing tag results for Code

May 29, 2013
Post comments count0
Post likes count1

What’s the point of SecureZeroMemory?

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...

Code
May 27, 2013
Post comments count0
Post likes count1

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

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> ...

Code
May 24, 2013
Post comments count0
Post likes count1

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

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...

Code
May 23, 2013
Post comments count0
Post likes count1

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

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 c...

Code
May 20, 2013
Post comments count0
Post likes count2

Copying a file to the clipboard so you can paste it into Explorer or an email message or whatever

Raymond Chen

Today's Little Program takes a fully-qualified file name from the command line and puts that file onto the clipboard. Once there, you can paste it into an Explorer window, or into an email message, or a word processing document, or anybody else who understands shell data objects. #include <windows.h> #include <shlobj.h> #include <...

Code
May 17, 2013
Post comments count0
Post likes count1

Who sends the initial WM_UPDATEUISTATE message?

Raymond Chen

Last time, we looked at the confusingly-named WM_UPDATE­UI­STATE and WM_CHANGE­UI­STATE messages. But how does the whole indicator thingie get off the ground? The default state for a window is to show all indicators. But as a special trick, the dialog manager will send a WM_UPDATE­UI­STATE message with UIS_INITIALIZE aft...

Code
May 16, 2013
Post comments count0
Post likes count1

Untangling the confusingly-named WM_UPDATEUISTATE and WM_CHANGEUISTATE messages

Raymond Chen

I always get confused by the and messages, and I have to go figure them out each time I need to mess with them. So this time, I'm going to write it down so I don't forget. Because the act of writing it down helps me to remember. It's like in school, where the teacher says, "This is a closed-book, closed-notes exam, but you are allowed to bring ...

Code
May 15, 2013
Post comments count0
Post likes count1

What does GDI use biXPelsPerMeter and SetBitmapDimensionEx for?

Raymond Chen

What does GDI use and for? Nothing. The and are completely ignored by GDI when loading a bitmap. The values are there for the benefit of image-editing programs who want to record additional information about the bitmap, but GDI ignores them. Similarly, the and functions update a structure associated with each bitmap, but GDI does not...

Code
May 13, 2013
Post comments count0
Post likes count1

How can I display a live screenshot of a piece of another application?

Raymond Chen

Today's Little Program takes a rectangular portion of another application and continuously replicates it in its own client area. You might want to do this if you want to monitor a portion of an application like a custom progress bar, and the application doesn't use the Windows 7 taskbar progress indicator feature. (Maybe it's an old applicati...

Code
May 10, 2013
Post comments count0
Post likes count1

If you want to use a name for your file mapping, don’t just use the name of the file itself

Raymond Chen

The original question from the customer was why they couldn't get named file mappings to work at all, but it turns out that the reason is that they were using the full path to the file as the name, even though backslashes have special meaning in file mapping names. Okay, that problem can be solved by changing the backslash to some character lega...

Code