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.