Showing tag results for Code

Aug 15, 2005
Post comments count0
Post likes count0

The poor man’s way of identifying memory leaks

Raymond Chen
Raymond Chen

There is a variety of tools available for identifying resource leaks, but there's one method that requires no tools or special compiler switches or support libraries: Just let the leak continue until the source becomes blatantly obvious. Nightly automated stress testing is a regular part of any project. Some teams use screen savers as the trigger...

Code
Aug 12, 2005
Post comments count0
Post likes count0

Adding a lookup control to the dictionary: Searching Pinyin

Raymond Chen
Raymond Chen

Finally we start searching. For now, the search algorithm is going to be very simple: The string you type into the edit control will be treated as the start of a Pinyin word or phrase. We'll make it fancier later. Here is where a lot of the groundwork (some of which I called out explicitly and some of which I slipped in without calling attention...

Code
Aug 11, 2005
Post comments count0
Post likes count0

Adding a lookup control to the dictionary: Just getting it on the screen

Raymond Chen
Raymond Chen

When we last left the dictionary project, we were able to display the dictionary entries but hadn't yet gotten around to searching it. Today, we'll place the lookup control, though we won't hook it up until next time. First, we give the edit control an ID and create some member variables to keep track of it. class RootWindow : public Window { ...

Code
Aug 9, 2005
Post comments count0
Post likes count0

The dangers of messing with activation when handling a WM_ACTIVATE message

Raymond Chen
Raymond Chen

This is basically the same thing as The dangers of playing focus games when handling a WM_KILLFOCUS message, just with activation in place of focus. One developer discovered the hard way that if you mess with activation inside your WM_ACTIVATE handler, things get weird. The author noted that if he posted a message and did the work from the posted...

Code
Aug 8, 2005
Post comments count0
Post likes count0

The dangers of playing focus games when handling a WM_KILLFOCUS message

Raymond Chen
Raymond Chen

I had noted last year that WM_KILLFOCUS is the wrong time to do field validation. Here's another example of how messing with the focus during a WM_KILLFOCUS message can create confusion. Consider an edit control that displays feedback via a balloon tip. For example, password edit controls often warn you if you're typing your password while Caps...

Code
Aug 5, 2005
Post comments count0
Post likes count0

Why does the Internet Explorer animated logo arrange its frame vertically?

Raymond Chen
Raymond Chen

If you ever tried to build a custom animated logo for Internet Explorer, you cetainly noticed that the frames of the animation are arranged vertically rather than horizontally. Why is that? Because it's much more efficient. Recall that bitmaps are stored as a series of rows of pixels. In other words, if you number the pixels of a bitmap like ...

Code
Aug 4, 2005
Post comments count0
Post likes count0

Double-clicking radio buttons

Raymond Chen
Raymond Chen

A subtlety that adds a level of polish to your dialogs is supporting double-clicked radio buttons as an abbreviation for "select + OK". (Or "select + Next" or "select + Finish" if the page is part of a wizard.) Consider the following dialog template and associated dialog procedure: 1 DIALOGEX DISCARDABLE 32, 32, 200, 76 STYLE DS_MODALFRAME | ...

Code
Aug 3, 2005
Post comments count0
Post likes count0

Drawing a monochrome bitmap with transparency

Raymond Chen
Raymond Chen

Last time, I left you with a brief puzzle. Here are two approaches. I am not a GDI expert, so there may be even better solutions out there. To emphasize the transparency, I'll change the window background color to the application workspace color. BOOL WinRegisterClass(WNDCLASS *pwc) { pwc->hbrBackground = (HBRUSH)(COLOR_APPWORKSPACE + 1);...

Code
Aug 2, 2005
Post comments count0
Post likes count0

Rendering menu glyphs is slightly trickier

Raymond Chen
Raymond Chen

Last time, we saw how to draw themed and unthemed radio buttons, and I mentioned that menu glyphs are trickier. They're trickier because they are provided as raw monochrome bitmaps instead of fully-formed color-coordinated bitmaps. First, let's do it wrong in order to see what we get. Then we'll try to fix it. Start with a clean new scratch prog...

Code
Aug 1, 2005
Post comments count0
Post likes count0

Rendering standard Windows elements

Raymond Chen
Raymond Chen

The DrawFrameControl function allows you to render standard Windows elements in your custom controls. Let's start by simply rendering a selected radio button. Start with our new scratch program and make this very simple change: class RootWindow : public Window { ... protected: void PaintContent(PAINTSTRUCT *pps); ... }; void RootWindow::Pa...

Code