?? tut27.html
字號:
<!doctype html public "-//w3c//dtd html 4.0 transitional//en">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<meta name="Author" content="Iczelion">
<meta name="GENERATOR" content="Mozilla/4.7 [en] (Win98; I) [Netscape]">
<title>Iczelion's Win32asm Tutorial 27: Tooltip Control</title>
</head>
<body text="#FFFFFF" bgcolor="#000080" link="#FFFF00" vlink="#8080FF" alink="#FF00FF">
<center>
<h1>
<font face="Tahoma"><font color="#FFFFCC">Tutorial 27: Tooltip Control</font></font></h1></center>
<font face="Tahoma">We will learn about the tooltip control: What it is
and how to create and use it. Download <a href="../../files/tut27.zip">the
example</a>.</font>
<h3>
<font face="Tahoma">Theory:</font></h3>
<font face="Tahoma">A tooltip is a small rectangular window that is displayed
when the mouse pointer hovers over some specific area. A tooltip window
contains some text that the programmer wants to be displayed. In this regard,
a tooltip servers the same role as the status window but it disappears
when the user clicks or moves the mouse pointer away from the designated
area. You'll probably be familiar with the tooltips that are associated
with toolbar buttons. Those "tooltips" are conveniencies provided by the
toolbar control. If you want tooltips for other windows/controls, you need
to create your own tooltip control.</font>
<br><font face="Tahoma">Now that you know what a tooltip is, let's go on
to how we can create and use it. The steps are outlined below:</font>
<ol>
<li>
<font face="Tahoma">Create a tooltip control with CreateWindowEx</font></li>
<li>
<font face="Tahoma">Define a region that the tooltip control will monitor
for mouse pointer movement.</font></li>
<li>
<font face="Tahoma">Submit the region to the tooltip control</font></li>
<li>
<font face="Tahoma">Relay mouse messages of the submitted region to the
tooltip control (this step may occur earlier, depending on the method used
to relay the messages)</font></li>
</ol>
<font face="Tahoma">We wll next examine each step in detail.</font>
<h4>
<font face="Tahoma">Tooltip Creation</font></h4>
<font face="Tahoma">A tooltip control is a common control. As such, you
need to call <b><font color="#FFFFCC">InitCommonControls</font></b> somewhere
in your source code so that MASM implicitly links your program to comctl32.dll.
You create a tooltip control with CreateWindowEx. The typical scenario
would be like this:</font>
<blockquote><b><font face="Tahoma"><font color="#99FF99">.data</font></font></b>
<br><b><font face="Tahoma"><font color="#99FF99">TooltipClassName db "Tooltips_class32",0</font></font></b>
<br><b><font face="Tahoma"><font color="#99FF99">.code</font></font></b>
<br><b><font face="Tahoma"><font color="#99FF99">.....</font></font></b>
<br><b><font face="Tahoma"><font color="#99FF99">invoke InitCommonControls</font></font></b>
<br><b><font face="Tahoma"><font color="#99FF99">invoke CreateWindowEx,
NULL, addr TooltipClassName, NULL, TIS_ALWAYSTIP, CW_USEDEFAULT, CW_USEDEFAULT,
CW_USEDEFAULT, CW_USEDEFAULT, NULL, NULL, hInstance, NULL</font></font></b></blockquote>
<font face="Tahoma">Note the window style: <b><font color="#FFFFCC">TIS_ALWAYSTIP</font></b>.
This style specifies that the tooltip will be shown when the mouse pointer
is over the designated area regardless of the status of the window that
contains the area. Put simply, if you use this flag, when the mouse pointer
hovers over the area you register to the tooltip control, the tooltip window
will appear even if the window under the mouse pointer is inactive.</font>
<br><font face="Tahoma">You don't have to include <b><font color="#FFFFCC">WS_POPUP</font></b>
and <b><font color="#FFFFCC">WS_EX_TOOLWINDOW</font></b> styles in CreateWindowEx
because the tooltip control's window procedure adds them automatically.
You also don't need to specify the coordinate, the height and width of
the tooltip window: the tooltip control will adjust them automatically
to fit the tooltip text that will be displayed, thus we supply <b><font color="#FFFFCC">CW_USEDEFAULT</font></b>
in all four parameters. The remaining parameters are not remarkable.</font>
<h4>
<font face="Tahoma">Specifying the tool</font></h4>
<font face="Tahoma">The tooltip control is created but it's not shown immediately.
We want the tooltip window to show up when the mouse pointer hovers over
some area. Now is the time to specify that area. We call such area "<b><font color="#FFFFCC">tool</font></b>".
A tool is a rectangular area on the client area of a window which the tooltip
control will monitor for mouse pointer. If the mouse pointer hovers over
the tool, the tooltip window will appear. The rectangular area can cover
the whole client area or only a part of it. So we can divided tool into
two types: one that is implemented as a window and another that is implemented
as a rectangular area in the client area of some window. Both has their
uses. The tool that covers the whole client area of a window is most frequently
used with controls such as buttons, edit controls and so on. You don't
need to specify the coordinate and the dimensions of the tool: it's assumed
to be the whole client area of the window. The tool that is implemented
as a rectangular area on the client area is useful when you want to divide
the client area of a window into several regions without using child windows.
With this type of tool, you need to specify the coordinate of the upper
left corner and the width and height of the tool.</font>
<br><font face="Tahoma">You specify the tool with the<b><font color="#99FF99">
TOOLINFO</font></b> structure which has the following definition:</font>
<blockquote><b><tt><font color="#99FF99">TOOLINFO STRUCT</font></tt></b>
<br><b><tt><font color="#99FF99"> cbSize
DWORD ?</font></tt></b>
<br><b><tt><font color="#99FF99"> uFlags
DWORD ?</font></tt></b>
<br><b><tt><font color="#99FF99"> hWnd
DWORD ?</font></tt></b>
<br><b><tt><font color="#99FF99"> uId
DWORD ?</font></tt></b>
<br><b><tt><font color="#99FF99"> rect
RECT <></font></tt></b>
<br><b><tt><font color="#99FF99"> hInst
DWORD ?</font></tt></b>
<br><b><tt><font color="#99FF99"> lpszText
DWORD ?</font></tt></b>
<br><b><tt><font color="#99FF99"> lParam
LPARAM ?</font></tt></b>
<br><b><tt><font color="#99FF99">TOOLINFO ENDS</font></tt></b></blockquote>
<center><table BORDER >
<tr ALIGN=CENTER BGCOLOR="#666600">
<td>Field Name</td>
<td>Explanation</td>
</tr>
<tr>
<td><font face="Tahoma">cbSize</font></td>
<td><font face="Tahoma">The size of the TOOLINFO structure. You <b><font color="#FFFFCC">MUST</font></b>
fill this member. Windows will not flag error if this field is not filled
properly but you will receive strange, unpredictable results.</font></td>
</tr>
<tr>
<td><font face="Tahoma">uFlags</font></td>
<td><font face="Tahoma">The bit flags that specifies the characteristics
of the tool. This value can be a combination of the following flags:</font>
<ul>
<li>
<font face="Tahoma"><b><font color="#66FF99">TTF_IDISHWND</font></b>
"ID is hWnd". If you specify this flag, it means you want to use a tool
that covers the whole client area of a window (the first type of tool above).
If you use this flag, you <b><font color="#FFFF99">must</font></b> fill
the <b><font color="#FFFF99">uId
</font></b>member of this structure with
the handle of the window you want to use. If you don't specify this flag,
it means you want to use the second type of tool, the one that is implemented
as the rectangular area on the client window. In that case, you need to
fill the <b><font color="#FFFF99">rect
</font></b>member with the dimension
of the rectangle.</font></li>
<li>
<font face="Tahoma"><b><font color="#66FF99">TTF_CENTERTIP </font></b>Normally
the tooltip window will appear to the right and below the mouse pointer.
If you specify this flag, the tooltip window will always appear directly
below the tool and is centered regardless of the position of the mouse
pointer.</font></li>
<li>
<font face="Tahoma"><b><font color="#99FF99">TTF_RTLREADING</font></b>
You can forget about this flag if your program is not designed specifically
for Arabic or Hebrew systems. This flag displays the tooltip text with
right-to-left reading order. Doesn't work under other systems.</font></li>
<li>
<font face="Tahoma"><b><font color="#66FF99">TTF_SUBCLASS</font></b>
If you use this flag, it means you tell the tooltip control to subclass
the window that the tool is on so that the tooltip control can intercept
mouse messages that are sent to the window. This flag is very handy. If
you don't use this flag, you have to do more work to relay the mouse messages
to the tooltip control.</font></li>
</ul>
</td>
</tr>
<tr>
<td><font face="Tahoma">hWnd</font></td>
<td><font face="Tahoma">Handle to the window that contains the tool. If
you specify<b><font color="#66FF99"> TTF_IDISHWND</font></b> flag, this
field is ignored since Windows will use the value in <b><font color="#FFFF99">uId</font></b>
member as the window handle. You need to fill this field if:</font>
<ul>
<li>
<font face="Tahoma">You don't use <b><font color="#66FF99">TTF_IDISHWND</font></b>
flag (in other words, you use a rectangular tool)</font></li>
<li>
<font face="Tahoma">You specify the value <b><font color="#66FF99">LPSTR_TEXTCALLBACK</font></b>
in <b><font color="#FFFF99">lpszText</font></b> member. This value tells
the tooltip control that, when it needs to display the tooltip window,
it must ask the window that contains the tool for the text to be displayed.
This is a kind of dynamic realtime tooltip text update. If you want to
change your tooltip text dynamically, you should specify <b><font color="#66FF99">LPSTR_TEXTCALLBACK</font></b>
value in <b><font color="#FFFF99">lpszText</font></b> member. 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.</font></li>
</ul>
</td>
</tr>
<tr>
<td><font face="Tahoma">uId</font></td>
<td><font face="Tahoma">The value in this field can have two meanings,
depending on whether the <b><font color="#FFFF99">uFlags</font></b> member
contains the flag
<b><font color="#66FF99">TTF_IDISHWND</font></b>.</font>
<ul>
<li>
<font face="Tahoma">Application-defined tool ID if the <b><font color="#66FF99">TTF_IDISHWND
</font></b>flag
is not specified. Since this means you use a tool which covers only a part
of the client area, it's logical that you can have many such tools on the
same client area (without overlap). The tooltip control needs a way to
differentiate between them. In this case, the window handle in hWnd member
is not enough since all tools are on the same window. The application-defined
IDs are thus necessary. The IDs can be any value so long as they are unique
among themselves.</font></li>
<li>
<font face="Tahoma">The handle to the window whose whole client area is
used as the tool if the <b><font color="#66FF99">TTF_IDISHWND</font></b>
flag is specified. You may wonder why this field is used to store the window
handle instead of the <b><font color="#FFFF99">hWnd</font></b> field above.
The answer is: the hWnd member may already be filled if the value <b><font color="#66FF99">LPSTR_TEXTCALLBACK</font></b>
is specified in the <b><font color="#FFFF99">lpszText</font></b> member
and the window that is responsible for supplying the tooltip text and the
window that contains the tool may <b><font color="#FFFF99">NOT</font></b>
be the same ( You can design your program so that a single window can serve
both roles but this is too restrictive. In this case, Microsoft gives you
more freedom. Cheers.)</font></li>
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -