a2493ad071ccb3612ddd36a9035d4045c3e5a20f
[reactos.git] / rosapps / taskmgr / proclist.cpp
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 #ifdef _MSC_VER
24 #include "stdafx.h"
25 #else
26 #define WIN32_LEAN_AND_MEAN // Exclude rarely-used stuff from Windows headers
27 #include <windows.h>
28 #include <commctrl.h>
29 #include <stdlib.h>
30 #include <malloc.h>
31 #include <memory.h>
32 #include <tchar.h>
33 #include <process.h>
34 #include <stdio.h>
35 #endif
36
37 #include "taskmgr.h"
38 #include "ProcessPage.h"
39 #include "proclist.h"
40 #include "perfdata.h"
41
42
43 LRESULT CALLBACK ProcessListWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam);
44
45 LONG OldProcessListWndProc;
46
47
48 LRESULT CALLBACK ProcessListWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
49 {
50 HBRUSH hbrBackground;
51 RECT rcItem;
52 RECT rcClip;
53 HDC hDC;
54 int DcSave;
55
56 switch (message)
57 {
58 case WM_ERASEBKGND:
59
60 //
61 // The list control produces a nasty flicker
62 // when the user is resizing the window because
63 // it erases the background to white, then
64 // paints the list items over it.
65 //
66 // We will clip the drawing so that it only
67 // erases the parts of the list control that
68 // show only the background.
69 //
70
71 //
72 // Get the device context and save it's state
73 // to be restored after we're done
74 //
75 hDC = (HDC) wParam;
76 DcSave = SaveDC(hDC);
77
78 //
79 // Get the background brush
80 //
81 hbrBackground = (HBRUSH) GetClassLong(hWnd, GCL_HBRBACKGROUND);
82
83 //
84 // Calculate the clip rect by getting the RECT
85 // of the first and last items and adding them up.
86 //
87 // We also have to get the item's icon RECT and
88 // subtract it from our clip rect because we don't
89 // use icons in this list control.
90 //
91 ListView_GetItemRect(hWnd, 0, &rcClip, LVIR_BOUNDS);
92 ListView_GetItemRect(hWnd, ListView_GetItemCount(hWnd) - 1, &rcItem, LVIR_BOUNDS);
93 rcClip.bottom = rcItem.bottom;
94 ListView_GetItemRect(hWnd, 0, &rcItem, LVIR_ICON);
95 rcClip.left = rcItem.right;
96
97 //
98 // Now exclude the clip rect
99 //
100 ExcludeClipRect(hDC, rcClip.left, rcClip.top, rcClip.right, rcClip.bottom);
101
102 //
103 // Now erase the background
104 //
105 //
106 // FIXME: Should I erase it myself or
107 // pass down the updated HDC and let
108 // the default handler do it?
109 //
110 GetClientRect(hWnd, &rcItem);
111 FillRect(hDC, &rcItem, hbrBackground);
112
113 //
114 // Now restore the DC state that we
115 // saved earlier
116 //
117 RestoreDC(hDC, DcSave);
118
119 return TRUE;
120 }
121
122 //
123 // We pass on all messages except WM_ERASEBKGND
124 //
125 return CallWindowProc((WNDPROC)OldProcessListWndProc, hWnd, message, wParam, lParam);
126 }