Process Hacker
pagfiles.c
Go to the documentation of this file.
1 /*
2  * Process Hacker -
3  * pagefiles viewer
4  *
5  * Copyright (C) 2010 wj32
6  *
7  * This file is part of Process Hacker.
8  *
9  * Process Hacker is free software; you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation, either version 3 of the License, or
12  * (at your option) any later version.
13  *
14  * Process Hacker is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with Process Hacker. If not, see <http://www.gnu.org/licenses/>.
21  */
22 
23 #include <phapp.h>
24 
25 INT_PTR CALLBACK PhpPagefilesDlgProc(
26  _In_ HWND hwndDlg,
27  _In_ UINT uMsg,
28  _In_ WPARAM wParam,
29  _In_ LPARAM lParam
30  );
31 
33  _In_ HWND ParentWindowHandle
34  )
35 {
36  DialogBox(
38  MAKEINTRESOURCE(IDD_PAGEFILES),
39  ParentWindowHandle,
41  );
42 }
43 
44 static VOID PhpAddPagefileItems(
45  _In_ HWND ListViewHandle,
46  _In_ PVOID Pagefiles
47  )
48 {
50 
51  pagefile = PH_FIRST_PAGEFILE(Pagefiles);
52 
53  while (pagefile)
54  {
55  INT lvItemIndex;
56  PPH_STRING fileName;
57  PPH_STRING newFileName;
58  PPH_STRING usage;
59 
60  fileName = PhCreateStringFromUnicodeString(&pagefile->PageFileName);
61  newFileName = PhGetFileName(fileName);
62  PhDereferenceObject(fileName);
63 
64  lvItemIndex = PhAddListViewItem(ListViewHandle, MAXINT,
65  newFileName->Buffer, NULL);
66 
67  PhDereferenceObject(newFileName);
68 
69  // Usage
70  usage = PhFormatSize(UInt32x32To64(pagefile->TotalInUse, PAGE_SIZE), -1);
71  PhSetListViewSubItem(ListViewHandle, lvItemIndex, 1, usage->Buffer);
72  PhDereferenceObject(usage);
73 
74  // Peak usage
75  usage = PhFormatSize(UInt32x32To64(pagefile->PeakUsage, PAGE_SIZE), -1);
76  PhSetListViewSubItem(ListViewHandle, lvItemIndex, 2, usage->Buffer);
77  PhDereferenceObject(usage);
78 
79  // Total
80  usage = PhFormatSize(UInt32x32To64(pagefile->TotalSize, PAGE_SIZE), -1);
81  PhSetListViewSubItem(ListViewHandle, lvItemIndex, 3, usage->Buffer);
82  PhDereferenceObject(usage);
83 
84  pagefile = PH_NEXT_PAGEFILE(pagefile);
85  }
86 }
87 
88 INT_PTR CALLBACK PhpPagefilesDlgProc(
89  _In_ HWND hwndDlg,
90  _In_ UINT uMsg,
91  _In_ WPARAM wParam,
92  _In_ LPARAM lParam
93  )
94 {
95  switch (uMsg)
96  {
97  case WM_INITDIALOG:
98  {
99  NTSTATUS status;
100  HWND lvHandle;
101  PVOID pagefiles;
102 
103  PhCenterWindow(hwndDlg, GetParent(hwndDlg));
104 
105  lvHandle = GetDlgItem(hwndDlg, IDC_LIST);
106 
107  PhAddListViewColumn(lvHandle, 0, 0, 0, LVCFMT_LEFT, 120, L"File name");
108  PhAddListViewColumn(lvHandle, 1, 1, 1, LVCFMT_LEFT, 100, L"Usage");
109  PhAddListViewColumn(lvHandle, 2, 2, 2, LVCFMT_LEFT, 100, L"Peak usage");
110  PhAddListViewColumn(lvHandle, 3, 3, 3, LVCFMT_LEFT, 100, L"Total");
111  PhSetListViewStyle(lvHandle, FALSE, TRUE);
112  PhSetControlTheme(lvHandle, L"explorer");
113 
114  if (NT_SUCCESS(status = PhEnumPagefiles(&pagefiles)))
115  {
116  PhpAddPagefileItems(lvHandle, pagefiles);
117  PhFree(pagefiles);
118  }
119  else
120  {
121  PhShowStatus(hwndDlg, L"Unable to get pagefile information", status, 0);
122  EndDialog(hwndDlg, IDCANCEL);
123  }
124 
125  SendMessage(hwndDlg, WM_NEXTDLGCTL, (WPARAM)GetDlgItem(hwndDlg, IDOK), TRUE);
126  }
127  break;
128  case WM_COMMAND:
129  {
130  switch (LOWORD(wParam))
131  {
132  case IDCANCEL:
133  case IDOK:
134  EndDialog(hwndDlg, IDOK);
135  break;
136  case IDC_REFRESH:
137  {
138  NTSTATUS status;
139  PVOID pagefiles;
140 
141  if (NT_SUCCESS(status = PhEnumPagefiles(&pagefiles)))
142  {
143  ListView_DeleteAllItems(GetDlgItem(hwndDlg, IDC_LIST));
144  PhpAddPagefileItems(GetDlgItem(hwndDlg, IDC_LIST), pagefiles);
145  PhFree(pagefiles);
146  }
147  else
148  {
149  PhShowStatus(hwndDlg, L"Unable to get pagefile information", status, 0);
150  }
151  }
152  break;
153  }
154  }
155  break;
156  }
157 
158  return FALSE;
159 }