ReactOS  0.4.15-dev-1197-g8081ba9
umandlg.c
Go to the documentation of this file.
1 /*
2  * PROJECT: ReactOS Utility Manager Resources DLL (UManDlg.dll)
3  * LICENSE: GPL-2.0+ (https://spdx.org/licenses/GPL-2.0+)
4  * PURPOSE: Main DLL code file
5  * COPYRIGHT: Copyright 2019-2020 BiČ™oc George (fraizeraust99 at gmail dot com)
6  * Copyright 2019 Hermes Belusca-Maito
7  */
8 
9 /* INCLUDES *******************************************************************/
10 
11 #include "umandlg.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].lpszProgram);
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  WCHAR szAppPath[MAX_BUFFER];
103  HMENU hSysMenu;
104 
105  /* Save the dialog handle */
106  Globals.hMainDlg = hDlg;
107 
108  /* Center the dialog on the screen */
109  GetWindowRect(hDlg, &rc);
110  PosX = (GetSystemMetrics(SM_CXSCREEN) - rc.right) / 2;
111  PosY = (GetSystemMetrics(SM_CYSCREEN) - rc.bottom) / 2;
112  SetWindowPos(hDlg, 0, PosX, PosY, 0, 0, SWP_NOZORDER | SWP_NOSIZE);
113 
114  /* Extract the icon resource from the executable process */
115  GetModuleFileNameW(NULL, szAppPath, _countof(szAppPath));
116  Globals.hIcon = ExtractIconW(Globals.hInstance, szAppPath, 0);
117 
118  /* Set the icon within the dialog's title bar */
119  if (Globals.hIcon)
120  {
121  SendMessageW(hDlg, WM_SETICON, ICON_SMALL, (LPARAM)Globals.hIcon);
122  }
123 
124  /* Retrieve the system menu and append the "About" menu item onto it */
125  hSysMenu = GetSystemMenu(hDlg, FALSE);
126  if (hSysMenu != NULL)
127  {
128  if (LoadStringW(Globals.hInstance, IDM_ABOUT, szAboutDlg, _countof(szAboutDlg)))
129  {
130  AppendMenuW(hSysMenu, MF_SEPARATOR, 0, NULL);
131  AppendMenuW(hSysMenu, MF_STRING, IDM_ABOUT, szAboutDlg);
132  }
133  }
134 
135  /* Get the dialog items, specifically the dialog list box, the Start and Stop buttons */
139 
140  /* Initialize the GUI listbox */
142 
143  /* Set the selection to the first item */
145 
146  /* Refresh the list */
148 
149  /* Create a timer, we'll use it to control the state of our items in the listbox */
150  Globals.iTimer = SetTimer(hDlg, 0, 400, NULL);
151 
152  return TRUE;
153 }
154 
168 {
169  WCHAR szApp[MAX_BUFFER];
170  WCHAR szAuthors[MAX_BUFFER];
171 
173  LoadStringW(Globals.hInstance, IDS_AUTHORS, szAuthors, _countof(szAuthors));
174 
175  ShellAboutW(hDlgParent, szApp, szAuthors, Globals.hIcon);
176 }
177 
188 {
189  WCHAR szFormat[MAX_BUFFER];
190 
191  /* Format the string with the utility's name and set it to the listbox's title */
194 }
195 
209 {
210  Button_Enable(Globals.hDlgCtlStart, !bUtilState);
211  Button_Enable(Globals.hDlgCtlStop, bUtilState);
212 
213  /* Update the groupbox's title based on the selected utility item */
215 }
216 
227 {
228  UINT i;
229  INT iItem;
230  BOOL bIsRunning;
231  WCHAR szFormat[MAX_BUFFER];
232 
233  /* Disable listbox redraw */
235 
236  for (i = 0; i < _countof(EntriesList); ++i)
237  {
238  /* Check the utility's state */
239  bIsRunning = IsProcessRunning(EntriesList[i].lpszProgram);
240  if (bIsRunning != EntriesList[i].bState)
241  {
242  /* The utility's state has changed, save it */
243  EntriesList[i].bState = bIsRunning;
244 
245  /* Update the corresponding item in the listbox */
246  StringCchPrintfW(szFormat, _countof(szFormat),
247  (bIsRunning ? Globals.szRunning : Globals.szNotRunning),
249 
251  iItem = SendMessageW(Globals.hListDlg, LB_INSERTSTRING, (LPARAM)i, (LPARAM)szFormat);
252  if (iItem != LB_ERR)
254  }
255  }
256 
257  /* Re-enable listbox redraw */
259 
260  /*
261  * Check the previously selected item. This will help us determine what
262  * item has been selected and set its focus selection back. Furthermore, check
263  * the state of each accessibility tool and enable/disable the buttons.
264  */
267 
268  return 0;
269 }
270 
293  IN HWND hDlg,
294  IN UINT Msg,
295  IN WPARAM wParam,
296  IN LPARAM lParam)
297 {
298  switch (Msg)
299  {
300  case WM_INITDIALOG:
301  DlgInitHandler(hDlg);
302  return TRUE;
303 
304  case WM_CLOSE:
305  KillTimer(hDlg, Globals.iTimer);
307  EndDialog(hDlg, FALSE);
308  break;
309 
310  case WM_COMMAND:
311  {
312  switch (LOWORD(wParam))
313  {
314  case IDC_OK:
315  case IDC_CANCEL:
316  EndDialog(hDlg, FALSE);
317  break;
318 
319  case IDC_LISTBOX:
320  {
321  switch (HIWORD(wParam))
322  {
323  case LBN_SELCHANGE:
324  {
325  /* Retrieve the index of the current selected item */
326  INT iIndex = SendMessageW(Globals.hListDlg, LB_GETCURSEL, 0, 0);
327  if ((iIndex == LB_ERR) || (iIndex >= _countof(EntriesList)))
328  break;
329 
330  /* Assign the selected index and check the utility's state */
331  Globals.iSelectedIndex = iIndex;
333  break;
334  }
335  break;
336  }
337  break;
338  }
339 
340  case IDC_START:
342  break;
343 
344  case IDC_STOP:
346  break;
347 
348  default:
349  break;
350  }
351  break;
352  }
353 
354  case WM_TIMER:
356  return 0;
357 
358  case WM_SYSCOMMAND:
359  {
360  switch (LOWORD(wParam))
361  {
362  case IDM_ABOUT:
363  ShowAboutDlg(hDlg);
364  break;
365  }
366  break;
367  }
368  }
369 
370  return 0;
371 }
372 
384 {
385  HANDLE hMutex;
386  DWORD dwError;
387  INITCOMMONCONTROLSEX iccex;
388 
389  /* Create a mutant object for the program. */
390  hMutex = CreateMutexW(NULL, FALSE, L"Utilman");
391  if (hMutex)
392  {
393  /* Check if there's already a mutex for the program */
394  dwError = GetLastError();
395  if (dwError == ERROR_ALREADY_EXISTS)
396  {
397  /*
398  The program's instance is already here. That means
399  the program is running and we should not set a new instance
400  and mutex object.
401  */
403  return FALSE;
404  }
405  }
406 
407  /* Load the common controls for the program */
408  iccex.dwSize = sizeof(INITCOMMONCONTROLSEX);
410  InitCommonControlsEx(&iccex);
411 
418 
419  /* Initialize the list of accessibility utilities */
421 
422  /* Create the dialog box of the program */
426  DlgProc);
427 
428  /* Delete the mutex */
429  if (hMutex)
430  {
432  }
433 
434  return TRUE;
435 }
436 
458  IN DWORD fdwReason,
460 {
461  switch (fdwReason)
462  {
463  case DLL_PROCESS_ATTACH:
464  {
465  /* We don't care for DLL_THREAD_ATTACH and DLL_THREAD_DETACH notifications */
467 
468  /* Initialize the globals */
469  ZeroMemory(&Globals, sizeof(Globals));
471  break;
472  }
473 
474  case DLL_PROCESS_DETACH:
475  break;
476  }
477 
478  return TRUE;
479 }
#define LB_SETCURSEL
Definition: winuser.h:2045
DWORD WINAPI GetModuleFileNameW(HINSTANCE hModule, LPWSTR lpFilename, DWORD nSize)
Definition: loader.c:600
VOID InitUtilsList(IN BOOL bInitGui)
Definition: umandlg.c:38
#define IN
Definition: typedefs.h:39
#define CloseHandle
Definition: compat.h:487
UINT uNameId
Definition: umandlg.h:48
#define IDM_ABOUT
Definition: resource.h:29
#define LB_ADDSTRING
Definition: winuser.h:2013
BOOL WINAPI DestroyIcon(_In_ HICON)
Definition: cursoricon.c:2022
#define TRUE
Definition: types.h:120
BOOL CloseProcess(IN LPCWSTR lpszProcessName)
Definition: process.c:192
#define INT
Definition: polytest.cpp:20
#define WM_SETREDRAW
Definition: winuser.h:1598
#define MF_STRING
Definition: winuser.h:138
BOOL WINAPI DisableThreadLibraryCalls(IN HMODULE hLibModule)
Definition: loader.c:85
HINSTANCE hInstance
Definition: umandlg.h:32
DWORD WINAPI GetLastError(VOID)
Definition: except.c:1044
#define ZeroMemory
Definition: winbase.h:1648
#define Button_Enable(hwndCtl, fEnable)
Definition: windowsx.h:5
WCHAR szResource[MAX_BUFFER]
Definition: umandlg.h:49
#define IDC_LISTBOX
Definition: resource.h:13
#define DLL_PROCESS_ATTACH
Definition: compat.h:131
struct @1610 Msg[]
BOOL WINAPI SetWindowTextW(_In_ HWND, _In_opt_ LPCWSTR)
#define IDS_GROUPBOX_OPTIONS_TITLE
Definition: resource.h:25
UINT_PTR WPARAM
Definition: windef.h:207
#define SWP_NOZORDER
Definition: winuser.h:1232
int32_t INT_PTR
Definition: typedefs.h:64
LONG right
Definition: windef.h:308
#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:58
BOOL WINAPI EndDialog(_In_ HWND, _In_ INT_PTR)
WPARAM wParam
Definition: combotst.c:138
static IN DWORD IN LPVOID lpvReserved
HICON WINAPI ExtractIconW(HINSTANCE hInstance, LPCWSTR lpszFile, UINT nIconIndex)
Definition: shell32_main.c:881
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:135
#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
#define ICC_WIN95_CLASSES
Definition: commctrl.h:66
#define LB_RESETCONTENT
Definition: winuser.h:2037
INT_PTR APIENTRY DlgProc(IN HWND hDlg, IN UINT Msg, IN WPARAM wParam, IN LPARAM lParam)
Definition: umandlg.c:292
BOOL WINAPI UManStartDlg(VOID)
Definition: umandlg.c:383
#define FALSE
Definition: types.h:117
#define LB_ERR
Definition: winuser.h:2407
unsigned int BOOL
Definition: ntddk_ex.h:94
BOOL LaunchProcess(IN LPCWSTR lpszProcessName)
Definition: process.c:117
#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:656
#define MF_SEPARATOR
Definition: winuser.h:137
LONG_PTR LPARAM
Definition: windef.h:208
HANDLE hMutex
Definition: mutex.c:11
HICON hIcon
Definition: umandlg.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:4374
#define DLL_PROCESS_DETACH
Definition: compat.h:130
BOOL WINAPI DllMain(IN HINSTANCE hDllInstance, IN DWORD fdwReason, IN LPVOID lpvReserved)
Definition: umandlg.c:457
static HINSTANCE hDllInstance
Definition: clb.c:30
#define SM_CYSCREEN
Definition: winuser.h:950
#define IDS_OSK
Definition: resource.h:16
VOID GroupBoxUpdateTitle(VOID)
Definition: umandlg.c:187
HWND hDlgCtlStart
Definition: umandlg.h:36
HWND WINAPI GetDlgItem(_In_opt_ HWND, _In_ int)
__wchar_t WCHAR
Definition: xmlstorage.h:180
#define IDD_MAIN_DIALOG
Definition: resource.h:6
#define _countof(array)
Definition: sndvol32.h:68
#define WM_TIMER
Definition: winuser.h:1724
#define MAX_BUFFER
Definition: precomp.h:20
#define WM_CLOSE
Definition: winuser.h:1603
#define IDS_MAGNIFIER
Definition: resource.h:17
#define WINAPI
Definition: msvc.h:6
WCHAR szGrpBoxTitle[MAX_BUFFER]
Definition: umandlg.h:42
int WINAPI GetSystemMetrics(_In_ int)
unsigned long DWORD
Definition: ntddk_ex.h:95
#define LB_SETITEMDATA
Definition: winuser.h:2047
#define IDS_RUNNING
Definition: resource.h:257
BOOL WINAPI KillTimer(_In_opt_ HWND, _In_ UINT_PTR)
BOOL bState
Definition: umandlg.h:50
UTILMAN_GLOBALS Globals
Definition: umandlg.c:15
static const WCHAR L[]
Definition: oid.c:1250
BOOL WINAPI InitCommonControlsEx(const INITCOMMONCONTROLSEX *lpInitCtrls)
Definition: commctrl.c:893
LPCWSTR lpszProgram
Definition: umandlg.h:47
HWND hDlgCtlStop
Definition: umandlg.h:37
BOOL WINAPI ShellAboutW(HWND hWnd, LPCWSTR szApp, LPCWSTR szOtherStuff, HICON hIcon)
UTILMAN_STATE EntriesList[]
Definition: umandlg.c:19
#define WM_COMMAND
Definition: winuser.h:1722
VOID UpdateUtilityState(IN BOOL bUtilState)
Definition: umandlg.c:208
#define IDS_NOTRUNNING
Definition: resource.h:20
#define SWP_NOSIZE
Definition: winuser.h:1230
VOID ShowAboutDlg(IN HWND hDlgParent)
Definition: umandlg.c:167
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: umandlg.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
#define IDS_APP_NAME
Definition: resource.h:137
HWND hListDlg
Definition: umandlg.h:38
#define IDC_GROUPBOX
Definition: resource.h:24
BOOL DlgInitHandler(IN HWND hDlg)
Definition: umandlg.c:97
BOOL IsProcessRunning(IN LPCWSTR lpszProcessName)
Definition: process.c:71
#define HIWORD(l)
Definition: typedefs.h:247
LONG bottom
Definition: windef.h:309
#define ICC_STANDARD_CLASSES
Definition: commctrl.h:73
BOOL WINAPI GetWindowRect(_In_ HWND, _Out_ LPRECT)
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
#define LB_DELETESTRING
Definition: winuser.h:2014
INT iSelectedIndex
Definition: umandlg.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
INT ListBoxRefreshContents(VOID)
Definition: umandlg.c:226
#define APIENTRY
Definition: api.h:79
UINT_PTR iTimer
Definition: umandlg.h:34
#define IDS_AUTHORS
Definition: resource.h:44
WCHAR szNotRunning[MAX_BUFFER]
Definition: umandlg.h:41
WCHAR szRunning[MAX_BUFFER]
Definition: umandlg.h:40