ReactOS  0.4.12-dev-43-g63b00d8
affinity.c File Reference
#include "precomp.h"
Include dependency graph for affinity.c:

Go to the source code of this file.

Functions

static INT_PTR CALLBACK AffinityDialogWndProc (HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
 
void ProcessPage_OnSetAffinity (void)
 

Variables

HANDLE hProcessAffinityHandle
 
static const DWORD dwCpuTable []
 

Function Documentation

◆ AffinityDialogWndProc()

INT_PTR CALLBACK AffinityDialogWndProc ( HWND  hDlg,
UINT  message,
WPARAM  wParam,
LPARAM  lParam 
)
static

Definition at line 67 of file affinity.c.

Referenced by ProcessPage_OnSetAffinity().

68 {
69  DWORD_PTR dwProcessAffinityMask = 0;
70  DWORD_PTR dwSystemAffinityMask = 0;
71  WCHAR strErrorText[260];
72  WCHAR szTitle[256];
73  BYTE nCpu;
74 
75  switch (message) {
76  case WM_INITDIALOG:
77 
78  /*
79  * Get the current affinity mask for the process and
80  * the number of CPUs present in the system
81  */
82  if (!GetProcessAffinityMask(hProcessAffinityHandle, &dwProcessAffinityMask, &dwSystemAffinityMask)) {
83  GetLastErrorText(strErrorText, sizeof(strErrorText) / sizeof(WCHAR));
84  EndDialog(hDlg, 0);
85  LoadStringW(hInst, IDS_MSG_ACCESSPROCESSAFF, szTitle, sizeof(szTitle) / sizeof(WCHAR));
86  MessageBoxW(hMainWnd, strErrorText, szTitle, MB_OK|MB_ICONSTOP);
87  }
88 
89  for (nCpu=0; nCpu<sizeof(dwCpuTable) / sizeof(dwCpuTable[0]); nCpu++) {
90  /*
91  * Enable a checkbox for each processor present in the system
92  */
93  if (dwSystemAffinityMask & (1 << nCpu))
94  EnableWindow(GetDlgItem(hDlg, dwCpuTable[nCpu]), TRUE);
95  /*
96  * Check each checkbox that the current process
97  * has affinity with
98  */
99  if (dwProcessAffinityMask & (1 << nCpu))
100  CheckDlgButton(hDlg, dwCpuTable[nCpu], BST_CHECKED);
101  }
102 
103  return TRUE;
104 
105  case WM_COMMAND:
106 
107  /*
108  * If the user has cancelled the dialog box
109  * then just close it
110  */
111  if (LOWORD(wParam) == IDCANCEL) {
112  EndDialog(hDlg, LOWORD(wParam));
113  return TRUE;
114  }
115 
116  /*
117  * The user has clicked OK -- so now we have
118  * to adjust the process affinity mask
119  */
120  if (LOWORD(wParam) == IDOK) {
121  for (nCpu=0; nCpu<sizeof(dwCpuTable) / sizeof(dwCpuTable[0]); nCpu++) {
122  /*
123  * First we have to create a mask out of each
124  * checkbox that the user checked.
125  */
126  if (IsDlgButtonChecked(hDlg, dwCpuTable[nCpu]))
127  dwProcessAffinityMask |= (1 << nCpu);
128  }
129 
130  /*
131  * Make sure they are giving the process affinity
132  * with at least one processor. I'd hate to see a
133  * process that is not in a wait state get deprived
134  * of it's cpu time.
135  */
136  if (!dwProcessAffinityMask) {
137  LoadStringW(hInst, IDS_MSG_PROCESSONEPRO, strErrorText, sizeof(strErrorText) / sizeof(WCHAR));
138  LoadStringW(hInst, IDS_MSG_INVALIDOPTION, szTitle, sizeof(szTitle) / sizeof(WCHAR));
139  MessageBoxW(hDlg, strErrorText, szTitle, MB_OK|MB_ICONSTOP);
140  return TRUE;
141  }
142 
143  /*
144  * Try to set the process affinity
145  */
146  if (!SetProcessAffinityMask(hProcessAffinityHandle, dwProcessAffinityMask)) {
147  GetLastErrorText(strErrorText, sizeof(strErrorText) / sizeof(WCHAR));
148  EndDialog(hDlg, LOWORD(wParam));
149  LoadStringW(hInst, IDS_MSG_ACCESSPROCESSAFF, szTitle, sizeof(szTitle) / sizeof(WCHAR));
150  MessageBoxW(hMainWnd, strErrorText, szTitle, MB_OK|MB_ICONSTOP);
151  }
152 
153  EndDialog(hDlg, LOWORD(wParam));
154  return TRUE;
155  }
156 
157  break;
158  }
159 
160  return 0;
161 }
BOOL WINAPI CheckDlgButton(_In_ HWND, _In_ int, _In_ UINT)
Definition: tftpd.h:59
#define TRUE
Definition: types.h:120
#define IDOK
Definition: winuser.h:824
__wchar_t WCHAR
Definition: xmlstorage.h:180
#define MB_ICONSTOP
Definition: winuser.h:797
int WINAPI LoadStringW(_In_opt_ HINSTANCE hInstance, _In_ UINT uID, _Out_writes_to_(cchBufferMax, return+1) LPWSTR lpBuffer, _In_ int cchBufferMax)
WPARAM wParam
Definition: combotst.c:138
BOOL WINAPI EndDialog(_In_ HWND, _In_ INT_PTR)
#define IDS_MSG_ACCESSPROCESSAFF
Definition: resource.h:241
BOOL WINAPI SetProcessAffinityMask(IN HANDLE hProcess, IN DWORD_PTR dwProcessAffinityMask)
Definition: proc.c:924
UINT WINAPI IsDlgButtonChecked(_In_ HWND, _In_ int)
int WINAPI MessageBoxW(_In_opt_ HWND, _In_opt_ LPCWSTR, _In_opt_ LPCWSTR, _In_ UINT)
HWND WINAPI GetDlgItem(_In_opt_ HWND, _In_ int)
TCHAR szTitle[MAX_LOADSTRING]
Definition: magnifier.c:36
#define IDS_MSG_PROCESSONEPRO
Definition: resource.h:242
HWND hMainWnd
Definition: magnifier.c:33
#define WM_COMMAND
Definition: winuser.h:1716
uint32_t DWORD_PTR
Definition: typedefs.h:63
unsigned char BYTE
Definition: ntddk_ex.h:96
BOOL WINAPI EnableWindow(_In_ HWND, _In_ BOOL)
HINSTANCE hInst
Definition: dxdiag.c:13
LPWSTR GetLastErrorText(LPWSTR lpszBuf, DWORD dwSize)
Definition: taskmgr.c:1152
#define MB_OK
Definition: winuser.h:784
BOOL WINAPI GetProcessAffinityMask(IN HANDLE hProcess, OUT PDWORD_PTR lpProcessAffinityMask, OUT PDWORD_PTR lpSystemAffinityMask)
Definition: proc.c:893
#define BST_CHECKED
Definition: winuser.h:197
#define IDS_MSG_INVALIDOPTION
Definition: resource.h:243
HANDLE hProcessAffinityHandle
Definition: affinity.c:26
static const DWORD dwCpuTable[]
Definition: affinity.c:28
#define IDCANCEL
Definition: winuser.h:825
#define WM_INITDIALOG
Definition: winuser.h:1715
#define LOWORD(l)
Definition: pedump.c:82

◆ ProcessPage_OnSetAffinity()

void ProcessPage_OnSetAffinity ( void  )

Definition at line 41 of file affinity.c.

Referenced by TaskManagerWndProc().

42 {
43  DWORD dwProcessId;
44  WCHAR strErrorText[260];
45  WCHAR szTitle[256];
46 
47  dwProcessId = GetSelectedProcessId();
48 
49  if (dwProcessId == 0)
50  return;
51 
54  GetLastErrorText(strErrorText, sizeof(strErrorText) / sizeof(WCHAR));
55  LoadStringW(hInst, IDS_MSG_ACCESSPROCESSAFF, szTitle, sizeof(szTitle) / sizeof(WCHAR));
56  MessageBoxW(hMainWnd, strErrorText, szTitle, MB_OK|MB_ICONSTOP);
57  return;
58  }
63  }
64 }
DWORD GetSelectedProcessId(void)
Definition: procpage.c:99
#define CloseHandle
Definition: compat.h:398
#define IDD_AFFINITY_DIALOG
Definition: resource.h:23
#define PROCESS_QUERY_INFORMATION
Definition: pstypes.h:158
__wchar_t WCHAR
Definition: xmlstorage.h:180
#define MB_ICONSTOP
Definition: winuser.h:797
int WINAPI LoadStringW(_In_opt_ HINSTANCE hInstance, _In_ UINT uID, _Out_writes_to_(cchBufferMax, return+1) LPWSTR lpBuffer, _In_ int cchBufferMax)
#define IDS_MSG_ACCESSPROCESSAFF
Definition: resource.h:241
smooth NULL
Definition: ftsmooth.c:416
#define DialogBoxW(i, t, p, f)
Definition: winuser.h:4268
int WINAPI MessageBoxW(_In_opt_ HWND, _In_opt_ LPCWSTR, _In_opt_ LPCWSTR, _In_ UINT)
unsigned long DWORD
Definition: ntddk_ex.h:95
TCHAR szTitle[MAX_LOADSTRING]
Definition: magnifier.c:36
HWND hMainWnd
Definition: magnifier.c:33
HANDLE WINAPI OpenProcess(IN DWORD dwDesiredAccess, IN BOOL bInheritHandle, IN DWORD dwProcessId)
Definition: proc.c:1257
HINSTANCE hInst
Definition: dxdiag.c:13
static INT_PTR CALLBACK AffinityDialogWndProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
Definition: affinity.c:67
LPWSTR GetLastErrorText(LPWSTR lpszBuf, DWORD dwSize)
Definition: taskmgr.c:1152
#define MB_OK
Definition: winuser.h:784
HANDLE hProcessAffinityHandle
Definition: affinity.c:26
#define PROCESS_SET_INFORMATION
Definition: pstypes.h:157
#define MAKEINTRESOURCEW(i)
Definition: winuser.h:582

Variable Documentation

◆ dwCpuTable

const DWORD dwCpuTable[]
static
Initial value:
= {
}
#define IDC_CPU2
Definition: resource.h:40
#define IDC_CPU8
Definition: resource.h:54
#define IDC_CPU24
Definition: resource.h:100
#define IDC_CPU13
Definition: resource.h:70
#define IDC_CPU30
Definition: resource.h:119
#define IDC_CPU23
Definition: resource.h:99
#define IDC_CPU20
Definition: resource.h:91
#define IDC_CPU5
Definition: resource.h:46
#define IDC_CPU4
Definition: resource.h:44
#define IDC_CPU7
Definition: resource.h:51
#define IDC_CPU22
Definition: resource.h:97
#define IDC_CPU31
Definition: resource.h:122
#define IDC_CPU11
Definition: resource.h:64
#define IDC_CPU3
Definition: resource.h:42
#define IDC_CPU0
Definition: resource.h:38
#define IDC_CPU12
Definition: resource.h:67
#define IDC_CPU10
Definition: resource.h:60
#define IDC_CPU19
Definition: resource.h:88
#define IDC_CPU25
Definition: resource.h:103
#define IDC_CPU9
Definition: resource.h:57
#define IDC_CPU17
Definition: resource.h:82
#define IDC_CPU15
Definition: resource.h:76
#define IDC_CPU16
Definition: resource.h:79
#define IDC_CPU18
Definition: resource.h:85
#define IDC_CPU28
Definition: resource.h:112
#define IDC_CPU1
Definition: resource.h:39
#define IDC_CPU6
Definition: resource.h:49
#define IDC_CPU29
Definition: resource.h:115
#define IDC_CPU26
Definition: resource.h:106
#define IDC_CPU27
Definition: resource.h:109
#define IDC_CPU21
Definition: resource.h:94
#define IDC_CPU14
Definition: resource.h:73

Definition at line 28 of file affinity.c.

Referenced by AffinityDialogWndProc().

◆ hProcessAffinityHandle

HANDLE hProcessAffinityHandle

Definition at line 26 of file affinity.c.