?? lion-tutorial27.htm
字號:
<html>
<head>
<link rel="stylesheet" href="../../asm.css">
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>Iczelion's win32 asm tutorial</title>
</head>
<body bgcolor="#FFFFFF" background="../../images/back01.jpg">
<p align="center">Tutorial 27: Tooltip Control</p>
<hr size="1">
We will learn about the tooltip control: What it is and how to create and use
it. Download <a href="file:///E%7C/WebPages/files/tut27.zip">the example</a>.
<h3> Theory:</h3>
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. <br>
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:
<ol>
<li> Create a tooltip control with CreateWindowEx</li>
<li> Define a region that the tooltip control will monitor for mouse pointer
movement.</li>
<li> Submit the region to the tooltip control</li>
<li> 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)</li>
</ol>
We wll next examine each step in detail.
<h4> Tooltip Creation</h4>
A tooltip control is a common control. As such, you need to call <b>InitCommonControls</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:
<blockquote><b>.data</b> <br>
<b>TooltipClassName db "Tooltips_class32",0</b> <br>
<b>.code</b> <br>
<b>.....</b> <br>
<b>invoke InitCommonControls</b> <br>
<b>invoke CreateWindowEx, NULL, addr TooltipClassName, NULL, TIS_ALWAYSTIP,
CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, NULL, NULL, hInstance,
NULL</b></blockquote>
Note the window style: <b>TIS_ALWAYSTIP</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.
<br>
You don't have to include <b>WS_POPUP</b> and <b>WS_EX_TOOLWINDOW</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>CW_USEDEFAULT</b> in all four parameters.
The remaining parameters are not remarkable.
<h4> Specifying the tool</h4>
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>tool</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. <br>
You specify the tool with the<b> TOOLINFO</b> structure which has the following
definition:
<blockquote><b> TOOLINFO STRUCT </b> <br>
<b> cbSize
DWORD ? </b> <br>
<b> uFlags
DWORD ? </b> <br>
<b> hWnd
DWORD ? </b> <br>
<b> uId
DWORD ? </b> <br>
<b> rect
RECT <> </b> <br>
<b> hInst
DWORD ? </b> <br>
<b> lpszText
DWORD ? </b> <br>
<b> lParam
LPARAM ? </b> <br>
<b> TOOLINFO ENDS </b></blockquote>
<center>
<table BORDER >
<tr align=CENTER bgcolor="#666600">
<td>Field Name</td>
<td>Explanation</td>
</tr>
<tr>
<td>cbSize</td>
<td>The size of the TOOLINFO structure. You <b>MUST</b> fill this member.
Windows will not flag error if this field is not filled properly but you
will receive strange, unpredictable results.</td>
</tr>
<tr>
<td>uFlags</td>
<td>The bit flags that specifies the characteristics of the tool. This value
can be a combination of the following flags:
<ul>
<li> <b>TTF_IDISHWND</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>must</b> fill the <b>uId </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>rect </b>member with the dimension of
the rectangle.</li>
<li> <b>TTF_CENTERTIP </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.</li>
<li> <b>TTF_RTLREADING</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.</li>
<li> <b>TTF_SUBCLASS</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.</li>
</ul>
</td>
</tr>
<tr>
<td>hWnd</td>
<td>Handle to the window that contains the tool. If you specify<b> TTF_IDISHWND</b>
flag, this field is ignored since Windows will use the value in <b>uId</b>
member as the window handle. You need to fill this field if:
<ul>
<li> You don't use <b>TTF_IDISHWND</b> flag (in other words, you use
a rectangular tool)</li>
<li> You specify the value <b>LPSTR_TEXTCALLBACK</b> in <b>lpszText</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>LPSTR_TEXTCALLBACK</b> value in <b>lpszText</b>
member. The tooltip control will send <b>TTN_NEEDTEXT</b> notification
message to the window identified by the handle in <b>hWnd</b> field.</li>
</ul>
</td>
</tr>
<tr>
<td>uId</td>
<td>The value in this field can have two meanings, depending on whether
the <b>uFlags</b> member contains the flag <b>TTF_IDISHWND</b>.
<ul>
<li> Application-defined tool ID if the <b>TTF_IDISHWND </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.</li>
<li> The handle to the window whose whole client area is used as the
tool if the <b>TTF_IDISHWND</b> flag is specified. You may wonder
why this field is used to store the window handle instead of the <b>hWnd</b>
field above. The answer is: the hWnd member may already be filled
if the value <b>LPSTR_TEXTCALLBACK</b> is specified in the <b>lpszText</b>
member and the window that is responsible for supplying the tooltip
text and the window that contains the tool may <b>NOT</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.)</li>
</ul>
</td>
</tr>
<tr>
<td>rect</td>
<td>A <b>RECT</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>hWnd </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>TTF_IDISHWND</b> flag (you choose to use a tool that
covers the whole client area)</td>
</tr>
<tr>
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -