Showing tag results for Code

Jun 3, 2013
Post comments count0
Post likes count1

How do I make it more difficult for somebody to take a screenshot of my window?

Raymond Chen
Raymond Chen

Ultimately, you can't stop somebody from ignoring the words Confidential at the top of a document and whipping out a digital camera and taking a picture of the screen. But at least starting in Windows 7 you can make it a little more difficult. Take our scratch program and add this one line: ... SetWindowDisplayAffinity(hwnd, WDA...

Code
May 31, 2013
Post comments count0
Post likes count1

Posted messages are processed ahead of input messages, even if they were posted later

Raymond Chen
Raymond Chen

Regardless of which interpretation you use, it remains the case that posted messages are processed ahead of input messages. Under the MSDN interpretation, posted messages and input messages all go into the message queue, but posted messages are pulled from the queue before input messages. Under the Raymond interpretation, posted messages and in...

Code
May 30, 2013
Post comments count0
Post likes count1

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

Code
May 29, 2013
Post comments count0
Post likes count1

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

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