-
Notifications
You must be signed in to change notification settings - Fork 141
Expand file tree
/
Copy pathToolTipEx.cpp
More file actions
235 lines (207 loc) · 7.59 KB
/
ToolTipEx.cpp
File metadata and controls
235 lines (207 loc) · 7.59 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
// ToolTipEx.cpp : implementation file
//
/////////////////////////////////////////////////////////////////////////////
// Copyright (C) 1998 by Shane Martin
// All rights reserved
//
// Distribute freely, except: don't remove my name from the source or
// documentation (don't take credit for my work), mark your changes (don't
// get me blamed for your possible bugs), don't alter or remove this
// notice.
// No warrantee of any kind, express or implied, is included with this
// software; use at your own risk, responsibility for damages (if any) to
// anyone resulting from the use of this software rests entirely with the
// user.
//
// Send bug reports, bug fixes, enhancements, requests, flames, etc., and
// I'll try to keep a version up to date. I can be reached as follows:
/////////////////////////////////////////////////////////////////////////////
// last revised: 19 Apr 98
// ToolTipEx.cpp : implementation file
//
// Description:
// CToolTipEx provides additional features to the standard tooltip
// control "CToolTipCtrl".
// To use you must have the latest (as of Apr 98) commctrl.h and
// commctrl.dll (the one that came with IE4 is fine).
// Usage:
// Add a variable to your mainfrm.h for CToolTipEx.
// In your mainfrm.cpp's OnCreate add a line setting the toolbar's
// tooltip control to the variable you declared, such as:
// m_wndToolBar.GetToolBarCtrl().SetToolTips(&MyToolTipCtrl);
// To get a pointer to your new tooltip you will need to use:
// _AFX_THREAD_STATE* pThreadState = AfxGetThreadState();
// CToolTipEx* pToolTip = (CToolTipEx*)pThreadState->m_pToolTip;
// If you have any further question you can check the help file that
// was included, or send me an email.
#include "stdafx.h"
#include "ToolTipEx.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CToolTipEx
CToolTipEx::CToolTipEx()
{
}
CToolTipEx::~CToolTipEx()
{
}
BEGIN_MESSAGE_MAP(CToolTipEx, CToolTipCtrl)
//{{AFX_MSG_MAP(CToolTipEx)
// NOTE - the ClassWizard will add and remove mapping macros here.
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CToolTipEx message handlers
COLORREF CToolTipEx::SetBkColor(COLORREF crColor)
{
COLORREF oldColor;
oldColor = SendMessage(TTM_GETTIPBKCOLOR, 0, 0);
SendMessage(TTM_SETTIPBKCOLOR, (WPARAM)(COLORREF)crColor, 0);
return oldColor;
}
COLORREF CToolTipEx::SetTextColor(COLORREF crColor)
{
COLORREF oldColor;
oldColor = SendMessage(TTM_GETTIPTEXTCOLOR, 0, 0);
SendMessage(TTM_SETTIPTEXTCOLOR, (WPARAM)(COLORREF)crColor, 0);
return oldColor;
}
COLORREF CToolTipEx::GetBkColor()
{
return SendMessage(TTM_GETTIPBKCOLOR, 0, 0);
}
COLORREF CToolTipEx::GetTextColor()
{
return SendMessage(TTM_GETTIPTEXTCOLOR, 0, 0);
}
int CToolTipEx::SetDelayTime(DWORD dwType, int nTime)
{
// dwType can be one of the following:
// TTDT_AUTOPOP - The length of time the tooltip window
// remains visible if the pointer is stationary within a tool's
// bounding rectangle.
//
// TTDT_INITIAL - The length of time the pointer must
// remain stationary within a tool's bounding rectangle before
// the tooltip window appears.
//
// TTDT_RESHOW The length of time it takes for
// subsequent tooltip windows to appear as the pointer moves
// from one tool to another.
int nDuration;
switch(dwType)
{
case TTDT_AUTOPOP:
case TTDT_INITIAL:
case TTDT_RESHOW:
nDuration = SendMessage(TTM_GETDELAYTIME, (DWORD)dwType, 0);
SendMessage(TTM_SETDELAYTIME, (WPARAM)(DWORD)dwType, (LPARAM)(INT)MAKELONG(nTime, 0));
return nDuration;
}
return -1;
}
int CToolTipEx::GetDelayTime(DWORD dwType)
{
// dwType can be one of the following:
// TTDT_AUTOPOP - Retrieve the length of time the tooltip window
// remains visible if the pointer is stationary within a tool's
// bounding rectangle.
//
// TTDT_INITIAL - Retrieve the length of time the pointer must
// remain stationary within a tool's bounding rectangle before
// the tooltip window appears.
//
// TTDT_RESHOW Retrieve the length of time it takes for
// subsequent tooltip windows to appear as the pointer moves
// from one tool to another.
switch(dwType)
{
case TTDT_AUTOPOP:
case TTDT_INITIAL:
case TTDT_RESHOW:
return SendMessage(TTM_GETDELAYTIME, (DWORD)dwType, 0);
}
return -1;
}
void CToolTipEx::GetMargin(LPRECT lpRect)
{
// lpRect.top Distance between top border and top of tooltip
// text, in pixels.
// lpRect.left Distance between left border and left end of
// tooltip text, in pixels.
// lpRect.bottom Distance between bottom border and bottom of
// tooltip text, in pixels.
// lpRect.right Distance between right border and right end of
// tooltip text, in pixels
SendMessage(TTM_GETMARGIN, 0, (LPARAM)(LPRECT)lpRect);
}
int CToolTipEx::GetMaxTipWidth()
{
// The maximum tooltip width value does not indicate a tooltip
// window's actual width. Rather, if a tooltip string exceeds
// the maximum width, the control breaks the text into multiple
// lines, using spaces to determine line breaks. If the text
// cannot be segmented into multiple lines, it will be dis-
// played on a single line. The length of this line may exceed
// the maximum tooltip width.
// Defaults to -1 when tooltip control is first created.
return SendMessage(TTM_GETMAXTIPWIDTH, 0, 0);
}
RECT CToolTipEx::SetMargin(LPRECT lpRect)
{
// lpRect.top Distance between top border and top of tooltip
// text, in pixels.
// lpRect.left Distance between left border and left end of
// tooltip text, in pixels.
// lpRect.bottom Distance between bottom border and bottom of
// tooltip text, in pixels.
// lpRect.right Distance between right border and right end of
// tooltip text, in pixels.
RECT TempRect;
GetMargin(&TempRect);
SendMessage(TTM_SETMARGIN, 0, (LPARAM)(LPRECT)lpRect);
return TempRect;
}
int CToolTipEx::SetMaxTipWidth(int nWidth)
{
// The maximum tooltip width value does not indicate a tooltip
// window's actual width. Rather, if a tooltip string exceeds
// the maximum width, the control breaks the text into multiple
// lines, using spaces to determine line breaks. If the text
// cannot be segmented into multiple lines, it will be dis-
// played on a single line. The length of this line may exceed
// the maximum tooltip width.
return SendMessage(TTM_SETMAXTIPWIDTH, 0, (LPARAM)(INT)nWidth);
}
void CToolTipEx::TrackActivate(BOOL bActivate, LPTOOLINFO lpti)
{
SendMessage(TTM_TRACKACTIVATE, (WPARAM)(BOOL)bActivate,
(LPARAM)(LPTOOLINFO)lpti);
}
void CToolTipEx::TrackPosition(LPPOINT lppt)
{
// The tooltip control chooses where to display the tooltip
// window based on the coordinates you provide with this
// message. This causes the tooltip window to appear beside the
// tool to which it corresponds. To have tooltip windows
// displayed at specific coordinates, include the TTF_ABSOLUTE
// flag in the uFlags member of the TOOLINFO structure when
// adding the tool.
SendMessage(TTM_TRACKPOSITION, 0, (LPARAM)(DWORD)MAKELONG(lppt->x, lppt->y));
}
void CToolTipEx::TrackPosition(int xPos, int yPos)
{
// The tooltip control chooses where to display the tooltip
// window based on the coordinates you provide with this
// message. This causes the tooltip window to appear beside the
// tool to which it corresponds. To have tooltip windows
// displayed at specific coordinates, include the TTF_ABSOLUTE
// flag in the uFlags member of the TOOLINFO structure when
// adding the tool.
SendMessage(TTM_TRACKPOSITION, 0, (LPARAM)(DWORD)MAKELONG(xPos, yPos));
}