8ca34332d83d0827819b45d5efcfb98ac4302ce9
[reactos.git] / rosapps / taskmgr / proclist.c
1 /*
2 * ReactOS Task Manager
3 *
4 * proclist.cpp
5 *
6 * Copyright (C) 1999 - 2001 Brian Palmer <brianp@reactos.org>
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
12 *
13 * This program 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
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21 */
22
23 #define WIN32_LEAN_AND_MEAN // Exclude rarely-used stuff from Windows headers
24 #include <windows.h>
25 #include <commctrl.h>
26 #include <stdlib.h>
27 #include <malloc.h>
28 #include <memory.h>
29 #include <tchar.h>
30 #include <process.h>
31 #include <stdio.h>
32
33 #include "taskmgr.h"
34 #include "procpage.h"
35 #include "proclist.h"
36 #include "perfdata.h"
37
38
39 LRESULT CALLBACK ProcessListWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam);
40
41 LONG OldProcessListWndProc;
42
43
44 LRESULT CALLBACK ProcessListWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
45 {
46 HBRUSH hbrBackground;
47 RECT rcItem;
48 RECT rcClip;
49 HDC hDC;
50 int DcSave;
51
52 switch (message)
53 {
54 case WM_ERASEBKGND:
55
56 //
57 // The list control produces a nasty flicker
58 // when the user is resizing the window because
59 // it erases the background to white, then
60 // paints the list items over it.
61 //
62 // We will clip the drawing so that it only
63 // erases the parts of the list control that
64 // show only the background.
65 //
66
67 //
68 // Get the device context and save it's state
69 // to be restored after we're done
70 //
71 hDC = (HDC) wParam;
72 DcSave = SaveDC(hDC);
73
74 //
75 // Get the background brush
76 //
77 hbrBackground = (HBRUSH) GetClassLong(hWnd, GCL_HBRBACKGROUND);
78
79 //
80 // Calculate the clip rect by getting the RECT
81 // of the first and last items and adding them up.
82 //
83 // We also have to get the item's icon RECT and
84 // subtract it from our clip rect because we don't
85 // use icons in this list control.
86 //
87 ListView_GetItemRect(hWnd, 0, &rcClip, LVIR_BOUNDS);
88 ListView_GetItemRect(hWnd, ListView_GetItemCount(hWnd) - 1, &rcItem, LVIR_BOUNDS);
89 rcClip.bottom = rcItem.bottom;
90 ListView_GetItemRect(hWnd, 0, &rcItem, LVIR_ICON);
91 rcClip.left = rcItem.right;
92
93 //
94 // Now exclude the clip rect
95 //
96 ExcludeClipRect(hDC, rcClip.left, rcClip.top, rcClip.right, rcClip.bottom);
97
98 //
99 // Now erase the background
100 //
101 //
102 // FIXME: Should I erase it myself or
103 // pass down the updated HDC and let
104 // the default handler do it?
105 //
106 GetClientRect(hWnd, &rcItem);
107 FillRect(hDC, &rcItem, hbrBackground);
108
109 //
110 // Now restore the DC state that we
111 // saved earlier
112 //
113 RestoreDC(hDC, DcSave);
114
115 return TRUE;
116 }
117
118 //
119 // We pass on all messages except WM_ERASEBKGND
120 //
121 return CallWindowProc((WNDPROC)OldProcessListWndProc, hWnd, message, wParam, lParam);
122 }