ReactOS  0.4.14-dev-368-gfa26425
dialog.c
Go to the documentation of this file.
1 /*
2  * PROJECT: ReactOS Utility Manager (Accessibility)
3  * LICENSE: GPL-2.0+ (https://spdx.org/licenses/GPL-2.0+)
4  * PURPOSE: Main dialog code file
5  * COPYRIGHT: Copyright 2019 BiČ™oc George (fraizeraust99 at gmail dot com)
6  * Copyright 2019 Hermes Belusca-Maito
7  */
8 
9 /* INCLUDES *******************************************************************/
10 
11 #include "precomp.h"
12 
13 /* GLOBALS ********************************************************************/
14 
16 
17 /* DECLARATIONS ***************************************************************/
18 
20 {
21  {L"magnify.exe", IDS_MAGNIFIER, L"", FALSE},
22  {L"osk.exe", IDS_OSK, L"", FALSE}
23 };
24 
25 /* FUNCTIONS ******************************************************************/
26 
39 {
40  UINT i;
41 
42  if (!bInitGui)
43  {
44  // TODO: Load the list dynamically from the registry key
45  // hklm\software\microsoft\windows nt\currentversion\accessibility
46 
47  /* Initialize the resource utility strings only once */
48  for (i = 0; i < _countof(EntriesList); ++i)
49  {
51  EntriesList[i].szResource, _countof(EntriesList[i].szResource));
52 
54  }
55  }
56  else
57  {
58  INT iItem;
59  BOOL bIsRunning;
60  WCHAR szFormat[MAX_BUFFER];
61 
62  /* Reset the listbox */
64 
65  /* Add the utilities in the listbox */
66  for (i = 0; i < _countof(EntriesList); ++i)
67  {
68  bIsRunning = IsProcessRunning(EntriesList[i].lpProgram);
69  EntriesList[i].bState = bIsRunning;
70 
71  /* Load the string and append the utility's name to the format */
72  StringCchPrintfW(szFormat, _countof(szFormat),
73  (bIsRunning ? Globals.szRunning : Globals.szNotRunning),
75 
76  /* Add the item in the listbox */
77  iItem = (INT)SendMessageW(Globals.hListDlg, LB_ADDSTRING, 0, (LPARAM)szFormat);
78  if (iItem != LB_ERR)
80  }
81  }
82 }
83 
98 {
99  INT PosX, PosY;
100  RECT rc;
101  WCHAR szAboutDlg[MAX_BUFFER];
102  HMENU hSysMenu;
103 
104  /* Save the dialog handle */
105  Globals.hMainDlg = hDlg;
106 
107  /* Center the dialog on the screen */
108  GetWindowRect(hDlg, &rc);
109  PosX = (GetSystemMetrics(SM_CXSCREEN) - rc.right) / 2;
110  PosY = (GetSystemMetrics(SM_CYSCREEN) - rc.bottom) / 2;
111  SetWindowPos(hDlg, 0, PosX, PosY, 0, 0, SWP_NOZORDER | SWP_NOSIZE);
112 
113  /* Load the icon resource */
116  IMAGE_ICON,
117  0,
118  0,
120 
121  /* Set the icon within the dialog's title bar */
122  if (Globals.hIcon)
123  {
124  SendMessageW(hDlg, WM_SETICON, ICON_SMALL, (LPARAM)Globals.hIcon);
125  }
126 
127  /* Retrieve the system menu and append the "About" menu item onto it */
128  hSysMenu = GetSystemMenu(hDlg, FALSE);
129  if (hSysMenu != NULL)
130  {
131  if (LoadStringW(Globals.hInstance, IDM_ABOUT, szAboutDlg, _countof(szAboutDlg)))
132  {
133  AppendMenuW(hSysMenu, MF_SEPARATOR, 0, NULL);
134  AppendMenuW(hSysMenu, MF_STRING, IDM_ABOUT, szAboutDlg);
135  }
136  }
137 
138  /* Get the dialog items, specifically the dialog list box, the Start and Stop buttons */
142 
143  /* Initialize the GUI listbox */
145 
146  /* Set the selection to the first item */
148 
149  /* Refresh the list */
151 
152  /* Create a timer, we'll use it to control the state of our items in the listbox */
153  Globals.iTimer = SetTimer(hDlg, 0, 400, NULL);
154 
155  return TRUE;
156 }
157 
168 {
169  WCHAR szFormat[MAX_BUFFER];
170 
171  /* Format the string with the utility's name and set it to the listbox's title */
174 }
175 
189 {
190  Button_Enable(Globals.hDlgCtlStart, !bUtilState);
191  Button_Enable(Globals.hDlgCtlStop, bUtilState);
192 
193  /* Update the groupbox's title based on the selected utility item */
195 }
196 
207 {
208  UINT i;
209  INT iItem;
210  BOOL bIsRunning;
211  WCHAR szFormat[MAX_BUFFER];
212 
213  /* Disable listbox redraw */
215 
216  for (i = 0; i < _countof(EntriesList); ++i)
217  {
218  /* Check the utility's state */
219  bIsRunning = IsProcessRunning(EntriesList[i].lpProgram);
220  if (bIsRunning != EntriesList[i].bState)
221  {
222  /* The utility's state has changed, save it */
223  EntriesList[i].bState = bIsRunning;
224 
225  /* Update the corresponding item in the listbox */
226  StringCchPrintfW(szFormat, _countof(szFormat),
227  (bIsRunning ? Globals.szRunning : Globals.szNotRunning),
229 
231  iItem = SendMessageW(Globals.hListDlg, LB_INSERTSTRING, (LPARAM)i, (LPARAM)szFormat);
232  if (iItem != LB_ERR)
234  }
235  }
236 
237  /* Re-enable listbox redraw */
239 
240  /*
241  * Check the previously selected item. This will help us determine what
242  * item has been selected and set its focus selection back. Furthermore, check
243  * the state of each accessibility tool and enable/disable the buttons.
244  */
247 
248  return 0;
249 }
250 
273  IN HWND hDlg,
274  IN UINT Msg,
275  IN WPARAM wParam,
276  IN LPARAM lParam)
277 {
278  switch (Msg)
279  {
280  case WM_INITDIALOG:
281  DlgInitHandler(hDlg);
282  return TRUE;
283 
284  case WM_CLOSE:
285  KillTimer(hDlg, Globals.iTimer);
287  EndDialog(hDlg, FALSE);
288  break;
289 
290  case WM_COMMAND:
291  {
292  switch (LOWORD(wParam))
293  {
294  case IDC_OK:
295  case IDC_CANCEL:
296  EndDialog(hDlg, FALSE);
297  break;
298 
299  case IDC_LISTBOX:
300  {
301  switch (HIWORD(wParam))
302  {
303  case LBN_SELCHANGE:
304  {
305  /* Retrieve the index of the current selected item */
306  INT iIndex = SendMessageW(Globals.hListDlg, LB_GETCURSEL, 0, 0);
307  if ((iIndex == LB_ERR) || (iIndex >= _countof(EntriesList)))
308  break;
309 
310  /* Assign the selected index and check the utility's state */
311  Globals.iSelectedIndex = iIndex;
313  break;
314  }
315  break;
316  }
317  break;
318  }
319 
320  case IDC_START:
322  break;
323 
324  case IDC_STOP:
326  break;
327 
328  default:
329  break;
330  }
331  break;
332  }
333 
334  case WM_TIMER:
336  return 0;
337 
338  case WM_SYSCOMMAND:
339  {
340  switch (LOWORD(wParam))
341  {
342  case IDM_ABOUT:
343  ShowAboutDlg(hDlg);
344  break;
345  }
346  break;
347  }
348  }
349 
350  return 0;
351 }
352 
376  IN HINSTANCE hPrevInstance,
377  IN LPWSTR pCmdLine,
378  IN INT nCmdShow)
379 {
380  HANDLE hMutex;
381  DWORD dwError;
382  INITCOMMONCONTROLSEX iccex;
383 
384  UNREFERENCED_PARAMETER(hPrevInstance);
385  UNREFERENCED_PARAMETER(pCmdLine);
386  UNREFERENCED_PARAMETER(nCmdShow);
387 
388  /* Create a mutant object for the program. */
389  hMutex = CreateMutexW(NULL, FALSE, L"Utilman");
390  if (hMutex)
391  {
392  /* Check if there's already a mutex for the program */
393  dwError = GetLastError();
394  if (dwError == ERROR_ALREADY_EXISTS)
395  {
396  /*
397  The program's instance is already here. That means
398  the program is running and we should not set a new instance
399  and mutex object.
400  */
402  return 0;
403  }
404  }
405 
406  /* Load the common controls for the program */
407  iccex.dwSize = sizeof(INITCOMMONCONTROLSEX);
409  InitCommonControlsEx(&iccex);
410 
411  /* Initialize the globals */
412  ZeroMemory(&Globals, sizeof(Globals));
414 
421 
422  /* Initialize the list of accessibility utilities */
424 
425  /* Create the dialog box of the program */
429  DlgProc);
430 
431  /* Delete the mutex */
432  if (hMutex)
433  {
435  }
436 
437  return 0;
438 }
#define LB_SETCURSEL
Definition: winuser.h:2045
#define IN
Definition: typedefs.h:38
#define TRUE
Definition: types.h:120
#define CloseHandle
Definition: compat.h:406
#define IMAGE_ICON
Definition: winuser.h:212
UINT uNameId
Definition: precomp.h:48
VOID ShowAboutDlg(HWND hWndParent)
Definition: about.c:77
#define IDM_ABOUT
Definition: resource.h:29
#define LB_ADDSTRING
Definition: winuser.h:2013
BOOL WINAPI DestroyIcon(_In_ HICON)
Definition: cursoricon.c:2022
#define UNREFERENCED_PARAMETER(P)
Definition: ntbasedef.h:323
#define IDS_MAGNIFIER
Definition: resource.h:20
#define _countof(array)
Definition: fontsub.cpp:30
struct @1591 Msg[]
#define INT
Definition: polytest.cpp:20
#define IDI_ICON_UTILMAN
Definition: resource.h:13
BOOL IsProcessRunning(IN LPCWSTR lpProcessName)
Definition: process.c:27
#define WM_SETREDRAW
Definition: winuser.h:1598
#define MF_STRING
Definition: winuser.h:138
HINSTANCE hInstance
Definition: precomp.h:32
DWORD WINAPI GetLastError(VOID)
Definition: except.c:1059
#define ZeroMemory
Definition: winbase.h:1642
#define Button_Enable(hwndCtl, fEnable)
Definition: windowsx.h:5
#define IDC_GROUPBOX
Definition: resource.h:27
WCHAR szResource[MAX_BUFFER]
Definition: precomp.h:49
BOOL WINAPI SetWindowTextW(_In_ HWND, _In_opt_ LPCWSTR)
UINT_PTR WPARAM
Definition: windef.h:207
#define SWP_NOZORDER
Definition: winuser.h:1232
int32_t INT_PTR
Definition: typedefs.h:62
LONG right
Definition: windef.h:293
#define LBN_SELCHANGE
Definition: winuser.h:2057
int WINAPI LoadStringW(_In_opt_ HINSTANCE hInstance, _In_ UINT uID, _Out_writes_to_(cchBufferMax, return+1) LPWSTR lpBuffer, _In_ int cchBufferMax)
struct tagINITCOMMONCONTROLSEX INITCOMMONCONTROLSEX
int32_t INT
Definition: typedefs.h:56
WPARAM wParam
Definition: combotst.c:138
BOOL WINAPI AppendMenuW(_In_ HMENU, _In_ UINT, _In_ UINT_PTR, _In_opt_ LPCWSTR)
#define ICON_SMALL
Definition: tnclass.cpp:48
#define IDC_START
Definition: resource.h:137
#define IDS_GROUPBOX_OPTIONS_TITLE
Definition: resource.h:28
#define SM_CXSCREEN
Definition: winuser.h:949
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
HINSTANCE hInstance
Definition: charmap.c:20
INT ListBoxRefreshContents(VOID)
Definition: dialog.c:206
#define ICC_WIN95_CLASSES
Definition: commctrl.h:66
#define LB_RESETCONTENT
Definition: winuser.h:2037
#define LB_ERR
Definition: winuser.h:2407
unsigned int BOOL
Definition: ntddk_ex.h:94
HANDLE WINAPI LoadImageW(_In_opt_ HINSTANCE, _In_ LPCWSTR, _In_ UINT, _In_ int, _In_ int, _In_ UINT)
Definition: cursoricon.c:2172
#define IDC_LISTBOX
Definition: resource.h:16
VOID UpdateUtilityState(IN BOOL bUtilState)
Definition: dialog.c:188
#define IDC_STOP
Definition: resource.h:69
HMENU WINAPI GetSystemMenu(_In_ HWND, _In_ BOOL)
smooth NULL
Definition: ftsmooth.c:416
HWND WINAPI GetDesktopWindow(void)
Definition: window.c:652
#define MF_SEPARATOR
Definition: winuser.h:137
LONG_PTR LPARAM
Definition: windef.h:208
HANDLE hMutex
Definition: mutex.c:11
HICON hIcon
Definition: precomp.h:33
#define IDC_CANCEL
Definition: resource.h:60
UINT_PTR WINAPI SetTimer(_In_opt_ HWND, _In_ UINT_PTR, _In_ UINT, _In_opt_ TIMERPROC)
#define DialogBoxW(i, t, p, f)
Definition: winuser.h:4300
#define SM_CYSCREEN
Definition: winuser.h:950
HWND hDlgCtlStart
Definition: precomp.h:36
#define LR_DEFAULTSIZE
Definition: winuser.h:1084
__wchar_t WCHAR
Definition: xmlstorage.h:180
#define IDD_MAIN_DIALOG
Definition: resource.h:6
#define WM_TIMER
Definition: winuser.h:1724
#define MAX_BUFFER
Definition: precomp.h:26
#define WM_CLOSE
Definition: winuser.h:1603
#define WINAPI
Definition: msvc.h:8
WCHAR szGrpBoxTitle[MAX_BUFFER]
Definition: precomp.h:42
int WINAPI GetSystemMetrics(_In_ int)
unsigned long DWORD
Definition: ntddk_ex.h:95
UTILMAN_STATE EntriesList[]
Definition: dialog.c:19
#define LB_SETITEMDATA
Definition: winuser.h:2047
#define IDS_OSK
Definition: resource.h:19
#define IDS_RUNNING
Definition: resource.h:258
BOOL WINAPI KillTimer(_In_opt_ HWND, _In_ UINT_PTR)
INT WINAPI wWinMain(IN HINSTANCE hInstance, IN HINSTANCE hPrevInstance, IN LPWSTR pCmdLine, IN INT nCmdShow)
Definition: dialog.c:374
BOOL bState
Definition: precomp.h:50
static const WCHAR L[]
Definition: oid.c:1250
BOOL WINAPI InitCommonControlsEx(const INITCOMMONCONTROLSEX *lpInitCtrls)
Definition: commctrl.c:893
HWND hDlgCtlStop
Definition: precomp.h:37
#define WM_COMMAND
Definition: winuser.h:1722
INT_PTR APIENTRY DlgProc(IN HWND hDlg, IN UINT Msg, IN WPARAM wParam, IN LPARAM lParam)
Definition: dialog.c:272
#define IDS_NOTRUNNING
Definition: resource.h:23
#define SWP_NOSIZE
Definition: winuser.h:1230
UTILMAN_GLOBALS Globals
Definition: dialog.c:15
BOOL LaunchProcess(LPCWSTR lpProcessName)
Definition: process.c:73
BOOL WINAPI EndDialog(HWND hwnd, INT_PTR retval)
Definition: dialog.c:2085
LRESULT WINAPI SendMessageW(_In_ HWND, _In_ UINT, _In_ WPARAM, _In_ LPARAM)
STRSAFEAPI StringCchPrintfW(STRSAFE_LPWSTR pszDest, size_t cchDest, STRSAFE_LPCWSTR pszFormat,...)
Definition: strsafe.h:530
HWND hMainDlg
Definition: precomp.h:39
HANDLE WINAPI DECLSPEC_HOTPATCH CreateMutexW(IN LPSECURITY_ATTRIBUTES lpMutexAttributes OPTIONAL, IN BOOL bInitialOwner, IN LPCWSTR lpName OPTIONAL)
Definition: synch.c:576
#define LB_GETCURSEL
Definition: winuser.h:2021
unsigned int UINT
Definition: ndis.h:50
HWND hListDlg
Definition: precomp.h:38
VOID GroupBoxUpdateTitle(VOID)
Definition: dialog.c:167
BOOL CloseProcess(IN LPCWSTR lpProcessName)
Definition: process.c:148
HWND WINAPI GetDlgItem(HWND hDlg, int nIDDlgItem)
Definition: dialog.c:2183
#define HIWORD(l)
Definition: typedefs.h:246
LONG bottom
Definition: windef.h:294
#define ICC_STANDARD_CLASSES
Definition: commctrl.h:73
BOOL WINAPI GetWindowRect(_In_ HWND, _Out_ LPRECT)
BOOL DlgInitHandler(IN HWND hDlg)
Definition: dialog.c:97
BOOL WINAPI SetWindowPos(_In_ HWND, _In_opt_ HWND, _In_ int, _In_ int, _In_ int, _In_ int, _In_ UINT)
#define MAKEINTRESOURCEW(i)
Definition: winuser.h:582
#define ERROR_ALREADY_EXISTS
Definition: disk.h:80
WCHAR * LPWSTR
Definition: xmlstorage.h:184
LPCWSTR lpProgram
Definition: precomp.h:47
VOID InitUtilsList(BOOL bInitGui)
Definition: dialog.c:38
#define LB_DELETESTRING
Definition: winuser.h:2014
INT iSelectedIndex
Definition: precomp.h:35
static const CLSID *static CLSID *static const GUID VARIANT VARIANT *static IServiceProvider DWORD *static HMENU
Definition: ordinal.c:60
#define WM_SYSCOMMAND
Definition: winuser.h:1723
#define IDC_OK
Definition: resource.h:59
#define WM_INITDIALOG
Definition: winuser.h:1721
#define LB_INSERTSTRING
Definition: winuser.h:2035
LPARAM lParam
Definition: combotst.c:139
#define LOWORD(l)
Definition: pedump.c:82
#define APIENTRY
Definition: api.h:79
UINT_PTR iTimer
Definition: precomp.h:34
WCHAR szNotRunning[MAX_BUFFER]
Definition: precomp.h:41
WCHAR szRunning[MAX_BUFFER]
Definition: precomp.h:40