Showing tag results for Code

May 22, 2009
Post comments count0
Post likes count1

If an event is signaled more than once, are they delivered in the order in which they were signaled?

Raymond Chen

A customer asked the following question: Is it guaranteed that the events when signaled multiple times on an event object are delivered in the order in which they were signaled? For example, a thread is waiting on the event handle and performs some operation each time it is signaled. The ordering of those operations should be in the same order...

Code
May 18, 2009
Post comments count0
Post likes count1

How do I know whether a window message was processed?

Raymond Chen

Commenter Skeets Norquist asks how to tell whether the original window procedure processed a message when you use to call the original window procedure. "CallWindowProc() always seems to return an LRESULT of 0." No, actually, returns whatever the window procedure did. If the window procedure returned zero, then returns zero. If the window pro...

Code
May 8, 2009
Post comments count0
Post likes count1

Writing a sort comparison function, redux

Raymond Chen

Prerequisites: Experience with sort functions such as qsort. Overqualifications: Familiarity with sort algorithms. If you break the rules for sort comparison functions, then don't expect the result of a sort call to be meaningful. In fact, if you really mess it up, you can corrupt memory or go into an infinite loop. My program hangs when I...

Code
May 7, 2009
Post comments count0
Post likes count1

When you subclass a window, it’s the original window procedure of the window you subclass you have to call when you want to call the original window procedure

Raymond Chen

When you subclass a window, you set the window procedure to a function of your choosing, and you remember the original window procedure so you can pass it to the CallWindowProc function when your subclass function wants to pass the message to the original window procedure. For example, if you subclass a window like this: SubclassWidgetDialog(HWN...

Code
Apr 29, 2009
Post comments count0
Post likes count1

Why is there sometimes a half-second delay between the click and the action?

Raymond Chen

There are places in the user interface where you may click to perform an action, but the action doesn't actually take place until a half second later. Why is there a half-second delay? Because it's waiting to see if the user is on the way to a double-click. Some users simply double-click everything in sight, and depending on what the single cl...

Code
Apr 22, 2009
Post comments count0
Post likes count1

What structure packing do the Windows SDK header files expect?

Raymond Chen

/Zp8 In words, integral types and pointers up to eight bytes in size are stored at their natural alignment. Larger types are stored at eight-byte alignment. In other words (saying it a third time), let be an integral or pointer type. If ≤ 8, then is aligned at a -byte boundary. If ≥ 8, then is aligned at an 8-byte boundary.

Code
Apr 20, 2009
Post comments count0
Post likes count1

The dangers of destroying a window while it is processing a sent message

Raymond Chen

Commenter BryanK wonders why weird things happen if you destroy a window while it is processing the message. He suspects that it's similar to the problems you encounter when you destroy a window in response to the message. Although I haven't studied the situation, I wouldn't be surprised if the problem is indeed entirely analogous. It just f...

Code
Apr 8, 2009
Post comments count0
Post likes count0

Let GDI do your RLE compression for you

Raymond Chen

This is another trick along the lines of using DIB sections to perform bulk color mapping. GDI will do it for you; you just have to know how to ask. Today's mission is to take a 4bpp bitmap and compress it in BI_RLE4 format. Now, sure, there are programs out there which already do this conversion, but the lesson is in the journey, not in the dest...

Code
Apr 6, 2009
Post comments count0
Post likes count1

There’s nothing wrong with making bold treeview items

Raymond Chen

Commenter Frans Bouma asks, Why is the text of a treenode chopped off when you switch the font from normal to bold? It apparently is for backwards compatibility but I fail to see why this is necessary for backward compatibility... Actually, bold treeview items work just fine. Watch: Start with our scratch program and make these changes: ...

Code
Mar 30, 2009
Post comments count0
Post likes count1

What is the implementation of WM_PRINTCLIENT?

Raymond Chen

Via the suggestion box, Martin Filteau asks Could you explain the implementation of WM_PRINTCLIENT? It seems that even MS got it wrong in the LISTBOX control. Try to AnimateWindow a window that as a LISTBOX control as a child. The LISTBOX displays correctly if it is NOT empty. However, if it is empty... nothing is drawn. I got a similar ...

Code