Use VC to implement tool tip

Source: Internet
Author: User

I have used VC for tool tip many times, but I have to study it again every time. although it is necessary to study at the time, it is mainly because you are lazy. remember today. for more information, see. please also read this article and write it down for future reference.

Use VC to implement tool tip. it is complicated, but it is also simple. However, MFC helps to implement some windows, while other windows are not implemented, which is complicated. at first, I used the wm_mousemove message and then ctooltipctrl: Pop. This method is too stupid. not recommended. unless you need to customize.

MFC supports tool tip well. by default, cframewnd supports well. then there is cwnd. it is mainly reflected in the support of ttn_needtext messages and ontoolhittest messages. ttn_needtext is supported in cframewnd. ontoolhittest is supported in cwnd. with these support, you can implement the tip of the toolbar in the Framework Window. and implements the tool tip of a control in a dialog box.

For example, implement tool tip in the dialog box.

1. enabletooltips (true) is indispensable. It is recommended to call it in: cdialog: oninitdialog.

2. on_policy_ex (ttn_needtext, 0, onneedtext). onneedtext implements the text of tool tip. The input parameter idfrom is the Control ID, and the corresponding tip text is obtained based on the control ID.

In this two simple steps, the tool tip in the dialog box is implemented. in fact, not only dialog box, any window can use the above method to implement the tip of its own subwindow control. the premise is that it must be the derived class of cwnd.

This shows that MFC supports tool tip very well.

However, all of this is implemented by MFC. Let's briefly describe its implementation principle, so that we can see it more clearly.

Cwnd itself has a ctooltipctrl object, which is put in the pthreadstate. You just need to know that cwnd has one.

Cwnd is responsible for creating it and then calling filtertooltipmessage in pretranslatemessage. This function is used to process messages such as wm_mousemove and wm_ncmousemove, giving ctooltipctrl a chance, determines whether the mouse is in the window where the tip needs to be displayed. If yes, it is displayed. filtertooltipmessage first obtains data in toolinfo: From cwnd: ontoolhittest, for example, which control requires tip and other information, and then adds the required tip control to the tool list of ctooltipctrl by using the addtool message, then, the mouse moves the message to ctooltipctrl for processing. if the text of this tip needs to be obtained using the callback function, use ttn_needtext of wm_notify to get it from the parent window of ctooltipctrl. this process is ctooltipctrl to determine whether to display the tip, to obtain the text and display the tip of the whole process

In this analysis, we can see that the ontoolhittest function is implemented by the cwnd to help implement the tip of the control subwindow, and then send messages in the pretranslatemessage to help the ctooltipctrl correctly display the tip.

Cframewnd implements the response of ttn_needtext to help subwindows implement tip.

In fact, we can also avoid these default implementations. We can use ctooltipctrl to handle them by ourselves. The approach is the same:

1. ctooltipctrl: Create to create a tool tip

2. Add a tool to addtool. The tool here is an area or subwindow of the tip to be displayed. If you have any questions about addtool usage, we recommend that you check the sourceProgram. It may be easier to directly use ttm_addtool.

3. Call ctooltipctrl: relaymessage in pretranslatemessage

4. If the text in addtool is implemented by the callback function, the ttn_needtext message must be processed.

In fact, you have created ctooltipctrl and MFC to do the same, but you do not need to provide the window or area in ontoolhittest to display the tip.

If tip is used for the subwindow, it is easiest to use MFC. What if it is used for the subwindow?

Set uflags = ttf_idishwnd in toolinfo, set UID as the window handle, and hwnd as the window handle.

Please contact me if there are any errors that have been written so much to help me correct the mistakes.

I just haven't figured it out yet. That's why MFC put ctooltipctrl in pthreadstate. Is it to use a tool tip to serve all windows of the thread? Is it a kind of resource-saving performance. We still need to study this. If any one of you knows the answer, I hope you can leave it blank. Thank you.

 

This article from the csdn blog, reproduced please indicate the source: http://blog.csdn.net/twater2000/archive/2004/08/05/65501.aspx

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.