Showing tag results for Code

Apr 20, 2005
Post comments count0
Post likes count0

What is the DC brush good for?

Raymond Chen
Raymond Chen

The DC brush is a stock brush associated with the device context. Like the system color brushes, the color of the DC brush changes dynamically, but whereas the system color brushes change color based on the system colors, the color of the DC brush changes at your command. The DC brush is handy when you need a solid color brush for a very shor...

Code
Apr 18, 2005
Post comments count0
Post likes count5

What is the HINSTANCE passed to CreateWindow and RegisterClass used for?

Raymond Chen
Raymond Chen

One of the less-understood parameters to the function and the function is the (either passed as a parameter or as part of the structure). The window class name is not sufficient to identify the class uniquely. Each process has its own window class list, and each entry in the window class list consists of an instance handle and a class nam...

Code
Apr 15, 2005
Post comments count0
Post likes count0

Tweaking our computation of the interval between two moments in time

Raymond Chen
Raymond Chen

We can take our computation of the interval between two moments in time and combine it with the trick we developed for using the powers of mathematics to simplify multi-level comparisons to reduce the amount of work we impose upon the time/date engine. Observe that we avoided a call to the method (which is presumably rather complicated becau...

Code
Apr 14, 2005
Post comments count0
Post likes count0

Computing the interval between two moments in time

Raymond Chen
Raymond Chen

Computing the interval between two moments in time is easy: It's just subtraction, but subtraction may not be what you want. If you are displaying time units on the order of months and years, then you run into the problem that a month is of variable length. some people just take the value relative to a base date of January 1 and extract the yea...

Code
Apr 13, 2005
Post comments count0
Post likes count0

Using the powers of mathematics to simplify multi-level comparisons

Raymond Chen
Raymond Chen

What a boring title. Often you'll find yourself needing to perform a multi-level comparison. The most common example of this is performing a version check when there are major and minor version numbers involved. Bad version number checks are one of the most common sources of errors. If you're comparing version numbers, you can use the funct...

Code
Apr 7, 2005
Post comments count0
Post likes count0

The dialog manager, part 8: Custom navigation in dialog boxes

Raymond Chen
Raymond Chen

Some dialog boxes contain custom navigation that goes beyond what the function provides. For example, property sheets use Ctrl+Tab and Ctrl+Shift+Tab to change pages within the property sheet. Remember the core of the dialog loop: (Or the modified version we created in part 7.) To add custom navigation, just stick it in before callin...

Code
Apr 6, 2005
Post comments count0
Post likes count0

The dialog manager, part 7: More subtleties in message loops

Raymond Chen
Raymond Chen

Last time, we solved the problem with the function by posting a harmless message. Today, we're going to solve the problem in an entirely different way. The idea here is to make sure the modal message loop regains control, even if all that happened were incoming sent messages, so that it can detect that the flag is set and break out of the mod...

Code
Apr 5, 2005
Post comments count0
Post likes count0

The dialog manager, part 6: Subtleties in message loops

Raymond Chen
Raymond Chen

Last time, I left you with a homework exercise: Find the subtle bug in the interaction between and the modal message loop. The subtlety is that sets some flags but does nothing to force the message loop to notice that the flag was actually set. Recall that the function does not return until a posted message arrives in the queue. If incomin...

Code
Apr 4, 2005
Post comments count0
Post likes count0

The dialog manager, part 5: Converting a non-modal dialog box to modal

Raymond Chen
Raymond Chen

Let's apply what we learned from last time and convert a modeless dialog box into a modal one. As always, start with the scratch program and make the following additions: Not a very exciting program, I grant you that. It just displays a dialog box and returns a value that depends on which button you pressed. The function uses the function t...

Code