Merge 25584, 25588.
[reactos.git] / reactos / base / applications / taskmgr / proclist.c
1 /*
2 * ReactOS Task Manager
3 *
4 * proclist.c
5 *
6 * Copyright (C) 1999 - 2001 Brian Palmer <brianp@reactos.org>
7 *
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
11 * version 2.1 of the License, or (at your option) any later version.
12 *
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
17 *
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with this library; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 */
22
23 #include <precomp.h>
24
25
26 INT_PTR CALLBACK ProcessListWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam);
27
28 WNDPROC OldProcessListWndProc;
29
30
31 INT_PTR CALLBACK
32 ProcessListWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
33 {
34 HBRUSH hbrBackground;
35 RECT rcItem;
36 RECT rcClip;
37 HDC hDC;
38 int DcSave;
39
40 switch (message)
41 {
42 case WM_ERASEBKGND:
43
44 /*
45 * The list control produces a nasty flicker
46 * when the user is resizing the window because
47 * it erases the background to white, then
48 * paints the list items over it.
49 *
50 * We will clip the drawing so that it only
51 * erases the parts of the list control that
52 * show only the background.
53 */
54
55 /*
56 * Get the device context and save it's state
57 * to be restored after we're done
58 */
59 hDC = (HDC) wParam;
60 DcSave = SaveDC(hDC);
61
62 /*
63 * Get the background brush
64 */
65 hbrBackground = (HBRUSH)(LONG_PTR) GetClassLongPtr(hWnd, GCL_HBRBACKGROUND);
66
67 /*
68 * Calculate the clip rect by getting the RECT
69 * of the first and last items and adding them up.
70 *
71 * We also have to get the item's icon RECT and
72 * subtract it from our clip rect because we don't
73 * use icons in this list control.
74 */
75 (void)ListView_GetItemRect(hWnd, 0, &rcClip, LVIR_BOUNDS);
76 (void)ListView_GetItemRect(hWnd, ListView_GetItemCount(hWnd) - 1, &rcItem, LVIR_BOUNDS);
77 rcClip.bottom = rcItem.bottom;
78 (void)ListView_GetItemRect(hWnd, 0, &rcItem, LVIR_ICON);
79 rcClip.left = rcItem.right;
80
81 /*
82 * Now exclude the clip rect
83 */
84 ExcludeClipRect(hDC, rcClip.left, rcClip.top, rcClip.right, rcClip.bottom);
85
86 /*
87 * Now erase the background
88 *
89 *
90 * FIXME: Should I erase it myself or
91 * pass down the updated HDC and let
92 * the default handler do it?
93 */
94 GetClientRect(hWnd, &rcItem);
95 FillRect(hDC, &rcItem, hbrBackground);
96
97 /*
98 * Now restore the DC state that we
99 * saved earlier
100 */
101 RestoreDC(hDC, DcSave);
102
103 return TRUE;
104 }
105
106 /*
107 * We pass on all messages except WM_ERASEBKGND
108 */
109 return CallWindowProc(OldProcessListWndProc, hWnd, message, wParam, lParam);
110 }