-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathTrackToolTip.cpp
77 lines (64 loc) · 2.11 KB
/
TrackToolTip.cpp
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
#include "precomp.h"
#include "TrackToolTip.hpp"
#include <commctrl.h>
TrackToolTip::TrackToolTip(wxWindow *owner, wxString text, bool bEnable /*= false*/)
{
INITCOMMONCONTROLSEX icex;
HWND hwndTT;
TOOLINFO ti;
// Load the ToolTip class from the DLL.
icex.dwSize = sizeof(icex);
icex.dwICC = ICC_BAR_CLASSES;
//m_bIsVisible = false;
if(!InitCommonControlsEx(&icex))
return;
// Create the ToolTip control.
hwndTT = CreateWindow(TOOLTIPS_CLASS, TEXT(""),
WS_POPUP,
CW_USEDEFAULT, CW_USEDEFAULT,
CW_USEDEFAULT, CW_USEDEFAULT,
NULL, (HMENU)NULL, GetModuleHandle(NULL),
NULL);
m_hWndParent = (HWND)owner->GetHandle();
m_text = text;
// Prepare TOOLINFO structure for use as tracking ToolTip.
ti.cbSize = sizeof(TOOLINFO);
ti.uFlags = TTF_IDISHWND | TTF_TRACK | TTF_ABSOLUTE;
ti.hwnd = m_hWndParent;
ti.uId = (UINT)ti.hwnd;
ti.hinst = GetModuleHandle(NULL);
ti.lpszText = (LPSTR)m_text.c_str();
ti.rect.left = ti.rect.top = ti.rect.bottom = ti.rect.right = 0;
// Add the tool to the control, displaying an error if needed.
if(!SendMessage(hwndTT,TTM_ADDTOOL,0,(LPARAM)&ti)){
wxLogDebug(_T("Failed to create the tooltip '%s'"), m_text.c_str());
return;
}
Enable(bEnable);
m_hWnd = hwndTT;
}
void TrackToolTip::Track(int x, int y)
{
SendMessage(m_hWnd, TTM_TRACKPOSITION, 0, MAKELPARAM(x, y));
}
void TrackToolTip::Enable(BOOL bEnable)
{
TOOLINFO ti;
ti.cbSize = sizeof(TOOLINFO);
ti.uFlags = TTF_IDISHWND;
ti.hwnd = m_hWndParent;
ti.uId = (UINT)ti.hwnd;
SendMessage(m_hWnd, TTM_TRACKACTIVATE, bEnable, (LPARAM)&ti);
}
void TrackToolTip::SetText(wxString text)
{
m_text = text;
TOOLINFO ti;
ti.cbSize = sizeof(TOOLINFO);
ti.uFlags = TTF_IDISHWND;
ti.hwnd = m_hWndParent;
ti.uId = (UINT)ti.hwnd;
ti.hinst = GetModuleHandle(NULL);
ti.lpszText = (LPSTR)m_text.c_str();
SendMessage(m_hWnd, TTM_UPDATETIPTEXT, 0, (LPARAM)&ti);
}