xref: /reactos/sdk/include/reactos/ui/rosctrls.h (revision a6bf77e7)
1 
2 #pragma once
3 
4 class CListView: public CWindow
5 {
6 public:
7 
8     HWND Create(HWND hWndParent, _U_RECT rect, LPCTSTR szWindowName = NULL, DWORD dwStyle = 0,
9                     DWORD dwExStyle = 0, _U_MENUorID MenuOrID = 0U, LPVOID lpCreateParam = NULL)
10     {
11         m_hWnd = ::CreateWindowEx(dwExStyle,
12                                   WC_LISTVIEW,
13                                   szWindowName,
14                                   dwStyle,
15                                   rect.m_lpRect->left,
16                                   rect.m_lpRect->top,
17                                   rect.m_lpRect->right - rect.m_lpRect->left,
18                                   rect.m_lpRect->bottom - rect.m_lpRect->top,
19                                   hWndParent,
20                                   MenuOrID.m_hMenu,
21                                   _AtlBaseModule.GetModuleInstance(),
22                                   lpCreateParam);
23 
24         return m_hWnd;
25     }
26 
SetRedraw(BOOL redraw)27     void SetRedraw(BOOL redraw)
28     {
29         SendMessage(WM_SETREDRAW, redraw);
30     }
31 
SetTextBkColor(COLORREF cr)32     BOOL SetTextBkColor(COLORREF cr)
33     {
34         return (BOOL)SendMessage(LVM_SETTEXTBKCOLOR, 0, cr);
35     }
36 
SetBkColor(COLORREF cr)37     BOOL SetBkColor(COLORREF cr)
38     {
39         return (BOOL)SendMessage(LVM_SETBKCOLOR, 0, cr);
40     }
41 
SetTextColor(COLORREF cr)42     BOOL SetTextColor(COLORREF cr)
43     {
44         return (BOOL)SendMessage(LVM_SETTEXTCOLOR, 0, cr);
45     }
46 
47     DWORD SetExtendedListViewStyle(DWORD dw, DWORD dwMask = 0)
48     {
49         return (DWORD)SendMessage(LVM_SETEXTENDEDLISTVIEWSTYLE, dwMask, dw);
50     }
51 
InsertColumn(int iCol,LV_COLUMN * pcol)52     int InsertColumn(int iCol, LV_COLUMN* pcol)
53     {
54         return (int)SendMessage(LVM_INSERTCOLUMN, iCol, reinterpret_cast<LPARAM>(pcol));
55     }
56 
57     int InsertColumn(int iCol, LPWSTR pszText, int fmt, int width = -1, int iSubItem = -1, int iImage = -1, int iOrder = -1)
58     {
59         LV_COLUMN column = {0};
60         column.mask = LVCF_TEXT|LVCF_FMT;
61         column.pszText = pszText;
62         column.fmt = fmt;
63         if(width != -1)
64         {
65             column.mask |= LVCF_WIDTH;
66             column.cx = width;
67         }
68         if(iSubItem != -1)
69         {
70             column.mask |= LVCF_SUBITEM;
71             column.iSubItem = iSubItem;
72         }
73         if(iImage != -1)
74         {
75             column.mask |= LVCF_IMAGE;
76             column.iImage = iImage;
77         }
78         if(iOrder != -1)
79         {
80             column.mask |= LVCF_ORDER;
81             column.iOrder = iOrder;
82         }
83         return InsertColumn(iCol, &column);
84     }
85 
GetColumnWidth(int iCol)86     int GetColumnWidth(int iCol)
87     {
88         return (int)SendMessage(LVM_GETCOLUMNWIDTH, iCol);
89     }
90 
SetImageList(HIMAGELIST himl,int iImageList)91     HIMAGELIST SetImageList(HIMAGELIST himl, int iImageList)
92     {
93         return (HIMAGELIST)SendMessage(LVM_SETIMAGELIST, iImageList, reinterpret_cast<LPARAM>(himl));
94     }
95 
InsertItem(const LV_ITEM * pitem)96     int InsertItem(const LV_ITEM * pitem)
97     {
98         return (int)SendMessage(LVM_INSERTITEM, 0, reinterpret_cast<LPARAM>(pitem));
99     }
100 
DeleteItem(int i)101     BOOL DeleteItem(int i)
102     {
103         return (BOOL)SendMessage(LVM_DELETEITEM, i, 0);
104     }
105 
GetItem(LV_ITEM * pitem)106     BOOL GetItem(LV_ITEM* pitem)
107     {
108         return (BOOL)SendMessage(LVM_GETITEM, 0, reinterpret_cast<LPARAM>(pitem));
109     }
110 
SetItem(const LV_ITEM * pitem)111     BOOL SetItem(const LV_ITEM * pitem)
112     {
113         return (BOOL)SendMessage(LVM_SETITEM, 0, reinterpret_cast<LPARAM>(pitem));
114     }
115 
FindItem(int iStart,const LV_FINDINFO * plvfi)116     BOOL FindItem(int iStart, const LV_FINDINFO * plvfi)
117     {
118         return (BOOL)SendMessage(LVM_FINDITEM, iStart, (LPARAM) plvfi);
119     }
120 
GetItemCount()121     int GetItemCount()
122     {
123         return SendMessage(LVM_GETITEMCOUNT);
124     }
125 
DeleteAllItems()126     BOOL DeleteAllItems()
127     {
128         return (BOOL)SendMessage(LVM_DELETEALLITEMS);
129     }
130 
Update(int i)131     BOOL Update(int i)
132     {
133         return (BOOL)SendMessage(LVM_UPDATE, i, 0);
134     }
135 
GetSelectedCount()136     UINT GetSelectedCount()
137     {
138         return (UINT)SendMessage(LVM_GETSELECTEDCOUNT);
139     }
140 
SortItems(PFNLVCOMPARE pfnCompare,PVOID lParam)141     BOOL SortItems(PFNLVCOMPARE pfnCompare, PVOID lParam)
142     {
143         return (BOOL)SendMessage(LVM_SORTITEMS, (WPARAM)lParam, (LPARAM) pfnCompare);
144     }
145 
EnsureVisible(int i,BOOL fPartialOK)146     BOOL EnsureVisible(int i, BOOL fPartialOK)
147     {
148         return (BOOL)SendMessage(LVM_ENSUREVISIBLE, i, MAKELPARAM((fPartialOK),0));
149     }
150 
EditLabel(int i)151     HWND EditLabel(int i)
152     {
153         return (HWND)SendMessage(LVM_EDITLABEL, i, 0);
154     }
155 
GetSelectionMark()156     int GetSelectionMark()
157     {
158         return (int)SendMessage(LVM_GETSELECTIONMARK);
159     }
160 
GetNextItem(int i,WORD flags)161     int GetNextItem(int i, WORD flags)
162     {
163         return (int)SendMessage(LVM_GETNEXTITEM, i, MAKELPARAM((flags),0));
164     }
165 
166     void GetItemSpacing(SIZE& spacing, BOOL bSmallIconView = FALSE)
167     {
168         DWORD ret = SendMessage(LVM_GETITEMSPACING, bSmallIconView);
169         spacing.cx = LOWORD(ret);
170         spacing.cy = HIWORD(ret);
171     }
172 
GetItemState(int i,UINT mask)173     UINT GetItemState(int i, UINT mask)
174     {
175         return SendMessage(LVM_GETITEMSTATE, i, (LPARAM)mask);
176     }
177 
SetItemState(int i,UINT state,UINT mask)178     void SetItemState(int i, UINT state, UINT mask)
179     {
180         LV_ITEM item;
181         item.stateMask = mask;
182         item.state = state;
183         SendMessage(LVM_SETITEMSTATE, i, reinterpret_cast<LPARAM>(&item));
184     }
185 
SetItemText(int i,int subItem,LPCWSTR text)186     BOOL SetItemText(int i, int subItem, LPCWSTR text)
187     {
188         LVITEMW item;
189         item.iSubItem = subItem;
190         item.pszText = (LPWSTR)text;
191         return SendMessage(LVM_SETITEMTEXT, i, (LPARAM)&item);
192     }
193 
SetCheckState(int i,BOOL check)194     void SetCheckState(int i, BOOL check)
195     {
196         SetItemState(i, INDEXTOSTATEIMAGEMASK((check)?2:1), LVIS_STATEIMAGEMASK);
197     }
198 
HitTest(LV_HITTESTINFO * phtInfo)199     int HitTest(LV_HITTESTINFO * phtInfo)
200     {
201         return (int)SendMessage(LVM_HITTEST, 0, reinterpret_cast<LPARAM>(phtInfo));
202     }
203 
GetItemData(int i)204     DWORD_PTR GetItemData(int i)
205     {
206         LVITEMW lvItem = { 0 };
207         lvItem.mask = LVIF_PARAM;
208         lvItem.iItem = i;
209         BOOL ret = GetItem(&lvItem);
210         return (DWORD_PTR)(ret ? lvItem.lParam : NULL);
211     }
212 
GetSelectedItem(LV_ITEM * pItem)213     BOOL GetSelectedItem(LV_ITEM* pItem)
214     {
215         pItem->iItem = GetNextItem(-1, LVNI_ALL | LVNI_SELECTED);
216         if (pItem->iItem == -1)
217             return FALSE;
218         return GetItem(pItem);
219     }
220 
GetItemText(int iItem,int iSubItem,LPTSTR pszText,int cchTextMax)221     void GetItemText(int iItem, int iSubItem, LPTSTR pszText, int cchTextMax)
222     {
223         LV_ITEM itemInfo;
224         itemInfo.iSubItem = iSubItem;
225         itemInfo.pszText = pszText;
226         itemInfo.cchTextMax = cchTextMax;
227 
228         SendMessage(LVM_GETITEMTEXT, iItem, (LPARAM) &itemInfo);
229     }
230 
GetItemPosition(int nItem,POINT * pPoint)231     BOOL GetItemPosition(int nItem, POINT* pPoint)
232     {
233         return (BOOL)SendMessage(LVM_GETITEMPOSITION, nItem, (LPARAM)pPoint);
234     }
235 
SetItemPosition(int nItem,POINT * pPoint)236     BOOL SetItemPosition(int nItem, POINT* pPoint)
237     {
238         return (BOOL)SendMessage(LVM_SETITEMPOSITION, nItem, MAKELPARAM(pPoint->x, pPoint->y));
239     }
240 
Arrange(UINT nCode)241     BOOL Arrange(UINT nCode)
242     {
243         return (BOOL)SendMessage(LVM_ARRANGE, nCode, 0);
244     }
245 
246 };
247 
248 template<typename TItemData = DWORD_PTR>
249 class CToolbar :
250     public CWindow
251 {
252 public: // Configuration methods
253 
254     // Hack:
255     // Use DECLARE_WND_SUPERCLASS instead!
256     HWND Create(HWND hWndParent, DWORD dwStyles = 0, DWORD dwExStyles = 0)
257     {
258         if (!dwStyles)
259         {
260             dwStyles = WS_CHILD | WS_VISIBLE | WS_CLIPCHILDREN;
261         }
262 
263         if (!dwExStyles)
264         {
265             dwExStyles = WS_EX_TOOLWINDOW;
266         }
267 
268         m_hWnd = CreateWindowExW(dwExStyles,
269                                 TOOLBARCLASSNAME,
270                                 NULL,
271                                 dwStyles,
272                                 0, 0, 0, 0, hWndParent,
273                                 NULL,
274                                 _AtlBaseModule.GetModuleInstance(),
275                                 NULL);
276 
277         if (!m_hWnd)
278             return NULL;
279 
280         /* Identify the version we're using */
281         SetButtonStructSize();
282 
283         return m_hWnd;
284     }
285 
SetButtonStructSize()286     DWORD SetButtonStructSize()
287     {
288         return SendMessageW(TB_BUTTONSTRUCTSIZE, sizeof(TBBUTTON), 0);
289     }
290 
GetTooltip()291     HWND GetTooltip()
292     {
293         return (HWND)SendMessageW(TB_GETTOOLTIPS);
294     }
295 
SetTooltip(HWND hWndTooltip)296     DWORD SetTooltip(HWND hWndTooltip)
297     {
298         return SendMessageW(TB_SETTOOLTIPS, reinterpret_cast<WPARAM>(hWndTooltip), 0);
299     }
300 
GetHotItem()301     INT GetHotItem()
302     {
303         return SendMessageW(TB_GETHOTITEM);
304     }
305 
SetHotItem(INT item)306     DWORD SetHotItem(INT item)
307     {
308         return SendMessageW(TB_SETHOTITEM, item);
309     }
310 
SetDrawTextFlags(DWORD useBits,DWORD bitState)311     DWORD SetDrawTextFlags(DWORD useBits, DWORD bitState)
312     {
313         return SendMessageW(TB_SETDRAWTEXTFLAGS, useBits, bitState);
314     }
315 
316 public: // Button list management methods
GetButtonCount()317     int GetButtonCount()
318     {
319         return SendMessageW(TB_BUTTONCOUNT);
320     }
321 
GetButton(int index,TBBUTTON * btn)322     DWORD GetButton(int index, TBBUTTON * btn)
323     {
324         return SendMessageW(TB_GETBUTTON, index, reinterpret_cast<LPARAM>(btn));
325     }
326 
AddButton(TBBUTTON * btn)327     DWORD AddButton(TBBUTTON * btn)
328     {
329         return SendMessageW(TB_ADDBUTTONS, 1, reinterpret_cast<LPARAM>(btn));
330     }
331 
AddButtons(int count,TBBUTTON * buttons)332     DWORD AddButtons(int count, TBBUTTON * buttons)
333     {
334         return SendMessageW(TB_ADDBUTTONS, count, reinterpret_cast<LPARAM>(buttons));
335     }
336 
InsertButton(int insertAt,TBBUTTON * btn)337     DWORD InsertButton(int insertAt, TBBUTTON * btn)
338     {
339         return SendMessageW(TB_INSERTBUTTON, insertAt, reinterpret_cast<LPARAM>(btn));
340     }
341 
MoveButton(int oldIndex,int newIndex)342     DWORD MoveButton(int oldIndex, int newIndex)
343     {
344         return SendMessageW(TB_MOVEBUTTON, oldIndex, newIndex);
345     }
346 
DeleteButton(int index)347     DWORD DeleteButton(int index)
348     {
349         return SendMessageW(TB_DELETEBUTTON, index, 0);
350     }
351 
GetButtonInfo(int cmdId,TBBUTTONINFO * info)352     DWORD GetButtonInfo(int cmdId, TBBUTTONINFO * info)
353     {
354         return SendMessageW(TB_GETBUTTONINFO, cmdId, reinterpret_cast<LPARAM>(info));
355     }
356 
SetButtonInfo(int cmdId,TBBUTTONINFO * info)357     DWORD SetButtonInfo(int cmdId, TBBUTTONINFO * info)
358     {
359         return SendMessageW(TB_SETBUTTONINFO, cmdId, reinterpret_cast<LPARAM>(info));
360     }
361 
CheckButton(int cmdId,BOOL bCheck)362     DWORD CheckButton(int cmdId, BOOL bCheck)
363     {
364         return SendMessageW(TB_CHECKBUTTON, cmdId, MAKELPARAM(bCheck, 0));
365     }
366 
367 public: // Layout management methods
GetButtonSize()368     DWORD GetButtonSize()
369     {
370         return SendMessageW(TB_GETBUTTONSIZE);
371     }
372 
SetButtonSize(int w,int h)373     DWORD SetButtonSize(int w, int h)
374     {
375         return SendMessageW(TB_SETBUTTONSIZE, 0, MAKELPARAM(w, h));
376     }
377 
AutoSize()378     DWORD AutoSize()
379     {
380         return SendMessageW(TB_AUTOSIZE);
381     }
382 
GetMaxSize(LPSIZE size)383     DWORD GetMaxSize(LPSIZE size)
384     {
385         return SendMessageW(TB_GETMAXSIZE, 0, reinterpret_cast<LPARAM>(size));
386     }
387 
GetIdealSize(BOOL useHeight,LPSIZE size)388     DWORD GetIdealSize(BOOL useHeight, LPSIZE size)
389     {
390         return SendMessageW(TB_GETIDEALSIZE, useHeight, reinterpret_cast<LPARAM>(size));
391     }
392 
GetMetrics(TBMETRICS * tbm)393     DWORD GetMetrics(TBMETRICS * tbm)
394     {
395         return SendMessageW(TB_GETMETRICS, 0, reinterpret_cast<LPARAM>(tbm));
396     }
397 
SetMetrics(TBMETRICS * tbm)398     DWORD SetMetrics(TBMETRICS * tbm)
399     {
400         return SendMessageW(TB_SETMETRICS, 0, reinterpret_cast<LPARAM>(tbm));
401     }
402 
GetItemRect(int index,LPRECT prcItem)403     DWORD GetItemRect(int index, LPRECT prcItem)
404     {
405         return SendMessageW(TB_GETITEMRECT, index, reinterpret_cast<LPARAM>(prcItem));
406     }
407 
SetRedraw(BOOL bEnable)408     DWORD SetRedraw(BOOL bEnable)
409     {
410         return SendMessageW(WM_SETREDRAW, bEnable);
411     }
412 
GetPadding()413     DWORD GetPadding()
414     {
415         return SendMessageW(TB_GETPADDING);
416     }
417 
SetPadding(int x,int y)418     DWORD SetPadding(int x, int y)
419     {
420         return SendMessageW(TB_SETPADDING, 0, MAKELPARAM(x, y));
421     }
422 
423 public: // Image list management methods
SetImageList(HIMAGELIST himl)424     HIMAGELIST SetImageList(HIMAGELIST himl)
425     {
426         return (HIMAGELIST)SendMessageW(TB_SETIMAGELIST, 0, reinterpret_cast<LPARAM>(himl));
427     }
428 
429 public: // Other methods
HitTest(PPOINT ppt)430     INT HitTest(PPOINT ppt)
431     {
432         return (INT) SendMessageW(TB_HITTEST, 0, reinterpret_cast<LPARAM>(ppt));
433     }
434 
435 public: // Utility methods
GetItemData(int index)436     TItemData * GetItemData(int index)
437     {
438         TBBUTTON btn;
439         GetButton(index, &btn);
440         return (TItemData*) btn.dwData;
441     }
442 
SetItemData(int index,TItemData * data)443     DWORD SetItemData(int index, TItemData * data)
444     {
445         TBBUTTONINFOW info = { 0 };
446         info.cbSize = sizeof(info);
447         info.dwMask = TBIF_BYINDEX | TBIF_LPARAM;
448         info.lParam = (DWORD_PTR) data;
449         return SetButtonInfo(index, &info);
450     }
451 };
452 
453 class CStatusBar :
454     public CWindow
455 {
456 public:
SetText(LPCWSTR lpszText)457     VOID SetText(LPCWSTR lpszText)
458     {
459         SendMessage(SB_SETTEXT, SBT_NOBORDERS, (LPARAM) lpszText);
460     }
461 
Create(HWND hwndParent,HMENU hMenu)462     HWND Create(HWND hwndParent, HMENU hMenu)
463     {
464         m_hWnd = CreateWindowExW(0,
465             STATUSCLASSNAMEW,
466             NULL,
467             WS_CHILD | WS_VISIBLE | SBARS_SIZEGRIP,
468             0, 0, 0, 0,
469             hwndParent,
470             hMenu,
471             _AtlBaseModule.GetModuleInstance(),
472             NULL);
473 
474         return m_hWnd;
475     }
476 
477 };
478 
479 class CTreeView :
480     public CWindow
481 {
482 public:
Create(HWND hwndParent)483     HWND Create(HWND hwndParent)
484     {
485         m_hWnd = CreateWindowExW(WS_EX_CLIENTEDGE,
486             WC_TREEVIEWW,
487             L"",
488             WS_CHILD | WS_VISIBLE | TVS_HASLINES | TVS_SHOWSELALWAYS,
489             0, 28, 200, 350,
490             hwndParent,
491             NULL,
492             _AtlBaseModule.GetModuleInstance(),
493             NULL);
494 
495         return m_hWnd;
496     }
497 
AddItem(HTREEITEM hParent,LPWSTR lpText,INT Image,INT SelectedImage,LPARAM lParam)498     HTREEITEM AddItem(HTREEITEM hParent, LPWSTR lpText, INT Image, INT SelectedImage, LPARAM lParam)
499     {
500         TVINSERTSTRUCTW Insert;
501 
502         ZeroMemory(&Insert, sizeof(TV_INSERTSTRUCT));
503 
504         Insert.item.mask = TVIF_TEXT | TVIF_PARAM | TVIF_IMAGE | TVIF_SELECTEDIMAGE;
505         Insert.hInsertAfter = TVI_LAST;
506         Insert.hParent = hParent;
507         Insert.item.iSelectedImage = SelectedImage;
508         Insert.item.iImage = Image;
509         Insert.item.lParam = lParam;
510         Insert.item.pszText = lpText;
511 
512         return InsertItem(&Insert);
513     }
514 
SetRedraw(BOOL redraw)515     void SetRedraw(BOOL redraw)
516     {
517         SendMessage(WM_SETREDRAW, redraw);
518     }
519 
SetBkColor(COLORREF cr)520     BOOL SetBkColor(COLORREF cr)
521     {
522         return (BOOL) SendMessage(TVM_SETBKCOLOR, 0, cr);
523     }
524 
SetTextColor(COLORREF cr)525     BOOL SetTextColor(COLORREF cr)
526     {
527         return (BOOL) SendMessage(TVM_SETTEXTCOLOR, 0, cr);
528     }
529 
SetImageList(HIMAGELIST himl,int iImageList)530     HIMAGELIST SetImageList(HIMAGELIST himl, int iImageList)
531     {
532         return (HIMAGELIST) SendMessage(TVM_SETIMAGELIST, iImageList, reinterpret_cast<LPARAM>(himl));
533     }
534 
InsertItem(const TVINSERTSTRUCTW * pitem)535     HTREEITEM InsertItem(const TVINSERTSTRUCTW * pitem)
536     {
537         return (HTREEITEM) SendMessage(TVM_INSERTITEM, 0, reinterpret_cast<LPARAM>(pitem));
538     }
539 
DeleteItem(HTREEITEM i)540     BOOL DeleteItem(HTREEITEM i)
541     {
542         return (BOOL) SendMessage(TVM_DELETEITEM, 0, (LPARAM)i);
543     }
544 
GetItem(TV_ITEM * pitem)545     BOOL GetItem(TV_ITEM* pitem)
546     {
547         return (BOOL) SendMessage(TVM_GETITEM, 0, reinterpret_cast<LPARAM>(pitem));
548     }
549 
SetItem(const TV_ITEM * pitem)550     BOOL SetItem(const TV_ITEM * pitem)
551     {
552         return (BOOL) SendMessage(TVM_SETITEM, 0, reinterpret_cast<LPARAM>(pitem));
553     }
554 
GetItemCount()555     int GetItemCount()
556     {
557         return SendMessage(TVM_GETCOUNT);
558     }
559 
EnsureVisible(HTREEITEM i)560     BOOL EnsureVisible(HTREEITEM i)
561     {
562         return (BOOL) SendMessage(TVM_ENSUREVISIBLE, 0, (LPARAM)i);
563     }
564 
EditLabel(HTREEITEM i)565     HWND EditLabel(HTREEITEM i)
566     {
567         return (HWND) SendMessage(TVM_EDITLABEL, 0, (LPARAM)i);
568     }
569 
GetNextItem(HTREEITEM i,WORD flags)570     HTREEITEM GetNextItem(HTREEITEM i, WORD flags)
571     {
572         return (HTREEITEM)SendMessage(TVM_GETNEXTITEM, flags, (LPARAM)i);
573     }
574 
GetItemState(int i,UINT mask)575     UINT GetItemState(int i, UINT mask)
576     {
577         return SendMessage(TVM_GETITEMSTATE, i, (LPARAM) mask);
578     }
579 
HitTest(TVHITTESTINFO * phtInfo)580     HTREEITEM HitTest(TVHITTESTINFO * phtInfo)
581     {
582         return (HTREEITEM) SendMessage(TVM_HITTEST, 0, reinterpret_cast<LPARAM>(phtInfo));
583     }
584 
GetItemData(HTREEITEM item)585     DWORD_PTR GetItemData(HTREEITEM item)
586     {
587         TVITEMW lvItem;
588         lvItem.hItem = item;
589         lvItem.mask = TVIF_PARAM;
590         BOOL ret = GetItem(&lvItem);
591         return (DWORD_PTR) (ret ? lvItem.lParam : NULL);
592     }
593 
GetSelection()594     HTREEITEM GetSelection()
595     {
596         return GetNextItem(NULL, TVGN_CARET);
597     }
598 
Expand(HTREEITEM item,DWORD action)599     BOOL Expand(HTREEITEM item, DWORD action)
600     {
601         return SendMessage(TVM_EXPAND, action, (LPARAM)item);
602     }
603 
604     BOOL SelectItem(HTREEITEM item, DWORD action = TVGN_CARET)
605     {
606         return SendMessage(TVM_SELECTITEM, action, (LPARAM) item);
607     }
608 
609 };
610 
611 class CTooltips :
612     public CWindow
613 {
614 public: // Configuration methods
615 
616     HWND Create(HWND hWndParent, DWORD dwStyles = WS_POPUP | TTS_NOPREFIX, DWORD dwExStyles = WS_EX_TOPMOST)
617     {
618         RECT r = { 0 };
619         return CWindow::Create(TOOLTIPS_CLASS, hWndParent, r, L"", dwStyles, dwExStyles);
620     }
621 
622 public: // Relay event
623 
624     // Win7+: Can use GetMessageExtraInfo to provide the WPARAM value.
625     VOID RelayEvent(MSG * pMsg, WPARAM extraInfo = 0)
626     {
627         SendMessageW(TTM_RELAYEVENT, extraInfo, reinterpret_cast<LPARAM>(pMsg));
628     }
629 
630 public: // Helpers
631 
GetToolCount()632     INT GetToolCount()
633     {
634         return SendMessageW(TTM_GETTOOLCOUNT, 0, 0);
635     }
636 
AddTool(IN CONST TTTOOLINFOW * pInfo)637     BOOL AddTool(IN CONST TTTOOLINFOW * pInfo)
638     {
639         return SendMessageW(TTM_ADDTOOL, 0, reinterpret_cast<LPARAM>(pInfo));
640     }
641 
DelTool(IN HWND hwndToolOwner,IN UINT uId)642     VOID DelTool(IN HWND hwndToolOwner, IN UINT uId)
643     {
644         TTTOOLINFOW info = { sizeof(TTTOOLINFOW), 0 };
645         info.hwnd = hwndToolOwner;
646         info.uId = uId;
647         SendMessageW(TTM_DELTOOL, 0, reinterpret_cast<LPARAM>(&info));
648     }
649 
NewToolRect(IN HWND hwndToolOwner,IN UINT uId,IN RECT rect)650     VOID NewToolRect(IN HWND hwndToolOwner, IN UINT uId, IN RECT rect)
651     {
652         TTTOOLINFOW info = { sizeof(TTTOOLINFOW), 0 };
653         info.hwnd = hwndToolOwner;
654         info.uId = uId;
655         info.rect = rect;
656         SendMessageW(TTM_NEWTOOLRECT, 0, reinterpret_cast<LPARAM>(&info));
657     }
658 
GetToolInfo(IN HWND hwndToolOwner,IN UINT uId,IN OUT TTTOOLINFOW * pInfo)659     BOOL GetToolInfo(IN HWND hwndToolOwner, IN UINT uId, IN OUT TTTOOLINFOW * pInfo)
660     {
661         pInfo->hwnd = hwndToolOwner;
662         pInfo->uId = uId;
663         return SendMessageW(TTM_GETTOOLINFO, 0, reinterpret_cast<LPARAM>(pInfo));
664     }
665 
SetToolInfo(IN CONST TTTOOLINFOW * pInfo)666     VOID SetToolInfo(IN CONST TTTOOLINFOW * pInfo)
667     {
668         SendMessageW(TTM_SETTOOLINFO, 0, reinterpret_cast<LPARAM>(pInfo));
669     }
670 
HitTest(IN CONST TTHITTESTINFOW * pInfo)671     BOOL HitTest(IN CONST TTHITTESTINFOW * pInfo)
672     {
673         return SendMessageW(TTM_HITTEST, 0, reinterpret_cast<LPARAM>(pInfo));
674     }
675 
GetText(IN HWND hwndToolOwner,IN UINT uId,OUT PWSTR pBuffer,IN DWORD cchBuffer)676     VOID GetText(IN HWND hwndToolOwner, IN UINT uId, OUT PWSTR pBuffer, IN DWORD cchBuffer)
677     {
678         TTTOOLINFOW info = { sizeof(TTTOOLINFOW), 0 };
679         info.hwnd = hwndToolOwner;
680         info.uId = uId;
681         info.lpszText = pBuffer;
682         SendMessageW(TTM_GETTEXT, cchBuffer, reinterpret_cast<LPARAM>(&info));
683     }
684 
685     VOID UpdateTipText(IN HWND hwndToolOwner, IN UINT uId, IN PCWSTR szText, IN HINSTANCE hinstResourceOwner = NULL)
686     {
687         TTTOOLINFOW info = { sizeof(TTTOOLINFOW), 0 };
688         info.hwnd = hwndToolOwner;
689         info.uId = uId;
690         info.lpszText = const_cast<PWSTR>(szText);
691         info.hinst = hinstResourceOwner;
692         SendMessageW(TTM_UPDATETIPTEXT, 0, reinterpret_cast<LPARAM>(&info));
693     }
694 
EnumTools(IN CONST TTTOOLINFOW * pInfo)695     BOOL EnumTools(IN CONST TTTOOLINFOW * pInfo)
696     {
697         return SendMessageW(TTM_ENUMTOOLS, 0, reinterpret_cast<LPARAM>(pInfo));
698     }
699 
700     BOOL GetCurrentTool(OUT OPTIONAL TTTOOLINFOW * pInfo = NULL)
701     {
702         return SendMessageW(TTM_GETCURRENTTOOL, 0, reinterpret_cast<LPARAM>(pInfo));
703     }
704 
GetTitle(TTGETTITLE * pTitleInfo)705     VOID GetTitle(TTGETTITLE * pTitleInfo)
706     {
707         SendMessageW(TTM_GETTITLE, 0, reinterpret_cast<LPARAM>(pTitleInfo));
708     }
709 
710     BOOL SetTitle(PCWSTR szTitleText, WPARAM icon = 0)
711     {
712         return SendMessageW(TTM_SETTITLE, icon, reinterpret_cast<LPARAM>(szTitleText));
713     }
714 
TrackActivate(IN HWND hwndToolOwner,IN UINT uId)715     VOID TrackActivate(IN HWND hwndToolOwner, IN UINT uId)
716     {
717         TTTOOLINFOW info = { sizeof(TTTOOLINFOW), 0 };
718         info.hwnd = hwndToolOwner;
719         info.uId = uId;
720         SendMessageW(TTM_TRACKACTIVATE, TRUE, reinterpret_cast<LPARAM>(&info));
721     }
722 
TrackDeactivate()723     VOID TrackDeactivate()
724     {
725         SendMessageW(TTM_TRACKACTIVATE, FALSE, NULL);
726     }
727 
TrackPosition(IN WORD x,IN WORD y)728     VOID TrackPosition(IN WORD x, IN WORD y)
729     {
730         SendMessageW(TTM_TRACKPOSITION, 0, MAKELPARAM(x, y));
731     }
732 
733     // Opens the tooltip
Popup()734     VOID Popup()
735     {
736         SendMessageW(TTM_POPUP);
737     }
738 
739     // Closes the tooltip - Pressing the [X] for a TTF_CLOSE balloon is equivalent to calling this
Pop()740     VOID Pop()
741     {
742         SendMessageW(TTM_POP);
743     }
744 
745     // Delay times for AUTOMATIC tooltips (they don't affect balloons)
GetDelayTime(UINT which)746     INT GetDelayTime(UINT which)
747     {
748         return SendMessageW(TTM_GETDELAYTIME, which);
749     }
750 
SetDelayTime(UINT which,WORD time)751     VOID SetDelayTime(UINT which, WORD time)
752     {
753         SendMessageW(TTM_SETDELAYTIME, which, MAKELPARAM(time, 0));
754     }
755 
756     // Activates or deactivates the automatic tooltip display when hovering a control
757     VOID Activate(IN BOOL bActivate = TRUE)
758     {
759         SendMessageW(TTM_ACTIVATE, bActivate);
760     }
761 
762     // Adjusts the position of a tooltip when used to display trimmed text
AdjustRect(IN BOOL bTextToWindow,IN OUT RECT * pRect)763     VOID AdjustRect(IN BOOL bTextToWindow, IN OUT RECT * pRect)
764     {
765         SendMessageW(TTM_ADJUSTRECT, bTextToWindow, reinterpret_cast<LPARAM>(pRect));
766     }
767 
768     // Useful for TTF_ABSOLUTE|TTF_TRACK tooltip positioning
GetBubbleSize(IN TTTOOLINFOW * pInfo)769     SIZE GetBubbleSize(IN TTTOOLINFOW * pInfo)
770     {
771         DWORD ret = SendMessageW(TTM_GETBUBBLESIZE, 0, reinterpret_cast<LPARAM>(pInfo));
772         const SIZE sz = { LOWORD(ret), HIWORD(ret) };
773         return sz;
774     }
775 
776     // Fills the RECT with the margin size previously set. Default is 0 margins.
GetMargin(OUT RECT * pRect)777     VOID GetMargin(OUT RECT * pRect)
778     {
779         SendMessageW(TTM_GETMARGIN, 0, reinterpret_cast<LPARAM>(pRect));
780     }
781 
SetMargin(IN RECT * pRect)782     VOID SetMargin(IN RECT * pRect)
783     {
784         SendMessageW(TTM_SETMARGIN, 0, reinterpret_cast<LPARAM>(pRect));
785     }
786 
787     // Gets a previously established max width. Returns -1 if no limit is set
GetMaxTipWidth()788     INT GetMaxTipWidth()
789     {
790         return SendMessageW(TTM_GETMAXTIPWIDTH);
791     }
792 
793     INT SetMaxTipWidth(IN OPTIONAL INT width = -1)
794     {
795         return SendMessageW(TTM_SETMAXTIPWIDTH, 0, width);
796     }
797 
798     // Get the color of the tooltip text
GetTipTextColor()799     COLORREF GetTipTextColor()
800     {
801         return SendMessageW(TTM_GETTIPTEXTCOLOR);
802     }
803 
SetTipTextColor(IN COLORREF textColor)804     VOID SetTipTextColor(IN COLORREF textColor)
805     {
806         SendMessageW(TTM_SETTIPTEXTCOLOR, textColor);
807     }
808 
GetTipBkColor()809     COLORREF GetTipBkColor()
810     {
811         return SendMessageW(TTM_GETTIPBKCOLOR);
812     }
813 
SetTipBkColor(IN COLORREF textColor)814     VOID SetTipBkColor(IN COLORREF textColor)
815     {
816         SendMessageW(TTM_SETTIPBKCOLOR, textColor);
817     }
818 
SetWindowTheme(IN PCWSTR szThemeName)819     VOID SetWindowTheme(IN PCWSTR szThemeName)
820     {
821         SendMessageW(TTM_SETWINDOWTHEME, 0, reinterpret_cast<LPARAM>(szThemeName));
822     }
823 
824     // Forces redraw
Update()825     VOID Update()
826     {
827         SendMessageW(TTM_UPDATE);
828     }
829 
WindowFromPoint(IN POINT * pPoint)830     HWND WindowFromPoint(IN POINT * pPoint)
831     {
832         return reinterpret_cast<HWND>(SendMessageW(TTM_WINDOWFROMPOINT, 0, reinterpret_cast<LPARAM>(pPoint)));
833     }
834 };
835