comparison foosdk/sdk/libPPUI/CPopupTooltipMessage.h @ 1:20d02a178406 default tip

*: check in everything else yay
author Paper <paper@tflc.us>
date Mon, 05 Jan 2026 02:15:46 -0500
parents
children
comparison
equal deleted inserted replaced
0:e9bb126753e7 1:20d02a178406
1 #pragma once
2
3 #include "win32_op.h"
4 #include "wtl-pp.h"
5
6 class CPopupTooltipMessage {
7 public:
8 CPopupTooltipMessage(DWORD style = TTS_BALLOON | TTS_NOPREFIX) : m_style(style | WS_POPUP), m_toolinfo(), m_shutDown() {}
9 void ShowFocus(const TCHAR * message, CWindow wndParent) {
10 Show(message, wndParent); wndParent.SetFocus();
11 }
12 void Show(const TCHAR * message, CWindow wndParent) {
13 if (m_shutDown || (message == NULL && m_tooltip.m_hWnd == NULL)) return;
14 Initialize();
15 Hide();
16
17 if (message != NULL) {
18 CRect rect;
19 WIN32_OP_D(wndParent.GetWindowRect(rect));
20 ShowInternal(message, wndParent, rect);
21 }
22 }
23 void ShowEx(const TCHAR * message, CWindow wndParent, CRect rect) {
24 if (m_shutDown) return;
25 Initialize();
26 Hide();
27 ShowInternal(message, wndParent, rect);
28 }
29 void Hide() {
30 if (m_tooltip.m_hWnd != NULL && m_tooltip.GetToolCount() > 0) {
31 m_tooltip.TrackActivate(&m_toolinfo, FALSE);
32 m_tooltip.DelTool(&m_toolinfo);
33 }
34 }
35
36 void CleanUp() {
37 if (m_tooltip.m_hWnd != NULL) {
38 m_tooltip.DestroyWindow();
39 }
40 }
41 void ShutDown() {
42 m_shutDown = true; CleanUp();
43 }
44 private:
45 void ShowInternal(const TCHAR * message, CWindow wndParent, CRect rect) {
46
47 PFC_ASSERT(!m_shutDown);
48 PFC_ASSERT(message != NULL);
49 PFC_ASSERT(wndParent != NULL);
50
51 if (_tcschr(message, '\n') != nullptr) {
52 m_tooltip.SetMaxTipWidth(rect.Width());
53 }
54 m_toolinfo.cbSize = sizeof(m_toolinfo);
55 m_toolinfo.uFlags = TTF_TRACK | TTF_IDISHWND | TTF_ABSOLUTE | TTF_TRANSPARENT | TTF_CENTERTIP;
56 m_toolinfo.hwnd = wndParent;
57 m_toolinfo.uId = 0;
58 m_toolinfo.lpszText = const_cast<TCHAR*>(message);
59 m_toolinfo.hinst = NULL; //core_api::get_my_instance();
60 if (m_tooltip.AddTool(&m_toolinfo)) {
61 m_tooltip.TrackPosition(rect.CenterPoint().x, rect.bottom);
62 m_tooltip.TrackActivate(&m_toolinfo, TRUE);
63 }
64 }
65 void Initialize() {
66 if (m_tooltip.m_hWnd == NULL) {
67 WIN32_OP(m_tooltip.Create(NULL, NULL, NULL, m_style));
68 }
69 }
70 CToolTipCtrl m_tooltip;
71 TOOLINFO m_toolinfo;
72 const DWORD m_style;
73 bool m_shutDown;
74 };
75
76
77 template<typename T> class CDialogWithTooltip : public CDialogImpl<T> {
78 public:
79 BEGIN_MSG_MAP_EX(CDialogWithTooltip)
80 MSG_WM_DESTROY(OnDestroy)
81 END_MSG_MAP()
82
83 void ShowTip(UINT id, const TCHAR * label) {
84 m_tip.Show(label, this->GetDlgItem(id));
85 }
86 void ShowTip(HWND child, const TCHAR * label) {
87 m_tip.Show(label, child);
88 }
89
90 void ShowTipF(UINT id, const TCHAR * label) {
91 m_tip.ShowFocus(label, this->GetDlgItem(id));
92 }
93 void ShowTipF(HWND child, const TCHAR * label) {
94 m_tip.ShowFocus(label, child);
95 }
96 void HideTip() { m_tip.Hide(); }
97 private:
98 void OnDestroy() { m_tip.ShutDown(); this->SetMsgHandled(FALSE); }
99 CPopupTooltipMessage m_tip;
100 };
101