📄 tut27.html
字号:
</ul>
</td>
</tr>
<tr>
<td><font face="Tahoma">rect</font></td>
<td><font face="Tahoma">A <b><font color="#66FF99">RECT</font></b> structure
that specifies the dimension of the tool. This structure defines a rectangle
relative to the upper left corner of the client area of the window specified
by the <b><font color="#FFFF99">hWnd </font></b>member. In short, you must
fill this structure if you want to specify a tool that covers only a part
of the client area. The tooltip control will ignore this field if you specify
<b><font color="#66FF99">TTF_IDISHWND</font></b>
flag (you choose to use a tool that covers the whole client area)</font></td>
</tr>
<tr>
<td><font face="Tahoma">hInst</font></td>
<td><font face="Tahoma">The handle of the instance that contains the string
resource that will be used as the tooltip text if the value in the <b><font color="#FFFF99">lpszText</font></b>
member specifies the string resource identifier. This may sound confusing.
Read the explanation of the <b><font color="#FFFF99">lpszText</font></b>
member first and you will understand what this field is used for. The tooltip
control ignores this field if the <b><font color="#FFFF99">lpszText </font></b>field
doesn't contain a string resource identifier.</font></td>
</tr>
<tr>
<td><font face="Tahoma">lpszText</font></td>
<td><font face="Tahoma">This field can have several values:</font>
<ul>
<li>
<font face="Tahoma">If you specify the value <b><font color="#66FF99">LPSTR_TEXTCALLBACK
</font></b>in this field, the tooltip control will send <b><font color="#66FF99">TTN_NEEDTEXT</font></b>
notification message to the window identified by the handle in <b><font color="#FFFF99">hWnd</font></b>
field for the text string to be displayed in the tooltip window. This is
the most dynamic method of tooltip text update: you can change the tooltip
text each time the tooltip window is displayed.</font></li>
<li>
<font face="Tahoma">If you specify a string resource identifier in this
field, when the tooltip control needs to display the tooltip text in the
tooltip window, it searches for the string in the string table of the instance
specified by <b><font color="#FFFF99">hInst</font></b> member. The tooltip
control identifies a string resource identifier by checking the high word
of this field. Since a string resource identifier is a 16-bit value, the
high word of this field will always be zero. This method is useful if you
plan to port your program to other languages. Since the string resource
is defined in a resource script, you don't need to modify the source code.You
only have to modify the string table and the tooltip texts will change
without the risk of introducing bugs into your program.</font></li>
<li>
<font face="Tahoma">If the value in this field is not <b><font color="#66FF99">LPSTR_TEXTCALLBACK</font></b>
and the high word is not zero, the tooltip control interprets the value
as the pointer to a text string that will be used as the tooltip text.
This method is the easiest to use but the least flexible.</font></li>
</ul>
</td>
</tr>
</table></center>
<p><font face="Tahoma">To recapitulate, you need to fill the <b><font color="#66FF99">TOOLINFO</font></b>
structure prior to submitting it to the tooltip control. This structure
describes the characteristics of the tool you desire.</font>
<h4>
<font face="Tahoma">Register the tool with the tooltip control</font></h4>
<font face="Tahoma">After you fill the <b><font color="#66FF99">TOOLINFO</font></b>
structure, you must submit it to tooltip control. A tooltip control can
service many tools so it is usually unnecessary to create more than one
tooltip control for a window. To register a tool with a tooltip control,
you send the <b><font color="#FFFF99">TTM_ADDTOOL</font></b> message to
the tooltip control. The <b><font color="#66FF99">wParam</font></b> is
not used and the<b><font color="#66FF99"> lParam</font></b> must contain
the address of the <b><font color="#66FF99">TOOLINFO</font></b> structure
you want to register.</font>
<blockquote><font face="Tahoma">.data?</font>
<br><font face="Tahoma">ti TOOLINFO <></font>
<br><font face="Tahoma">.......</font>
<br><font face="Tahoma">.code</font>
<br><font face="Tahoma">.......</font>
<br><font face="Tahoma"><fill the TOOLINFO structure></font>
<br><font face="Tahoma">.......</font>
<br><font face="Tahoma">invoke SendMessage, hwndTooltip, TTM_ADDTOOL, NULL,
addr ti</font></blockquote>
<font face="Tahoma"><b><font color="#FFFF99">SendMessage</font></b> for
this message will return <b><font color="#FFCC33">TRUE</font></b> if the
tool is successfully registered with the tooltip control, <b><font color="#FFCC33">FALSE</font></b>
otherwise.</font>
<br><font face="Tahoma">You can unregister the tool by sending <b><font color="#FFFF99">TTM_DELTOOL</font></b>
message to the tooltip control.</font>
<h4>
<font face="Tahoma">Relaying Mouse Messages to the Tooltip Control</font></h4>
<font face="Tahoma">When the above step is completed, the tooltip control
knows which area it should monitor for mouse messages and what text it
should display in the tooltip window. The only thing it lacks is the *trigger*
for that action. Think about it: the area specified by the tool is on the
client area of the other window. How can the tooltip control intercept
the mouse messages destined for that window? It needs to do so in order
that it can measure the amount of time the mouse pointer hovers over a
point in the tool so that when the specified amount of time elapses, the
tooltip control shows the tooltip window. There are two methods of accomplishing
this goal, one that requires the cooperation of the window that contains
the tool and the other without the cooperation on the part of the window.</font>
<ul>
<li>
<font face="Tahoma">The window that contains the tool must relay the mouse
messages to the tooltip control by sending <b><font color="#FFFF99">TTM_RELAYEVENT</font></b>
messages to the control. The <b><font color="#FFFF99">lParam</font></b>
of this message must contain the address of a <b><font color="#66FF99">MSG</font></b>
structure that specifies the message to be relayed to the tooltip control.
A tooltip control processes only the following mouse messages:</font></li>
<ul>
<li>
<b><font face="Tahoma"><font color="#FFCC33">WM_LBUTTONDOWN</font></font></b></li>
<li>
<b><font face="Tahoma"><font color="#FFCC33">WM_MOUSEMOVE</font></font></b></li>
<li>
<b><font face="Tahoma"><font color="#FFCC33">WM_LBUTTONUP</font></font></b></li>
<li>
<b><font face="Tahoma"><font color="#FFCC33">WM_RBUTTONDOWN</font></font></b></li>
<li>
<b><font face="Tahoma"><font color="#FFCC33">WM_MBUTTONDOWN</font></font></b></li>
<li>
<b><font face="Tahoma"><font color="#FFCC33">WM_RBUTTONUP</font></font></b></li>
<li>
<b><font face="Tahoma"><font color="#FFCC33">WM_MBUTTONUP</font></font></b></li>
</ul>
<font face="Tahoma">All other messages are ignored. Thus in the window
procedure of the window that contains the tool, there must be a switch
that does something like this:</font><font face="Tahoma"></font>
<p><b><font face="Tahoma"><font color="#66FF99">WndProc proc hWnd:DWORD,
uMsg:DWORD, wParam:DWORD, lParam:DWORD</font></font></b>
<br><b><font face="Tahoma"><font color="#66FF99">.......</font></font></b>
<br><b><font face="Tahoma"><font color="#66FF99"> </font><font color="#FFCC33">
if</font><font color="#66FF99"> </font><font color="#FF99FF">uMsg==WM_CREATE</font></font></b>
<br><b><font face="Tahoma"><font color="#66FF99">
.............</font></font></b>
<br><b><font face="Tahoma"><font color="#66FF99"> </font><font color="#FFCC33">elseif</font><font color="#66FF99">
</font><font color="#FF99FF">uMsg==WM_LBUTTONDOWN || uMsg==WM_MOUSEMOVE
|| uMsg==WM_LBUTTONUP || uMsg==WM_RBUTTONDOWN || uMsg==WM_MBUTTONDOWN ||
uMsg==WM_RBUTTONUP || uMsg==WM_MBUTTONUP</font></font></b>
<br><b><font face="Tahoma"><font color="#66FF99">
invoke SendMessage, hwndTooltip, TTM_RELAYEVENT, NULL, addr msg</font></font></b>
<br><b><font face="Tahoma"><font color="#66FF99">
..........</font></font></b>
<li>
<font face="Tahoma">You can specify <b><font color="#66FF99">TTF_SUBCLASS</font></b>
flag in the<b><font color="#FFFF99"> uFlags</font></b> member of the <b><font color="#66FF99">TOOLINFO</font></b>
structure. This flag tells the tooltip control to subclass the window that
contains the tool so it can intercept the mouse messages without the cooperation
of the window. This method is easier to use since it doesn't require more
coding than specifying <b><font color="#66FF99">TTF_SUBCLASS</font></b>
flag and the tooltip control handles all the message interception itself.</font></li>
</ul>
<font face="Tahoma">That's it. At this step, your tooltip control is fully
functional. There are several useful tooltip-related messages you should
know about.</font>
<ul>
<li>
<font face="Tahoma"><b><font color="#FFFF99">TTM_ACTIVATE.</font></b>
If you want to disable/enable the tooltip control dynamically, this message
is for you. If the wParam value is <b><font color="#FFCC33">TRUE</font></b>,
the tooltip control is enabled. If the wParam value is <b><font color="#FFCC33">FALSE</font></b>,
the tooltip control is disabled. A tooltip control is enabled when it first
created so you don't need to send this message to activate it.</font></li>
<li>
<font face="Tahoma"><b><font color="#FFFF99">TTM_GETTOOLINFO </font></b>and
<b><font color="#FFFF99">TTM_SETTOOLINFO</font></b>. If you want to obtain/change
the values in the TOOLINFO structure after it was submitted to the tooltip
control, use these messages. You need to specify the tool you need to change
with the correct uId and hWnd values. If you only want to change the rect
member, use <b><font color="#FFFF99">TTM_NEWTOOLRECT</font></b> message.
If you only want to change the tooltip text, use <b><font color="#FFFF99">TTM_UPDATETIPTEXT</font></b>.</font></li>
<li>
<font face="Tahoma"><b><font color="#FFFF99">TTM_SETDELAYTIME</font></b>.
With this message, you can specify the time delay the tooltip control uses
when it's displaying the tooltip text and much more.</font></li>
</ul>
<h3>
<font face="Tahoma">Example:</font></h3>
<font face="Tahoma">The following example is a simple dialog box with two
buttons. The client area of the dialog box is divided into 4 areas: upper
left, upper right, lower left and lower right. Each area is specified as
a tool with its own tooltip text. The two buttons also has their own tooltip
texts.</font>
<blockquote><b><tt>.386</tt></b>
<br><b><tt>.model flat,stdcall</tt></b>
<br><b><tt>option casemap:none</tt></b>
<br><b><tt>include \masm32\include\windows.inc</tt></b>
<br><b><tt>include \masm32\include\kernel32.inc</tt></b>
<br><b><tt>include \masm32\include\user32.inc</tt></b>
<br><b><tt>include \masm32\include\comctl32.inc</tt></b>
<br><b><tt>includelib \masm32\lib\comctl32.lib</tt></b>
<br><b><tt>includelib \masm32\lib\user32.lib</tt></b>
<br><b><tt>includelib \masm32\lib\kernel32.lib</tt></b>
<br><b><tt>DlgProc proto :DWORD,:DWORD,:DWORD,:DWORD</tt></b>
<br><b><tt>EnumChild proto :DWORD,:DWORD</tt></b>
<br><b><tt>SetDlgToolArea proto :DWORD,:DWORD,:DWORD,:DWORD,:DWORD</tt></b>
<br><b><tt>.const</tt></b>
<br><b><tt>IDD_MAINDIALOG equ 101</tt></b>
<br><b><tt>.data</tt></b>
<br><b><tt>ToolTipsClassName db "Tooltips_class32",0</tt></b>
<br><b><tt>MainDialogText1 db "This is the upper left area of the dialog",0</tt></b>
<br><b><tt>MainDialogText2 db "This is the upper right area of the dialog",0</tt></b>
<br><b><tt>MainDialogText3 db "This is the lower left area of the dialog",0</tt></b>
<br><b><tt>MainDialogText4 db "This is the lower right area of the dialog",0</tt></b>
<br><b><tt>.data?</tt></b>
<br><b><tt>hwndTool dd ?</tt></b>
<br><b><tt>hInstance dd ?</tt></b>
<br><b><tt>.code</tt></b>
<br><b><tt>start:</tt></b>
<br><b><tt> invoke GetModuleHandle,NULL</tt></b>
<br><b><tt> mov hInstance,eax</tt></b>
<br><b><tt> invoke DialogBoxParam,hInstance,IDD_MAINDIALOG,NULL,addr
DlgProc,NULL</tt></b>
<br><b><tt> invoke ExitProcess,eax</tt></b><b><tt></tt></b>
<p><b><tt>DlgProc proc hDlg:DWORD,uMsg:DWORD,wParam:DWORD,lParam:DWORD</tt></b>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -