Tool tip Control Introduction

Source: Internet
Author: User
Tags range resource unique id

Theory:
A tooltip is a rectangular window that is displayed when the mouse hovers over a particular area. The ToolTip window contains the text that some programmers want to display. At this point, the ToolTip works the same as the status bar, but the tooltip disappears when clicked or away from the specified area. You may be familiar with ToolTips associated with toolbars, which are handy for toolbar controls. If you want to display ToolTips in other windows and controls, you'll have to create them yourself.

Now that you know what ToolTips are, let's see how to create them. The approximate steps are as follows:

Create a ToolTip control with the CreateWindowEx function.
Defines the area where a ToolTip control will monitor mouse movement.
Passing a zone to a ToolTip control
The mouse message for the delivery area is forwarded to the ToolTip control. (This step may be earlier, depending on the method of relaying the message)
Here we will discuss each step in detail.
Tool tip Control Creation
A tooltip control is a generic control. Again, to invoke initcommoncontrols somewhere in the source code so that MASM can connect your program with Comctl32.dll. To create a ToolTip control with CreateWindowEx, the typical code is as follows:
. Data
Tooltipclassname db "Tooltips_class32", 0
. Code
.....
Invoke InitCommonControls
Invoke CreateWindowEx, NULL, addr tooltipclassname, NULL, Tis_alwaystip, Cw_usedefault, Cw_usedefault, Cw_usedefault, CW _usedefault, NULL, NULL, HINSTANCE, NULL
Note Window style: tis_alwaystip Specifies a tooltip, regardless of the window state that contains the specified range, the ToolTip is always displayed when the mouse moves over the specified range. Simply put, the tooltip appears even if the window is inactive and the mouse is moved over the specified area of the ToolTip.
You don't have to include ws_popup and Ws_ex_toolwindow styles in CreateWindowEx, because the ToolTip processing is automatically added, and you don't have to specify the coordinates and width of the ToolTip window, and the control will automatically adjust according to the text you want to display. Four parameters, all using CW _usedefault, the rest of the parameters are not very important.
Specifying tools
The tooltip control was created but not yet displayed, and we want to display a ToolTip window when the mouse pointer is over a range. You need to specify this area now. We call such areas "tools", "Tools" Is the tooltip control that monitors whether the mouse pointer moves through a square area in the client area of the window. If the mouse pointer moves over the tool, the ToolTip window appears. Tool can cover the entire customer area or just a part of it. So we divide the "tools" into two types, one as a window and the other as part of a client area of a window. Two different kinds of use. Tools that cover the entire customer area are typically used for buttons, edit controls, and so on, and you don't have to specify the coordinates and size of the focus field. : It is assumed to be the entire client area of the window. A "tool" that covers only a portion of the window client area is especially useful when you want to divide the client area of the window into sections but you don't want to use a child window, but you need to specify the coordinates and width of the upper left corner.

Use the following TOOLINFO structure to define "tools":

Toolinfo STRUCT
cbsize DWORD?
Uflags DWORD?
HWnd DWORD?
UId DWORD?
Rect rect <>
hinst DWORD?
Lpsztext DWORD?
LParam LParam? The
toolinfo ENDS
Domain name describes the size of the
cbsize toolinfo structure. Must be populated, if the area is not properly populated Windows does not error, but you will get unexpected strange results. The
Uflags specifies the properties of the Focus field, which can be a union of the following flags:
Ttf_idishwnd "ID is HWnd". If you specify this flag, you will use the "Tools" (The first "tools") that cover the entire client area. If you use this sign, , you have to populate the UID member with the window handle you want to use, and if you don't specify this member, it means you want to use the second "tool" and the square area of the client Area window. In this case, you must fill the RECT member with the size of the square area.
Ttf_centertip The ToolTip window is usually displayed at the bottom right of the mouse, and if you specify this flag, the ToolTip will always appear below the focus field, regardless of the mouse position.
Ttf_rtlreading. If your program is not designed for Arabic or Hebrew systems, you can ignore it, making prompt text appear in Right-to-left order and not in other systems.
Ttf_subclass If you use this flag, the ToolTip control will subclass the tool window to intercept the mouse message sent to it, which is useful, otherwise you will have to do more work to forward the message to the ToolTip control.

The hWnd contains the window handle for the tool, and if you specify the TTF_IDISHWND flag, Windows ignores the value and uses the value of the UID member as the window handle. You need to populate this domain domain if:
You do not use the TTF_IDISHWND flag (in other words, you use local "tools")
You specified the Lpstr_textcallback in the Lpsztext member. This value tells the ToolTip control when you need to display a prompt window, you must query the window that contains the tool to see what should be displayed. This is a real-time control text update. If you need to dynamically change the hint text, you should specify the Lpstr_textcallback value in the Lpsztext member, and the control will send the TTN_NEEDTEXT message to the window specified by the HWND.

The value of the UId field may have two meanings, depending on whether the uflags contains Ttf_idishwnd.
If the TTF_IDISHWND flag is not specified, it represents the application-defined tool ID. Since this means that you use a "tool" that covers only a portion of the client area, the logical introduction of a client area may have multiple same focus domains (no overlap), and one window handle to an HWND member is not enough, The application definition ID is necessary to differentiate them, as long as the unique ID can be any value.
If the TTF_IDISHWND flag is specified to indicate that the entire client area is the window handle of the focus field, you may wonder why the window handle is not stored without the value of the HWND member mentioned above. The answer is: If Lpsztext is specified as Lpstr_textcallback, The Hwnd may have been populated. There are also windows that provide prompt text and windows that contain tools may not be the same! (You can design a window program to provide two kinds of services, but too strict, at this point, Microsoft provides us with greater freedom, cheers!)

RECT specifies the RECT structure of the tool size. This structure defines a square size that is based on the upper-left corner of the client area in the HWND-specified window, in short, if you want to specify a portion of the client area as a "tool" to populate this structure, if you specify the TTF_IDISHWND flag, Control ignores this value. (You have selected the entire client area as a "tool")
Hinst if lpsztext specifies the identity of the string resource, contains the instance handle that will be used as the tool to extract the text string resource. It sounds a bit confusing, read the instructions of Lpsztext to understand what this domain is for. If Lpsztext does not contain a string resource identifier, Control ignores this field.
Lpsztext This field can have several values as follows:
If specified as Lpstr_textcallback, the ToolTip control sends a TTN_NEEDTEXT message to the HWND window to obtain the string that will be displayed. Prompt text Dynamic Update method: Every time you display a prompt window, change the prompt text.
If you specify a string resource identifier in this field, when the control wants to display the prompt text in the prompt window, it searches for a list of string resources for instances of the Hinst member identity. Because the string resource list identity is always 16-bit, the high byte of this field will always be 0, which is useful when you want to migrate the program, Because the string resource is defined as a script, you do not have to modify the source code. Just modify the string list prompt text will change accordingly, without worrying about introducing bugs.
If the value of this field is not lpstr_textcallback and the high byte is not zero, the control intercepts this value as a pointer to the hint text, which is the simplest method but also the most unstable. Identifies the string resource by examining the high byte.

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.