Showing tag results for Code

Nov 13, 2003
Post comments count0
Post likes count0

Answer to previous exercise about m_fRecursing

Raymond Chen

Answer to previous exercise: The flag does not need to be per-instance. It only needs to be valid long enough that the recursive call that comes immediately afterwards can be detected. However, a global variable would not work because two threads might be inside the recursive call simultaneously. But a thread-local variable would work. (If you...

Code
Nov 12, 2003
Post comments count0
Post likes count0

A different type of dialog procedure

Raymond Chen

In the discussion following my entry about dialog procedure return values, somebody suggested an alternate dialog design where you just call to do default actions (the same way you write window procedures and ) rather than returning TRUE/FALSE. So let's do that. In fact, we're going to do it twice. I'll cover one method today and cover an enti...

Code
Nov 11, 2003
Post comments count0
Post likes count0

Safer subclassing

Raymond Chen

Answer to yesterday's homework assignment, with discussion.

Code
Nov 10, 2003
Post comments count0
Post likes count0

Homework assignment about window subclassing

Raymond Chen

Window subclassing is trickier than you think. Consider this code sketch: What could go wrong? We'll discuss it tomorrow.

Code
Nov 7, 2003
Post comments count0
Post likes count0

Returning values from a dialog procedure

Raymond Chen

For some reason, the way values are returned from a dialog procedure confuses people, so I'm going to try to explain it a different way. The trick with dialog box procedures is realizing that they actually need to return two pieces of information: Since tw...

Code
Nov 4, 2003
Post comments count0
Post likes count0

Just follow the rules and nobody gets hurt

Raymond Chen

You may have been lazy and not bothered calling VirtualProtect(PAGE_EXECUTE) when you generated some code on the fly. You got away with it because the i386 processor page protections do not have a "read but don't execute" mode, so anything you could read you could also execute. Until ...

Code
Nov 3, 2003
Post comments count0
Post likes count1

The long and sad story of the Shell Folders key

Raymond Chen

When you are attempting to architect an operating system, backwards compatibility is one of the ones you just have to accept. But when new programs rely on app hacks designed for old programs, that makes you want to scream.

CodeHistory
Oct 31, 2003
Post comments count0
Post likes count1

Why highlighting by inverting colors is a bad idea

Raymond Chen

Often people will say, "Oh, we can highlight by inverting the color." This may have worked great on two-color black-and-white displays, but in the world of 32-bit color this no longer is effective. Consider the following picture. See if you can guess which one is inverted. ...

Code
Oct 29, 2003
Post comments count0
Post likes count0

Drawing an active-looking caption even when not active

Raymond Chen

"Why would somebody ever want to do that?" you might ask. Well, this is a common appearance for floating toolbars. (But aside from that case, I can't think of any other valid reason to draw a window as active even though it isn't.) Fortunately this is easy to do. Just add this line to the of ...

Code
Oct 27, 2003
Post comments count0
Post likes count0

Getting a custom right-click menu for the caption icon

Raymond Chen

Explorer does it. Now you can too. It's a simple matter of detecting a context menu on the caption icon and displaying a custom context menu. Here are the simple changes to our scratch program to display a rather pointless one-item menu. When we receive a message, we check that...

Code