Skip to content

Commit 5363033

Browse files
committed
Added new columns: DPI Awareness, company, and description.
1 parent edf8630 commit 5363033

6 files changed

Lines changed: 101 additions & 8 deletions

File tree

CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,4 @@ if(MSVC)
88
target_compile_options(taskmon PRIVATE /GS- /W4 /Os /Oy)
99
target_link_options(taskmon PRIVATE /NODEFAULTLIB /ENTRY:WinMainCRTStartup /SUBSYSTEM:WINDOWS /OPT:REF /OPT:ICF /MERGE:.rdata=.text /MERGE:.pdata=.text)
1010
endif()
11-
target_link_libraries(taskmon PRIVATE kernel32 user32 gdi32 shell32 comctl32 ole32 shlwapi ntdll advapi32 dwmapi uxtheme comdlg32)
11+
target_link_libraries(taskmon PRIVATE kernel32 user32 gdi32 shell32 comctl32 ole32 shlwapi ntdll advapi32 dwmapi uxtheme comdlg32 version)

src/listview.c

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,23 @@ static void format_column(const process_entry* e, column_id cid, wchar_t* buf, i
153153
lstrcat(buf, L"/s");
154154
} else buf[0] = L'\0';
155155
break;
156+
case COL_DESCRIPTION:
157+
lstrcpyn(buf, e->description, len);
158+
break;
159+
case COL_COMPANY:
160+
lstrcpyn(buf, e->company, len);
161+
break;
162+
case COL_DPI: {
163+
const wchar_t* label;
164+
switch (e->dpi_awareness) {
165+
case TM_DPI_UNAWARE: label = L"Unaware"; break;
166+
case TM_DPI_SYSTEM_AWARE: label = L"System"; break;
167+
case TM_DPI_PER_MONITOR_AWARE: label = L"Per-Monitor"; break;
168+
default: label = L"Unknown"; break;
169+
}
170+
lstrcpyn(buf, label, len);
171+
break;
172+
}
156173
default:
157174
buf[0] = L'\0';
158175
break;

src/process.c

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,15 @@ static int compare_entries(const process_entry* a, const process_entry* b, sort_
200200
case SORT_FIELD_IO_OTHER:
201201
res = (a->io_other_rate < b->io_other_rate) ? -1 : (a->io_other_rate > b->io_other_rate);
202202
break;
203+
case SORT_FIELD_DESCRIPTION:
204+
res = StrCmpI(a->description, b->description);
205+
break;
206+
case SORT_FIELD_COMPANY:
207+
res = StrCmpI(a->company, b->company);
208+
break;
209+
case SORT_FIELD_DPI:
210+
res = (int)a->dpi_awareness - (int)b->dpi_awareness;
211+
break;
203212
default:
204213
break;
205214
}
@@ -361,6 +370,53 @@ static void get_process_cmdline(DWORD pid, wchar_t* buf, int len) {
361370
CloseHandle(h);
362371
}
363372

373+
static void get_process_version_info(DWORD pid, wchar_t* desc, int desc_len, wchar_t* company, int comp_len) {
374+
desc[0] = L'\0';
375+
company[0] = L'\0';
376+
wchar_t path[MAX_PATH];
377+
get_process_path(pid, path, MAX_PATH);
378+
if (!path[0]) return;
379+
DWORD dummy;
380+
DWORD size = GetFileVersionInfoSizeW(path, &dummy);
381+
if (size == 0) return;
382+
void* data = heap_alloc(size);
383+
if (data) {
384+
if (GetFileVersionInfoW(path, 0, size, data)) {
385+
struct { USHORT lang; USHORT codepage; } *translate;
386+
UINT tlen;
387+
if (VerQueryValueW(data, L"\\VarFileInfo\\Translation", (LPVOID*)&translate, &tlen) && tlen >= sizeof(*translate)) {
388+
wchar_t subblock[64];
389+
wchar_t* value;
390+
UINT vlen;
391+
wnsprintf(subblock, 64, L"\\StringFileInfo\\%04x%04x\\FileDescription", translate[0].lang, translate[0].codepage);
392+
if (VerQueryValueW(data, subblock, (LPVOID*)&value, &vlen)) lstrcpyn(desc, value, desc_len);
393+
wnsprintf(subblock, 64, L"\\StringFileInfo\\%04x%04x\\CompanyName", translate[0].lang, translate[0].codepage);
394+
if (VerQueryValueW(data, subblock, (LPVOID*)&value, &vlen)) lstrcpyn(company, value, comp_len);
395+
}
396+
}
397+
heap_free(data);
398+
}
399+
}
400+
401+
static tm_dpi_awareness get_process_dpi_awareness(DWORD pid) {
402+
typedef HRESULT (WINAPI *PFN_GPDA)(HANDLE, int*);
403+
static PFN_GPDA fn = NULL;
404+
static BOOL checked = FALSE;
405+
if (!checked) {
406+
HMODULE h = GetModuleHandle(L"shcore.dll");
407+
if (!h) h = LoadLibrary(L"shcore.dll");
408+
if (h) fn = (PFN_GPDA)GetProcAddress(h, "GetProcessDpiAwareness");
409+
checked = TRUE;
410+
}
411+
if (!fn) return TM_DPI_UNAWARE;
412+
HANDLE h = OpenProcess(PROCESS_QUERY_LIMITED_INFORMATION, FALSE, pid);
413+
if (!h) return TM_DPI_UNAWARE;
414+
int awareness = 0;
415+
fn(h, &awareness);
416+
CloseHandle(h);
417+
return (tm_dpi_awareness)awareness;
418+
}
419+
364420
process_entry* snapshot_processes(snapshot_entry* snapshots, int* out_count, sort_field field, BOOL descending) {
365421
FILETIME sys_idle_ft, sys_kernel_ft, sys_user_ft;
366422
GetSystemTimes(&sys_idle_ft, &sys_kernel_ft, &sys_user_ft);
@@ -413,6 +469,8 @@ process_entry* snapshot_processes(snapshot_entry* snapshots, int* out_count, sor
413469
e->integrity_level = get_process_integrity(pid);
414470
get_process_user(pid, e->user, 64);
415471
get_process_cmdline(pid, e->cmdline, 256);
472+
get_process_version_info(pid, e->description, 128, e->company, 128);
473+
e->dpi_awareness = get_process_dpi_awareness(pid);
416474
e->arch_machine = get_process_arch(pid);
417475
if (pid == 0) {
418476
lstrcpy(e->name, L"System Idle Process");

src/process.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,25 @@ typedef enum {
2929
SORT_FIELD_IO_READ,
3030
SORT_FIELD_IO_WRITE,
3131
SORT_FIELD_IO_OTHER,
32+
SORT_FIELD_DESCRIPTION,
33+
SORT_FIELD_COMPANY,
34+
SORT_FIELD_DPI,
3235
SORT_FIELD_COUNT,
3336
} sort_field;
3437

38+
typedef enum {
39+
TM_DPI_UNAWARE = 0,
40+
TM_DPI_SYSTEM_AWARE = 1,
41+
TM_DPI_PER_MONITOR_AWARE = 2
42+
} tm_dpi_awareness;
43+
3544
typedef struct {
3645
DWORD pid;
3746
DWORD parent_pid;
3847
wchar_t name[64];
48+
wchar_t description[128];
49+
wchar_t company[128];
50+
tm_dpi_awareness dpi_awareness;
3951
double cpu_percent;
4052
SIZE_T working_set;
4153
SIZE_T private_working_set;

src/settings.c

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,21 +18,24 @@ const column_def COLUMNS[COL_COUNT] = {
1818
{ L"Private Bytes", L"Private Bytes", 120, SORT_FIELD_PRIVATE_BYTES, FALSE, FALSE },
1919
{ L"Page Faults", L"Page Faults", 100, SORT_FIELD_PAGE_FAULTS, FALSE, FALSE },
2020
{ L"User", L"User", 120, SORT_FIELD_USER, FALSE, FALSE },
21-
{ L"Command Line", L"Command Line", 300, SORT_FIELD_CMDLINE, FALSE, FALSE },
21+
{ L"Command Line", L"Command Line", 500, SORT_FIELD_CMDLINE, FALSE, FALSE },
2222
{ L"Architecture", L"Architecture", 70, SORT_FIELD_ARCH, FALSE, FALSE },
2323
{ L"Session", L"Session", 60, SORT_FIELD_SESSION, FALSE, FALSE },
2424
{ L"Peak Memory", L"Peak Memory", 120, SORT_FIELD_PEAK_WORKING_SET, FALSE, FALSE },
25-
{ L"Virtual Memory", L"Virtual Mem", 120, SORT_FIELD_VIRTUAL_MEM, FALSE, FALSE },
26-
{ L"GDI Objects", L"GDI Obj", 70, SORT_FIELD_GDI_OBJECTS, FALSE, FALSE },
27-
{ L"USER Objects", L"USER Obj", 70, SORT_FIELD_USER_OBJECTS, FALSE, FALSE },
25+
{ L"Virtual Memory", L"Virtual Memory", 120, SORT_FIELD_VIRTUAL_MEM, FALSE, FALSE },
26+
{ L"GDI Objects", L"GDI Objects", 70, SORT_FIELD_GDI_OBJECTS, FALSE, FALSE },
27+
{ L"USER Objects", L"USER Objects", 70, SORT_FIELD_USER_OBJECTS, FALSE, FALSE },
2828
{ L"Integrity", L"Integrity", 80, SORT_FIELD_INTEGRITY, FALSE, FALSE },
29-
{ L"Parent PID", L"PPID", 80, SORT_FIELD_PPID, FALSE, FALSE },
30-
{ L"Private WS", L"Private WS", 100, SORT_FIELD_PRIVATE_WS, FALSE, FALSE },
29+
{ L"Parent PID", L"Parent PID", 80, SORT_FIELD_PPID, FALSE, FALSE },
30+
{ L"Private Working Set", L"Private Working Set", 100, SORT_FIELD_PRIVATE_WS, FALSE, FALSE },
3131
{ L"Paged Pool", L"Paged Pool", 100, SORT_FIELD_PAGED_POOL, FALSE, FALSE },
32-
{ L"Non-paged Pool", L"NP Pool", 100, SORT_FIELD_NONPAGED_POOL, FALSE, FALSE },
32+
{ L"Non-paged Pool", L"Non-paged Pool", 100, SORT_FIELD_NONPAGED_POOL, FALSE, FALSE },
3333
{ L"I/O Read", L"I/O Read", 100, SORT_FIELD_IO_READ, FALSE, FALSE },
3434
{ L"I/O Write", L"I/O Write", 100, SORT_FIELD_IO_WRITE, FALSE, FALSE },
3535
{ L"I/O Other", L"I/O Other", 100, SORT_FIELD_IO_OTHER, FALSE, FALSE },
36+
{ L"Description", L"Description", 200, SORT_FIELD_DESCRIPTION, FALSE, FALSE },
37+
{ L"Company", L"Company", 150, SORT_FIELD_COMPANY, FALSE, FALSE },
38+
{ L"DPI Awareness", L"DPI Awareness", 90, SORT_FIELD_DPI, FALSE, FALSE },
3639
};
3740

3841
const UINT REFRESH_MS[REFRESH_OPTION_COUNT] = { 0, 5000, 10000, 30000, 60000 };

src/settings.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,9 @@ typedef enum {
2929
COL_IO_READ,
3030
COL_IO_WRITE,
3131
COL_IO_OTHER,
32+
COL_DESCRIPTION,
33+
COL_COMPANY,
34+
COL_DPI,
3235
COL_COUNT,
3336
} column_id;
3437

0 commit comments

Comments
 (0)