Showing tag results for 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
Jul 27, 2005
Post comments count0
Post likes count0

When the normal window destruction messages are thrown for a loop

Raymond Chen
Raymond Chen

Last time, I alluded to weirdness that can result in the normal cycle of destruction messages being thrown out of kilter. Commenter Adrian noted that the WM_GETMINMAXINFO message arrives before WM_NCCREATE for top-level windows. This is indeed unfortunate but (mistake or not) it's been that way for over a decade and changing it now would intro...

Code
Jul 26, 2005
Post comments count0
Post likes count1

What is the difference between WM_DESTROY and WM_NCDESTROY?

Raymond Chen
Raymond Chen

There are two window messages closely-associated with window destruction, the WM_DESTROY message and the WM_NCDESTROY message. What's the difference? The difference is that the WM_DESTROY message is sent at the start of the window destruction sequence, whereas the WM_NCDESTROY message is sent at the end. This is an important distinction when y...

Code
Jul 22, 2005
Post comments count0
Post likes count0

The importance of passing the WT_EXECUTELONGFUNCTION flag to QueueUserWorkItem

Raymond Chen
Raymond Chen

One of the flags to the QueueUserWorkItem function is WT_EXECUTELONGFUNCTION. The documentation for that flag reads The callback function can perform a long wait. This flag helps the system to decide if it should create a new thread. As noted in the documentation, the thread pool uses this flag to decide whether it should create a new thread...

Code
Jul 21, 2005
Post comments count0
Post likes count0

FindFirstFile is not a SQL query

Raymond Chen
Raymond Chen

The function is not a SQL query. It's a very simple directory enumerator. There is a slightly fancier version called , but even that function doesn't add much at present beyond filtering for directories or devices. You don't get to pass it sort criteria like or "return the files/directories sorted smallest file first", or "return the files/dir...

Code
Jul 13, 2005
Post comments count0
Post likes count0

Converting from traditional to simplified Chinese, part 3: Highlighting differences

Raymond Chen
Raymond Chen

One of the things that is interesting to me as a student of the Chinese languages is to recognize where the traditional and simplified Chinese scripts differ. Since this is my program, I'm going to hard-code the color for simplified Chinese script: maroon. To accomplish the highlighting, we take advantage of listview's custom-draw feature. Cus...

Code
Jul 12, 2005
Post comments count0
Post likes count0

Converting from traditional to simplified Chinese, part 2: Using the dictionary

Raymond Chen
Raymond Chen

Now that we have our traditional-to-simplified pseudo-dictionary, we can use it to generate simplified Chinese words in our Chinese/English dictionary. class StringPool { public: StringPool(); ~StringPool(); LPWSTR AllocString(const WCHAR* pszBegin, const WCHAR* pszEnd); LPWSTR DupString(const WCHAR* pszBegin) { return AllocString(pszBegi...

Code