32 typedef struct _AFFINITY_DIALOG_CONTEXT
36 ULONG_PTR AffinityMask;
37 ULONG_PTR NewAffinityMask;
48 _In_ HWND ParentWindowHandle,
55 assert(!!ProcessItem != !!ThreadItem);
57 context.ProcessItem = ProcessItem;
58 context.ThreadItem = ThreadItem;
70 _In_ HWND ParentWindowHandle,
71 _In_ ULONG_PTR AffinityMask,
72 _Out_ PULONG_PTR NewAffinityMask
77 context.ProcessItem = NULL;
78 context.ThreadItem = NULL;
79 context.AffinityMask = AffinityMask;
89 *NewAffinityMask = context.NewAffinityMask;
113 ULONG_PTR systemAffinityMask;
114 ULONG_PTR affinityMask;
120 systemAffinityMask = 0;
122 if (context->ProcessItem)
124 HANDLE processHandle;
125 PROCESS_BASIC_INFORMATION basicInfo;
130 context->ProcessItem->ProcessId
136 affinityMask = basicInfo.AffinityMask;
138 NtClose(processHandle);
141 else if (context->ThreadItem)
145 HANDLE processHandle;
146 PROCESS_BASIC_INFORMATION processBasicInfo;
151 context->ThreadItem->ThreadId
170 systemAffinityMask = processBasicInfo.AffinityMask;
172 NtClose(processHandle);
176 NtClose(threadHandle);
181 affinityMask = context->AffinityMask;
182 status = STATUS_SUCCESS;
185 if (
NT_SUCCESS(status) && systemAffinityMask == 0)
187 status = NtQuerySystemInformation(
200 PhShowStatus(hwndDlg, L
"Unable to retrieve the affinity", status, 0);
201 EndDialog(hwndDlg, IDCANCEL);
208 for (i = 0; i < 8 * 8; i++)
210 if ((i <
sizeof(ULONG_PTR) * 8) && ((systemAffinityMask >> i) & 0x1))
212 if ((affinityMask >> i) & 0x1)
214 Button_SetCheck(GetDlgItem(hwndDlg,
IDC_CPU0 + i), BST_CHECKED);
231 switch (LOWORD(wParam))
234 EndDialog(hwndDlg, IDCANCEL);
241 ULONG_PTR affinityMask;
247 for (i = 0; i <
sizeof(ULONG_PTR) * 8; i++)
249 if (Button_GetCheck(GetDlgItem(hwndDlg,
IDC_CPU0 + i)) == BST_CHECKED)
250 affinityMask |= (ULONG_PTR)1 << i;
253 if (context->ProcessItem)
255 HANDLE processHandle;
260 context->ProcessItem->ProcessId
264 NtClose(processHandle);
267 else if (context->ThreadItem)
274 context->ThreadItem->ThreadId
278 NtClose(threadHandle);
283 context->NewAffinityMask = affinityMask;
284 status = STATUS_SUCCESS;
288 EndDialog(hwndDlg, IDOK);
290 PhShowStatus(hwndDlg, L
"Unable to set the affinity", status, 0);
298 for (i = 0; i <
sizeof(ULONG_PTR) * 8; i++)
300 HWND checkBox = GetDlgItem(hwndDlg,
IDC_CPU0 + i);
302 if (IsWindowEnabled(checkBox))
303 Button_SetCheck(checkBox, LOWORD(wParam) ==
IDC_SELECTALL ? BST_CHECKED : BST_UNCHECKED);