Reusable classes with toolbar functionality Cpopuptext

Source: Internet
Author: User

Background: I use a clistbox derived class to implement the host (Owner-draw) list box, which has an item width that exceeds the width of the list box itself, so when the mouse pointer points to a large-width list box item, I want to display a toolbar-like hint window. Displays the complete list box item text in a window.

At first I wanted to use Ctooltipctrl::addtool's third parameter Lprecttool to implement this feature, but it didn't work. Later, I adopted a self-sustaining solution, creating a reusable window class, cpopuptext-base class is CWnd. You can use this derived class not only to implement a toolbar-like hint window in a list box, but also to implement a toolbar-like hint window in other common controls such as combo boxes, list views, and so on.

Cpopuptext implements a pop-up window similar to toolbar-a light yellow background, black text.

The Cpopuptext method is to instantiate the object and create a window.

CPopupText wndText;
wndText.Create(...);

The parameters of the CREATE function are: Parent window, style, ID, and location information CPoint, usually you want to create an invisible window (that is, turn off ws_visible), and then, when you want to show the prompts, call the SetWindowText function first.

Set the hint text, and then call the ShowWindow function to display the prompt text.

wndText.SetWindowText("hello, world");
wndText.ShowWindow(SW_SHOWNA);

The Cpopuptext class determines the size of the pop-up window based on the length of the hint text. Its font defaults are the same as the status line display font (defined by the Nonclientmetrics struct member Lfstatusfont returned by SystemParametersInfo (Spi_getnonclientmetrics), and set Sw_ Showna is important because you don't want the prompt window to be the active window and just show it. In addition, Cpopuptext also provides a specialized function cpopuptext::showdelayed, which is to set a millisecond delay before the prompt window is displayed, and if the delay is zero, the prompt window will be displayed immediately. You can use this feature to replace the call to ShowWindow. Call Cpopuptext::cancel If you want to hide the hint window or cancel showdelayed.

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.