?? lion-tutorial27.htm
字號(hào):
<td>hInst</td>
<td>The handle of the instance that contains the string resource that will
be used as the tooltip text if the value in the <b>lpszText</b> member
specifies the string resource identifier. This may sound confusing. Read
the explanation of the <b>lpszText</b> member first and you will understand
what this field is used for. The tooltip control ignores this field if
the <b>lpszText </b>field doesn't contain a string resource identifier.</td>
</tr>
<tr>
<td>lpszText</td>
<td>This field can have several values:
<ul>
<li> If you specify the value <b>LPSTR_TEXTCALLBACK </b>in this field,
the tooltip control will send <b>TTN_NEEDTEXT</b> notification message
to the window identified by the handle in <b>hWnd</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.</li>
<li> 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>hInst</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.</li>
<li> If the value in this field is not <b>LPSTR_TEXTCALLBACK</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.</li>
</ul>
</td>
</tr>
</table>
</center>
<p>To recapitulate, you need to fill the <b>TOOLINFO</b> structure prior to submitting
it to the tooltip control. This structure describes the characteristics of the
tool you desire.
<h4> Register the tool with the tooltip control</h4>
After you fill the <b>TOOLINFO</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>TTM_ADDTOOL</b> message to the tooltip control. The <b>wParam</b>
is not used and the<b> lParam</b> must contain the address of the <b>TOOLINFO</b>
structure you want to register.
<blockquote>.data? <br>
ti TOOLINFO <> <br>
....... <br>
.code <br>
....... <br>
<fill the TOOLINFO structure> <br>
....... <br>
invoke SendMessage, hwndTooltip, TTM_ADDTOOL, NULL, addr ti</blockquote>
<b>SendMessage</b> for this message will return <b>TRUE</b> if the tool is successfully
registered with the tooltip control, <b>FALSE</b> otherwise. <br>
You can unregister the tool by sending <b>TTM_DELTOOL</b> message to the tooltip
control.
<h4> Relaying Mouse Messages to the Tooltip Control</h4>
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.
<ul>
<li> The window that contains the tool must relay the mouse messages to the
tooltip control by sending <b>TTM_RELAYEVENT</b> messages to the control.
The <b>lParam</b> of this message must contain the address of a <b>MSG</b>
structure that specifies the message to be relayed to the tooltip control.
A tooltip control processes only the following mouse messages:</li>
<ul>
<li> <b>WM_LBUTTONDOWN</b></li>
<li> <b>WM_MOUSEMOVE</b></li>
<li> <b>WM_LBUTTONUP</b></li>
<li> <b>WM_RBUTTONDOWN</b></li>
<li> <b>WM_MBUTTONDOWN</b></li>
<li> <b>WM_RBUTTONUP</b></li>
<li> <b>WM_MBUTTONUP</b></li>
</ul>
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:
<p><b>WndProc proc hWnd:DWORD, uMsg:DWORD, wParam:DWORD, lParam:DWORD</b> <br>
<b>.......</b> <br>
<b> if uMsg==WM_CREATE</b> <br>
<b> .............</b> <br>
<b> elseif uMsg==WM_LBUTTONDOWN || uMsg==WM_MOUSEMOVE ||
uMsg==WM_LBUTTONUP || uMsg==WM_RBUTTONDOWN || uMsg==WM_MBUTTONDOWN || uMsg==WM_RBUTTONUP
|| uMsg==WM_MBUTTONUP</b> <br>
<b> invoke SendMessage, hwndTooltip,
TTM_RELAYEVENT, NULL, addr msg</b> <br>
<b> ..........</b>
<li> You can specify <b>TTF_SUBCLASS</b> flag in the<b> uFlags</b> member of
the <b>TOOLINFO</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>TTF_SUBCLASS</b> flag and the tooltip
control handles all the message interception itself.</li>
</ul>
That's it. At this step, your tooltip control is fully functional. There are several
useful tooltip-related messages you should know about.
<ul>
<li> <b>TTM_ACTIVATE.</b> If you want to disable/enable the tooltip control
dynamically, this message is for you. If the wParam value is <b>TRUE</b>,
the tooltip control is enabled. If the wParam value is <b>FALSE</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.</li>
<li> <b>TTM_GETTOOLINFO </b>and <b>TTM_SETTOOLINFO</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>TTM_NEWTOOLRECT</b> message. If you only want to change the
tooltip text, use <b>TTM_UPDATETIPTEXT</b>.</li>
<li> <b>TTM_SETDELAYTIME</b>. With this message, you can specify the time delay
the tooltip control uses when it's displaying the tooltip text and much more.</li>
</ul>
<h3> Example:</h3>
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.
<blockquote> .386 <br>
.model flat,stdcall <br>
option casemap:none <br>
include \masm32\include\windows.inc <br>
include \masm32\include\kernel32.inc <br>
include \masm32\include\user32.inc <br>
include \masm32\include\comctl32.inc <br>
includelib \masm32\lib\comctl32.lib <br>
includelib \masm32\lib\user32.lib <br>
includelib \masm32\lib\kernel32.lib <br>
DlgProc proto :DWORD,:DWORD,:DWORD,:DWORD <br>
EnumChild proto :DWORD,:DWORD <br>
SetDlgToolArea proto :DWORD,:DWORD,:DWORD,:DWORD,:DWORD <br>
.const <br>
IDD_MAINDIALOG equ 101 <br>
.data <br>
ToolTipsClassName db "Tooltips_class32",0 <br>
MainDialogText1 db "This is the upper left area of the dialog",0 <br>
MainDialogText2 db "This is the upper right area of the dialog",0 <br>
MainDialogText3 db "This is the lower left area of the dialog",0 <br>
MainDialogText4 db "This is the lower right area of the dialog",0 <br>
.data? <br>
hwndTool dd ? <br>
hInstance dd ? <br>
.code <br>
start: <br>
invoke GetModuleHandle,NULL <br>
mov hInstance,eax <br>
invoke DialogBoxParam,hInstance,IDD_MAINDIALOG,NULL,addr
DlgProc,NULL <br>
invoke ExitProcess,eax DlgProc proc hDlg:DWORD,uMsg:DWORD,wParam:DWORD,lParam:DWORD
<br>
LOCAL ti:TOOLINFO <br>
LOCAL id:DWORD <br>
LOCAL rect:RECT <br>
.if uMsg==WM_INITDIALOG <br>
invoke InitCommonControls
<br>
invoke CreateWindowEx,NULL,ADDR
ToolTipsClassName,NULL,\ <br>
TTS_ALWAYSTIP,CW_USEDEFAULT,\
<br>
CW_USEDEFAULT,CW_USEDEFAULT,CW_USEDEFAULT,NULL,NULL,\
<br>
hInstance,NULL
<br>
mov hwndTool,eax <br>
mov id,0 <br>
mov ti.cbSize,sizeof TOOLINFO
<br>
mov ti.uFlags,TTF_SUBCLASS
<br>
push hDlg <br>
pop ti.hWnd <br>
invoke GetWindowRect,hDlg,addr
rect <br>
invoke SetDlgToolArea,hDlg,addr
ti,addr MainDialogText1,id,addr rect <br>
inc id <br>
invoke SetDlgToolArea,hDlg,addr
ti,addr MainDialogText2,id,addr rect <br>
inc id <br>
invoke SetDlgToolArea,hDlg,addr
ti,addr MainDialogText3,id,addr rect <br>
inc id <br>
invoke SetDlgToolArea,hDlg,addr
ti,addr MainDialogText4,id,addr rect <br>
invoke EnumChildWindows,hDlg,addr
?? 快捷鍵說(shuō)明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -