Perfect Cpopuptext class

Source: Internet
Author: User
Tags knowledge base

"describes a reusable class Cpopuptext with toolbar functionality." This article is about in a list box, if the text length of the item in the list box exceeds the width of the list box itself, a pop-up prompt similar to ToolTips is displayed, displaying the Extra long list box data items (figure I). The Cpopuptext class that is given in this article is very useful, but the example code provided by the paper--listctrl seems to be a bit of a problem when you click the list box data item below the cue bar to select the item. It would be nice if it could be perfected ...

Figure one shows pop-up prompts

Answer:

The friend who raised the question is very careful. Really good, a bit more serious people are not difficult to find this example of the bug mentioned above. This article will be aimed at this problem to modify and improve the program.

This example program uses a special class--clistboxtiphandler, which is used to intercept messages sent to a list box. This class derives from CSubclassWnd, and readers are aware that CSubclassWnd is a very useful class that is easy to use and highly reusable. This class is used in many articles and example codes in the VC Knowledge Base (This class is certainly available in other commercial development). The purpose of this class is to send intercepted Windows messages to another window. The Clistboxtiphandler class also uses another class--cpopuptext, which is used to display a very long list box item text. Let's analyze the goals to be achieved.

When the user clicks on the pop-up text of the cue bar (figure I), it is not feasible to have Windows ignore the hint text and let the mouse click events pass through the text directly to the list box below. So how do I get the mouse click event to the list box? Windows has its own trick.

When a user clicks on a mouse somewhere on the screen, Windows uses its internal mechanism to determine what is underneath the cursor, and before sending the WM_LBUTTONDOWN message, Windows first sends a WM_NCHITTEST message to query which non client area the cursor is on. If the cursor is above the caption, Windows returns htcaption. If the cursor is over the menu, Windows returns to Htmenu. If the cursor falls in the client area, Windows returns htclient. Most applications do not process wm_nchittest messages-typically this message is handled by the default window procedure (DEFWINDOWPROC), so some people may never have heard of such a Windows message. DefWindowProc carries out all the corresponding calculations to determine whether the pixel falls on the title, menu, border, resize client area, and returns the corresponding HT code. There is a httransparent in these returned HT codes. This return code is something that we are interested in in a separate field. It tells Windows, "I'm transparent, don't send me any mouse event messages, send them to the next window." "Here is the next window, which refers to the window thread on the z-coordinate below the cursor. In fact, that's what we need--the following modifications to the Cpopuptext class:

UINT CPopupText::OnNcHitTest(CPoint pt)
{
 return HTTRANSPARENT;
}

Haha, it is so simple, the bug ruled out! Now when the user clicks the hint text in figure one, the list box below it is selected. True God! I like the bug that can be fixed with a function that has only one line of code. It proved that the original design was not disappointing, although it was not so perfect.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.