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