Process Hacker
treenewp.h
Go to the documentation of this file.
1 #ifndef _PH_TREENEWP_H
2 #define _PH_TREENEWP_H
3 
4 // Important notes about pointers:
5 //
6 // All memory allocation for nodes and strings is handled by the user.
7 // This usually means there is a very limited time during which they
8 // can be safely accessed.
9 //
10 // Node pointers are valid through the duration of message processing,
11 // and also up to the next restructure operation, either user- or control-
12 // initiated. This means that state such as the focused node, hot node and
13 // mark node must be carefully preserved through restructuring. If
14 // restructuring is suspended by a set-redraw call, all nodes must be
15 // considered invalid and no user input can be handled.
16 //
17 // Strings are valid only through the duration of message processing.
18 
19 typedef struct _PH_TREENEW_CONTEXT
20 {
21  HWND Handle;
29 
30  union
31  {
32  struct
33  {
34  ULONG FontOwned : 1;
35  ULONG Tracking : 1; // tracking for fixed divider
36  ULONG VScrollVisible : 1;
37  ULONG HScrollVisible : 1;
38  ULONG FixedColumnVisible : 1;
40  ULONG AnimateDivider : 1;
43  ULONG CanAnyExpand : 1;
44  ULONG TriState : 1;
45  ULONG HasFocus : 1;
46  ULONG ThemeInitialized : 1; // delay load theme data
47  ULONG ThemeActive : 1;
49  ULONG ThemeHasGlyph : 1;
50  ULONG ThemeHasHotGlyph : 1;
51  ULONG FocusNodeFound : 1; // used to preserve the focused node across restructuring
52  ULONG SearchFailed : 1; // used to prevent multiple beeps
53  ULONG SearchSingleCharMode : 1; // LV style single-character search
54  ULONG TooltipUnfolding : 1; // whether the current tooltip is unfolding
55  ULONG DoubleBuffered : 1;
60  ULONG SelectionRectangleAlpha : 1; // use alpha blending for the selection rectangle
61  ULONG CustomRowHeight : 1;
62  ULONG Spare : 4;
63  };
64  ULONG Flags;
65  };
66  ULONG Style;
69 
70  HFONT Font;
71  HCURSOR Cursor;
72  HCURSOR DividerCursor;
73 
74  RECT ClientRect;
77  ULONG VScrollWidth;
81  LONG FixedWidth; // width of the fixed part of the tree list
83  LONG NormalLeft; // FixedWidth + 1 if there is a fixed column, otherwise 0
84 
86  ULONG HotNodeIndex;
87  ULONG MarkNodeIndex; // selection mark
88 
91 
94 
95  PPH_TREENEW_COLUMN *Columns; // columns, indexed by ID
96  ULONG NextId;
98  ULONG NumberOfColumns; // just a statistic; do not use for actual logic
99 
100  PPH_TREENEW_COLUMN *ColumnsByDisplay; // columns, indexed by display order (excluding the fixed column)
102  ULONG NumberOfColumnsByDisplay; // the number of visible columns (excluding the fixed column)
103  LONG TotalViewX; // total width of normal columns
105  PPH_TREENEW_COLUMN FirstColumn; // first column, by display order (including the fixed column)
106  PPH_TREENEW_COLUMN LastColumn; // last column, by display order (including the fixed column)
107 
112  ULONG DividerHot; // 0 for un-hot, 100 for completely hot
113 
115 
116  ULONG SortColumn; // ID of the column to sort by
118 
121 
126 
128  ULONG TooltipId;
130  RECT TooltipRect; // text rectangle of an unfolding tooltip
131  HFONT TooltipFont;
136 
137  TEXTMETRIC TextMetrics;
143 
146  HBITMAP BufferedBitmap;
148 
151  RECT DragRect;
152 
155 
158 
159 LRESULT CALLBACK PhTnpWndProc(
160  _In_ HWND hwnd,
161  _In_ UINT uMsg,
162  _In_ WPARAM wParam,
163  _In_ LPARAM lParam
164  );
165 
166 BOOLEAN NTAPI PhTnpNullCallback(
167  _In_ HWND hwnd,
168  _In_ PH_TREENEW_MESSAGE Message,
169  _In_opt_ PVOID Parameter1,
170  _In_opt_ PVOID Parameter2,
171  _In_opt_ PVOID Context
172  );
173 
175  _Out_ PPH_TREENEW_CONTEXT *Context
176  );
177 
179  _In_ PPH_TREENEW_CONTEXT Context
180  );
181 
182 // Event handlers
183 
184 BOOLEAN PhTnpOnCreate(
185  _In_ HWND hwnd,
186  _In_ PPH_TREENEW_CONTEXT Context,
187  _In_ CREATESTRUCT *CreateStruct
188  );
189 
191  _In_ HWND hwnd,
192  _In_ PPH_TREENEW_CONTEXT Context
193  );
194 
196  _In_ HWND hwnd,
197  _In_ PPH_TREENEW_CONTEXT Context,
198  _In_opt_ HFONT Font,
199  _In_ LOGICAL Redraw
200  );
201 
203  _In_ HWND hwnd,
204  _In_ PPH_TREENEW_CONTEXT Context,
205  _In_ LONG Type,
206  _In_ STYLESTRUCT *StyleStruct
207  );
208 
210  _In_ HWND hwnd,
211  _In_ PPH_TREENEW_CONTEXT Context
212  );
213 
215  _In_ HWND hwnd,
216  _In_ PPH_TREENEW_CONTEXT Context
217  );
218 
219 ULONG PhTnpOnGetDlgCode(
220  _In_ HWND hwnd,
221  _In_ PPH_TREENEW_CONTEXT Context,
222  _In_ ULONG VirtualKey,
223  _In_opt_ PMSG Message
224  );
225 
227  _In_ HWND hwnd,
228  _In_ PPH_TREENEW_CONTEXT Context
229  );
230 
232  _In_ HWND hwnd,
233  _In_ PPH_TREENEW_CONTEXT Context,
234  _In_ HDC hdc,
235  _In_ ULONG Flags
236  );
237 
238 BOOLEAN PhTnpOnNcPaint(
239  _In_ HWND hwnd,
240  _In_ PPH_TREENEW_CONTEXT Context,
241  _In_opt_ HRGN UpdateRegion
242  );
243 
244 BOOLEAN PhTnpOnSetCursor(
245  _In_ HWND hwnd,
246  _In_ PPH_TREENEW_CONTEXT Context,
247  _In_ HWND CursorWindowHandle
248  );
249 
251  _In_ HWND hwnd,
252  _In_ PPH_TREENEW_CONTEXT Context,
253  _In_ ULONG Id
254  );
255 
257  _In_ HWND hwnd,
258  _In_ PPH_TREENEW_CONTEXT Context,
259  _In_ ULONG VirtualKeys,
260  _In_ LONG CursorX,
261  _In_ LONG CursorY
262  );
263 
265  _In_ HWND hwnd,
266  _In_ PPH_TREENEW_CONTEXT Context
267  );
268 
270  _In_ HWND hwnd,
271  _In_ PPH_TREENEW_CONTEXT Context,
272  _In_ ULONG Message,
273  _In_ ULONG VirtualKeys,
274  _In_ LONG CursorX,
275  _In_ LONG CursorY
276  );
277 
279  _In_ HWND hwnd,
280  _In_ PPH_TREENEW_CONTEXT Context
281  );
282 
284  _In_ HWND hwnd,
285  _In_ PPH_TREENEW_CONTEXT Context,
286  _In_ ULONG VirtualKey,
287  _In_ ULONG Data
288  );
289 
291  _In_ HWND hwnd,
292  _In_ PPH_TREENEW_CONTEXT Context,
293  _In_ ULONG Character,
294  _In_ ULONG Data
295  );
296 
298  _In_ HWND hwnd,
299  _In_ PPH_TREENEW_CONTEXT Context,
300  _In_ LONG Distance,
301  _In_ ULONG VirtualKeys,
302  _In_ LONG CursorX,
303  _In_ LONG CursorY
304  );
305 
307  _In_ HWND hwnd,
308  _In_ PPH_TREENEW_CONTEXT Context,
309  _In_ LONG Distance,
310  _In_ ULONG VirtualKeys,
311  _In_ LONG CursorX,
312  _In_ LONG CursorY
313  );
314 
316  _In_ HWND hwnd,
317  _In_ PPH_TREENEW_CONTEXT Context,
318  _In_ LONG CursorScreenX,
319  _In_ LONG CursorScreenY
320  );
321 
323  _In_ HWND hwnd,
324  _In_ PPH_TREENEW_CONTEXT Context,
325  _In_ ULONG Request,
326  _In_ USHORT Position
327  );
328 
330  _In_ HWND hwnd,
331  _In_ PPH_TREENEW_CONTEXT Context,
332  _In_ ULONG Request,
333  _In_ USHORT Position
334  );
335 
336 BOOLEAN PhTnpOnNotify(
337  _In_ HWND hwnd,
338  _In_ PPH_TREENEW_CONTEXT Context,
339  _In_ NMHDR *Header,
340  _Out_ LRESULT *Result
341  );
342 
343 ULONG_PTR PhTnpOnUserMessage(
344  _In_ HWND hwnd,
345  _In_ PPH_TREENEW_CONTEXT Context,
346  _In_ ULONG Message,
347  _In_ ULONG_PTR WParam,
348  _In_ ULONG_PTR LParam
349  );
350 
351 // Misc.
352 
354  _In_ PPH_TREENEW_CONTEXT Context,
355  _In_opt_ HFONT Font,
356  _In_ BOOLEAN Redraw
357  );
358 
360  _In_ PPH_TREENEW_CONTEXT Context
361  );
362 
364  _In_ PPH_TREENEW_CONTEXT Context
365  );
366 
368  _In_ PPH_TREENEW_CONTEXT Context
369  );
370 
372  _In_ PPH_TREENEW_CONTEXT Context
373  );
374 
376  _In_ PPH_TREENEW_CONTEXT Context
377  );
378 
380  _In_ PPH_TREENEW_CONTEXT Context
381  );
382 
384  _In_ PPH_TREENEW_CONTEXT Context
385  );
386 
388  _In_ PPH_TREENEW_CONTEXT Context,
389  _In_ ULONG FixedWidth
390  );
391 
393  _In_ PPH_TREENEW_CONTEXT Context,
394  _In_ BOOLEAN Redraw
395  );
396 
398  _In_ PPH_TREENEW_CONTEXT Context,
399  _In_ PH_TREENEW_MESSAGE Message,
400  _In_ LONG CursorX,
401  _In_ LONG CursorY,
402  _In_ PPH_TREENEW_NODE Node,
403  _In_ PPH_TREENEW_COLUMN Column,
404  _In_ ULONG VirtualKeys
405  );
406 
407 // Columns
408 
410  _In_ PPH_TREENEW_CONTEXT Context,
411  _In_ ULONG Id
412  );
413 
414 BOOLEAN PhTnpAddColumn(
415  _In_ PPH_TREENEW_CONTEXT Context,
416  _In_ PPH_TREENEW_COLUMN Column
417  );
418 
419 BOOLEAN PhTnpRemoveColumn(
420  _In_ PPH_TREENEW_CONTEXT Context,
421  _In_ ULONG Id
422  );
423 
424 BOOLEAN PhTnpCopyColumn(
425  _In_ PPH_TREENEW_CONTEXT Context,
426  _In_ ULONG Id,
427  _Out_ PPH_TREENEW_COLUMN Column
428  );
429 
430 BOOLEAN PhTnpChangeColumn(
431  _In_ PPH_TREENEW_CONTEXT Context,
432  _In_ ULONG Mask,
433  _In_ ULONG Id,
434  _In_ PPH_TREENEW_COLUMN Column
435  );
436 
438  _In_ PPH_TREENEW_CONTEXT Context
439  );
440 
442  _In_ PPH_TREENEW_CONTEXT Context
443  );
444 
445 // Columns (header control)
446 
448  _In_ PPH_TREENEW_CONTEXT Context,
449  _In_ PPH_TREENEW_COLUMN Column
450  );
451 
453  _In_ PPH_TREENEW_CONTEXT Context,
454  _In_ ULONG Mask,
455  _In_ PPH_TREENEW_COLUMN Column
456  );
457 
459  _In_ PPH_TREENEW_CONTEXT Context,
460  _Inout_ PPH_TREENEW_COLUMN Column
461  );
462 
464  _In_ PPH_TREENEW_CONTEXT Context
465  );
466 
468  _In_ PPH_TREENEW_CONTEXT Context,
469  _In_ PPH_TREENEW_COLUMN Column,
470  _In_ LONG Delta
471  );
472 
474  _In_ PPH_TREENEW_CONTEXT Context,
475  _In_ PPH_TREENEW_COLUMN NewColumn
476  );
477 
479  _In_ PPH_TREENEW_CONTEXT Context,
480  _In_opt_ PPH_TREENEW_COLUMN SortColumnPointer
481  );
482 
484  _In_ PPH_TREENEW_CONTEXT Context,
485  _In_ HWND HeaderHandle,
486  _In_ PPH_TREENEW_COLUMN Column,
487  _In_ ULONG Flags
488  );
489 
490 // Nodes
491 
492 BOOLEAN PhTnpGetNodeChildren(
493  _In_ PPH_TREENEW_CONTEXT Context,
494  _In_opt_ PPH_TREENEW_NODE Node,
495  _Out_ PPH_TREENEW_NODE **Children,
496  _Out_ PULONG NumberOfChildren
497  );
498 
499 BOOLEAN PhTnpIsNodeLeaf(
500  _In_ PPH_TREENEW_CONTEXT Context,
501  _In_ PPH_TREENEW_NODE Node
502  );
503 
504 BOOLEAN PhTnpGetCellText(
505  _In_ PPH_TREENEW_CONTEXT Context,
506  _In_ PPH_TREENEW_NODE Node,
507  _In_ ULONG Id,
508  _Out_ PPH_STRINGREF Text
509  );
510 
512  _In_ PPH_TREENEW_CONTEXT Context
513  );
514 
516  _In_ PPH_TREENEW_CONTEXT Context,
517  _In_ PPH_TREENEW_NODE Node,
518  _In_ ULONG Level
519  );
520 
522  _In_ PPH_TREENEW_CONTEXT Context,
523  _In_ PPH_TREENEW_NODE Node,
524  _In_ BOOLEAN Expanded
525  );
526 
527 BOOLEAN PhTnpGetCellParts(
528  _In_ PPH_TREENEW_CONTEXT Context,
529  _In_ ULONG Index,
530  _In_opt_ PPH_TREENEW_COLUMN Column,
531  _In_ ULONG Flags,
532  _Out_ PPH_TREENEW_CELL_PARTS Parts
533  );
534 
535 BOOLEAN PhTnpGetRowRects(
536  _In_ PPH_TREENEW_CONTEXT Context,
537  _In_ ULONG Start,
538  _In_ ULONG End,
539  _In_ BOOLEAN Clip,
540  _Out_ PRECT Rect
541  );
542 
544  _In_ PPH_TREENEW_CONTEXT Context,
545  _Inout_ PPH_TREENEW_HIT_TEST HitTest
546  );
547 
549  _In_ PPH_TREENEW_CONTEXT Context,
550  _In_ ULONG Start,
551  _In_ ULONG End,
552  _In_ ULONG Flags,
553  _Out_opt_ PULONG ChangedStart,
554  _Out_opt_ PULONG ChangedEnd
555  );
556 
558  _In_ PPH_TREENEW_CONTEXT Context,
559  _In_opt_ PPH_TREENEW_NODE NewHotNode,
560  _In_ BOOLEAN NewPlusMinusHot
561  );
562 
564  _In_ PPH_TREENEW_CONTEXT Context,
565  _In_ PPH_TREENEW_NODE Node,
566  _In_ LOGICAL ControlKey,
567  _In_ LOGICAL ShiftKey,
568  _In_ LOGICAL RightButton
569  );
570 
571 BOOLEAN PhTnpEnsureVisibleNode(
572  _In_ PPH_TREENEW_CONTEXT Context,
573  _In_ ULONG Index
574  );
575 
576 // Mouse
577 
579  _In_ PPH_TREENEW_CONTEXT Context,
580  _In_ LONG CursorX,
581  _In_ LONG CursorY
582  );
583 
585  _In_ PPH_TREENEW_CONTEXT Context,
586  _In_ LONG Distance
587  );
588 
590  _In_ PPH_TREENEW_CONTEXT Context,
591  _In_ LONG Distance
592  );
593 
594 // Keyboard
595 
596 BOOLEAN PhTnpProcessFocusKey(
597  _In_ PPH_TREENEW_CONTEXT Context,
598  _In_ ULONG VirtualKey
599  );
600 
601 BOOLEAN PhTnpProcessNodeKey(
602  _In_ PPH_TREENEW_CONTEXT Context,
603  _In_ ULONG VirtualKey
604  );
605 
607  _In_ PPH_TREENEW_CONTEXT Context,
608  _In_ ULONG Character
609  );
610 
612  _In_ PPH_TREENEW_CONTEXT Context,
613  _Inout_ PPH_TREENEW_SEARCH_EVENT SearchEvent,
614  _In_ BOOLEAN Partial,
615  _In_ BOOLEAN Wrap
616  );
617 
618 // Scrolling
619 
621  _In_ PPH_TREENEW_CONTEXT Context
622  );
623 
625  _In_ PPH_TREENEW_CONTEXT Context,
626  _In_ LONG DeltaRows,
627  _In_ LONG DeltaX
628  );
629 
631  _In_ PPH_TREENEW_CONTEXT Context,
632  _In_ LONG DeltaRows,
633  _In_ LONG DeltaX
634  );
635 
636 BOOLEAN PhTnpCanScroll(
637  _In_ PPH_TREENEW_CONTEXT Context,
638  _In_ BOOLEAN Horizontal,
639  _In_ BOOLEAN Positive
640  );
641 
642 // Drawing
643 
645  _In_ HWND hwnd,
646  _In_ PPH_TREENEW_CONTEXT Context,
647  _In_ HDC hdc,
648  _In_ PRECT PaintRect
649  );
650 
652  _In_ PPH_TREENEW_CONTEXT Context,
653  _In_ HDC hdc,
654  _Inout_ PPH_TREENEW_NODE Node
655  );
656 
658  _In_ PPH_TREENEW_CONTEXT Context,
659  _In_ HDC hdc,
660  _In_ PRECT CellRect,
661  _In_ PPH_TREENEW_NODE Node,
662  _In_ PPH_TREENEW_COLUMN Column,
663  _In_ LONG RowIndex,
664  _In_ LONG ColumnIndex
665  );
666 
668  _In_ PPH_TREENEW_CONTEXT Context,
669  _In_ HDC hdc
670  );
671 
673  _In_ HDC hdc,
674  _In_ PRECT Rect,
675  _In_ BOOLEAN Plus
676  );
677 
679  _In_ PPH_TREENEW_CONTEXT Context,
680  _In_ HDC hdc,
681  _In_ PRECT Rect
682  );
683 
685  _In_ PPH_TREENEW_CONTEXT Context,
686  _In_ HDC hdc
687  );
688 
689 // Tooltips
690 
692  _In_ PPH_TREENEW_CONTEXT Context
693  );
694 
696  _In_ PPH_TREENEW_CONTEXT Context,
697  _In_ PPOINT Point,
698  _Out_ PWSTR *Text
699  );
700 
702  _In_ PPH_TREENEW_CONTEXT Context
703  );
704 
706  _In_ PPH_TREENEW_CONTEXT Context
707  );
708 
710  _In_ PPH_TREENEW_CONTEXT Context
711  );
712 
714  _In_ PPH_TREENEW_CONTEXT Context,
715  _In_ BOOLEAN Fixed,
716  _In_ PPOINT Point,
717  _Out_opt_ PRECT ItemRect
718  );
719 
721  _In_ PPH_TREENEW_CONTEXT Context,
722  _In_ BOOLEAN Fixed,
723  _In_ PPOINT Point,
724  _Out_ PWSTR *Text
725  );
726 
728  VOID
729  );
730 
731 LRESULT CALLBACK PhTnpHeaderHookWndProc(
732  _In_ HWND hwnd,
733  _In_ UINT uMsg,
734  _In_ WPARAM wParam,
735  _In_ LPARAM lParam
736  );
737 
738 // Drag selection
739 
740 BOOLEAN PhTnpDetectDrag(
741  _In_ PPH_TREENEW_CONTEXT Context,
742  _In_ LONG CursorX,
743  _In_ LONG CursorY,
744  _In_ BOOLEAN DispatchMessages,
745  _Out_opt_ PULONG CancelledByMessage
746  );
747 
749  _In_ PPH_TREENEW_CONTEXT Context,
750  _In_ LONG CursorX,
751  _In_ LONG CursorY
752  );
753 
755  _In_ PPH_TREENEW_CONTEXT Context,
756  _In_ ULONG VirtualKeys,
757  _In_ PRECT OldRect,
758  _In_ PRECT NewRect,
759  _In_ PRECT TotalRect
760  );
761 
762 // Double buffering
763 
765  _In_ PPH_TREENEW_CONTEXT Context
766  );
767 
769  _In_ PPH_TREENEW_CONTEXT Context
770  );
771 
772 // Support functions
773 
775  _In_ HWND hwnd,
776  _Out_ PPOINT ClientPoint
777  );
778 
779 // Macros
780 
781 #define HRGN_FULL ((HRGN)1) // passed by WM_NCPAINT even though it's completely undocumented
782 
783 #define TNP_CELL_LEFT_MARGIN 6
784 #define TNP_CELL_RIGHT_MARGIN 6
785 #define TNP_ICON_RIGHT_PADDING 4
786 
787 #define TNP_TIMER_NULL 1
788 #define TNP_TIMER_ANIMATE_DIVIDER 2
789 
790 #define TNP_TOOLTIPS_ITEM 0
791 #define TNP_TOOLTIPS_FIXED_HEADER 1
792 #define TNP_TOOLTIPS_HEADER 2
793 #define TNP_TOOLTIPS_DEFAULT_MAXIMUM_WIDTH 550
794 
795 #define TNP_ANIMATE_DIVIDER_INTERVAL 10
796 #define TNP_ANIMATE_DIVIDER_INCREMENT 17
797 #define TNP_ANIMATE_DIVIDER_DECREMENT 2
798 
799 #define TNP_HIT_TEST_FIXED_DIVIDER(X, Context) \
800  ((Context)->FixedDividerVisible && (X) >= (Context)->FixedWidth - 8 && (X) < (Context)->FixedWidth + 8)
801 #define TNP_HIT_TEST_PLUS_MINUS_GLYPH(X, NodeLevel) \
802  (((X) >= TNP_CELL_LEFT_MARGIN + ((LONG)(NodeLevel) * SmallIconWidth)) && ((X) < TNP_CELL_LEFT_MARGIN + ((LONG)(NodeLevel) * SmallIconWidth) + SmallIconWidth))
803 
804 #endif