Showing tag results for Code

Mar 22, 2013
Post comments count0
Post likes count1

When will GetMessage return -1?

Raymond Chen
Raymond Chen

A source of great consternation is the mysterious return value from : If there is an error, the return value is −1. For example, the function fails if is an invalid window handle or is an invalid pointer. That paragraph has caused all sorts of havoc, because it throws into disarray the standard message pump: But don't worry, the standard m...

Code
Mar 21, 2013
Post comments count0
Post likes count0

Does this operation work when file system redirection is disabled? The default answer is NO

Raymond Chen
Raymond Chen

A customer reported that when their program called to get the icon for a folder, the call failed. "It works on some machines but not others. We don't know what the difference is between the working and non-working machines." They included the offending function from their program, but everything in the function looked good. The problem was somethi...

Code
Mar 15, 2013
Post comments count0
Post likes count0

Playing with the Windows Animation Manager: Moving lots of stuff around

Raymond Chen
Raymond Chen

We saw last time a sample program that moved a circle around. Today I'll try to build the classic demo of animating a lot of objects in a list. This isn't the prettiest code, but I wanted to make as few changes as possible. Start with the Timer-Driven Animation, and make these changes to the Main­Window.h header file. struct Item { I...

Code
Mar 14, 2013
Post comments count0
Post likes count0

Playing with the Windows Animation Manager: Fixing a sample

Raymond Chen
Raymond Chen

Windows 7 provides a component known as the Windows Animation Manager, known to some people by its acronym WAM, pronounced "wham". There are some nice sample programs for WAM on MSDN, but for some reason, the authors of the samples decided to animate the three color components of a resultant color. Because apparently the authors of those ...

Code
Mar 13, 2013
Post comments count0
Post likes count1

Closing holes in the update notification pattern

Raymond Chen
Raymond Chen

Suppose you have a function that is registered to be called the next time something gets updated, and suppose that the notification is a one-shot notification and needs to be re-armed each time you want to wait for the next notification. (For example, the Reg­Notify­Change­Key­Value function behaves this way.) Consider the followi...

Code
Mar 11, 2013
Post comments count0
Post likes count0

How can I see what files and shares are being accessed remotely, and the general usage pattern for the NetXxx functions

Raymond Chen
Raymond Chen

Today's Little Program is a command line version of the Shared Folders MMC snap-in. Why? Because it illustrates the usage pattern for the Net­Xxx family of functions. (It's also a clone of the networking portion of the openfiles tool.) The Net­Xxx family of functions generally work like this: You pass in some parameters that describe ...

Code
Mar 7, 2013
Post comments count0
Post likes count0

What are the conventions for managing standard handles?

Raymond Chen
Raymond Chen

Consider this function: void ChangeConsoleColor(WORD wColor) { HANDLE h = GetStdHandle(STD_OUTPUT_HANDLE); if (h != INVALID_HANDLE_VALUE) { SetConsoleTextAttribute(h, wColor); CloseHandle(h); } } "When I call this function, it works the first time, but when I call it a second time, Get­Std­Handle returns a handle numerically ide...

Code
Mar 6, 2013
Post comments count0
Post likes count0

What are the dire consequences of not selecting objects out of my DC?

Raymond Chen
Raymond Chen

The convention when working with device contexts is to restore them to the way you found them. If a drawing function selects a bitmap into a device context, then it should select the original bitmap into the device context before returning. Same for fonts, pens, all that stuff. But what if you decide to violate that convention? For example, maybe...

Code
Mar 4, 2013
Post comments count0
Post likes count0

Marking a shortcut to say that it should not be placed on the Windows 8 Start page upon installation or treated as a newly-installed application

Raymond Chen
Raymond Chen

Today's Little Program creates a shortcut on the Start menu but marks it as "Do not put me on the front page upon installation." This is something you should do to any secondary shortcuts your installer creates. And while you're at it, you may as well set the "Don't highlight me as a newly-installed program" attribute used by Windows 7. (Reme...

Code