Implement TOOL TIP with VC

zhaozj2021-02-16  148

I used VC to do Tool Tips many times, but I have to study again. Although I am talking about it, it should be, but mainly because I am lazy. Today, I have to write down. When I use it later, it is reference Please also read the friends of this article to remember it in the future.

Implement Tool TIP with VC. It is more complicated, but it is also simple, but the MFC helps some windows implementation, and other windows don't implement, but I have been complicated. I started using the WM_MouseMove message, then use CTooltipCtrl :: POP, this method Too stupid. Not recommended. Unless you need to be customized.

The MFC is good for Tool TIP. The default situation CFrameWnd supports very well. Then CWnd. Mainly reflected in the support of the TTN_NeedText message and the support of OntoolHitTest is supported in CFrameWnd .ontToolHittest is supported in CWND. These support can be well implemented in the frame window. Toolbar's TIP. And in a dialog box to implement a control Tool TIP.

Example. Implement TOOL TIP in the dialog.

1.enabletooltips (true) is indispensable. Suggestions in: cdialog :: OnIitDialog call.

2. On_notify_ex (TTN_NeedText, 0, OnneedText). OnneedText implements the text of the Tool Tip. Introduced parameter IDFROM is the ID of the control, get the corresponding TIP text according to the control ID

For this simple two-step, you will implement the Tool Tip in the dialog. In fact, you don't only only dialog boxes, any window can implement TIP of your sub-window control with the above method. But the premise is that the derived class of CWND.

This shows that the support of the MFC is very strong for TOOL TIP.

But all this is the MFC implementation, we are simple to describe its implementation principle, which is more clear

CWND itself has a ctooltipCtrl object, which is put in this pthreadstate, knowing that CWnd is OK.

CWnd responsible for creating it, and then call the FilterToolTipMessage in PreTranslateMessage, this function returns a handle WM_MOUSEMOVE, WM_NCMOUSEMOVE other news, CToolTipCtrl a chance to determine whether the mouse needs to be displayed on the TIP window, if it is, it shows .FilterToolTipMessage start CWnd :: ONTOOLHITTEST gets the data in ToolInfo:, such as which control requires TIP and other information, then use the AddTool message to add this need to TIP control to the Tool list of CTooltipCtrl, then transfer the mouse to CTooltipCtrl processing. If this is Tip's text needs to be obtained with a callback function, and it is obtained from the parent window of WM_NOTIFY TTN_NeedText. This process is whether ctooltipctrl determines whether to display TIP, get text and display TIP's whole process

In this analysis, you know that the Tip of CWND helps to achieve the control sub-window is actually the OntoolHitTest this function, then forward the message in PretranslateMessage to help CToolTIPCTRL correctly display TIP.

CframeWnd is a response to TTN_NeedText, helping sub-windows implement TIP.

In fact, we can also achieve these default implementations, you can use ctooltipctrl to get the same:

1.ctooltipctrl :: Create Create Tool Tip

2. ADTOOL adds a Tool, and the Tool is a region or a sub-window that needs to display TIP. If you use unclear place for AddTool, it is recommended to view the source program. It may feel more convenient to use TTM_ADDTool.

3. Call CTooltipCtrl in PretranslateMessage :: relaymessage

4. If in AddTool, the text is implemented with a callback function, then handle the TTN_NeedText message.

In fact, I have created CTooltiPCtrl and MFC. Just don't need to give a window or area that needs to be displayed in ONTOOLHITTEST.

If you use TIP to the child window. Use the MFC simpler. If you give yourself?

Set UFlags = TTF_IDishWnd in ToolInfo, then set the UID as the window handle, hwnd is the window handle. Write so much, if you have any place, please contact me to help me correct the error.

Just have a problem, I haven't figured it. That is why MFC puts CTooltipCtrl in pthreadstate. Is it necessary to use all window services for this thread? Is it a performance of resources. This also needs to be studied. If a friend knows the answer, I hope I can enlighten me. Thank you.

转载请注明原文地址:https://www.9cbs.com/read-9113.html

New Post(0)