ReactOS  0.4.12-dev-57-g7050ac4
utils.h File Reference
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Macros

#define LoadResourceString(hInst, uID)   LoadResourceStringEx((hInst), (uID), NULL)
 
#define LoadConditionalResourceString(hInst, bCond, uIDifT, uIDifF)   LoadConditionalResourceStringEx((hInst), (bCond), (uIDifT), (uIDifF), NULL)
 
#define MONITOR_CENTER   0x0001
 
#define MONITOR_CLIP   0x0000
 
#define MONITOR_WORKAREA   0x0002
 
#define MONITOR_AREA   0x0000
 

Functions

BOOL MemFree (IN PVOID lpMem)
 
PVOID MemAlloc (IN DWORD dwFlags, IN DWORD dwBytes)
 
LPWSTR FormatDateTime (IN LPSYSTEMTIME pDateTime)
 
VOID FreeDateTime (IN LPWSTR lpszDateTime)
 
LPWSTR LoadResourceStringEx (IN HINSTANCE hInstance, IN UINT uID, OUT size_t *pSize OPTIONAL)
 
LPWSTR LoadConditionalResourceStringEx (IN HINSTANCE hInstance, IN BOOL bCondition, IN UINT uIDifTrue, IN UINT uIDifFalse, IN size_t *pSize OPTIONAL)
 
DWORD RunCommand (IN LPCWSTR lpszCommand, IN LPCWSTR lpszParameters, IN INT nShowCmd)
 
VOID ClipOrCenterRectToMonitor (LPRECT prc, UINT flags)
 
VOID ClipOrCenterWindowToMonitor (HWND hWnd, UINT flags)
 
BOOL IsWindowsOS (VOID)
 
BOOL IsPreVistaOSVersion (VOID)
 
LPWSTR GetExecutableVendor (IN LPCWSTR lpszFilename)
 

Macro Definition Documentation

◆ LoadConditionalResourceString

#define LoadConditionalResourceString (   hInst,
  bCond,
  uIDifT,
  uIDifF 
)    LoadConditionalResourceStringEx((hInst), (bCond), (uIDifT), (uIDifF), NULL)

Definition at line 51 of file utils.h.

◆ LoadResourceString

#define LoadResourceString (   hInst,
  uID 
)    LoadResourceStringEx((hInst), (uID), NULL)

Definition at line 48 of file utils.h.

◆ MONITOR_AREA

#define MONITOR_AREA   0x0000

Definition at line 70 of file utils.h.

◆ MONITOR_CENTER

#define MONITOR_CENTER   0x0001

Definition at line 67 of file utils.h.

Referenced by ClipOrCenterRectToMonitor(), and CreatePropSheet().

◆ MONITOR_CLIP

#define MONITOR_CLIP   0x0000

Definition at line 68 of file utils.h.

◆ MONITOR_WORKAREA

#define MONITOR_WORKAREA   0x0002

Definition at line 69 of file utils.h.

Referenced by ClipOrCenterRectToMonitor(), and CreatePropSheet().

Function Documentation

◆ ClipOrCenterRectToMonitor()

VOID ClipOrCenterRectToMonitor ( LPRECT  prc,
UINT  flags 
)

Definition at line 173 of file utils.c.

Referenced by ClipOrCenterWindowToMonitor().

174 {
175  HMONITOR hMonitor;
176  MONITORINFO mi;
177  RECT rc;
178  int w = prc->right - prc->left;
179  int h = prc->bottom - prc->top;
180 
181  //
182  // Get the nearest monitor to the passed rect.
183  //
184  hMonitor = MonitorFromRect(prc, MONITOR_DEFAULTTONEAREST);
185 
186  //
187  // Get the work area or entire monitor rect.
188  //
189  mi.cbSize = sizeof(mi);
190  GetMonitorInfo(hMonitor, &mi);
191 
192  if (flags & MONITOR_WORKAREA)
193  rc = mi.rcWork;
194  else
195  rc = mi.rcMonitor;
196 
197  //
198  // Center or clip the passed rect to the monitor rect.
199  //
200  if (flags & MONITOR_CENTER)
201  {
202  prc->left = rc.left + (rc.right - rc.left - w) / 2;
203  prc->top = rc.top + (rc.bottom - rc.top - h) / 2;
204  prc->right = prc->left + w;
205  prc->bottom = prc->top + h;
206  }
207  else
208  {
209  prc->left = max(rc.left, min(rc.right-w, prc->left));
210  prc->top = max(rc.top, min(rc.bottom-h, prc->top));
211  prc->right = prc->left + w;
212  prc->bottom = prc->top + h;
213  }
214 }
#define max(a, b)
Definition: svc.c:63
GLubyte GLubyte GLubyte GLubyte w
Definition: glext.h:6102
LONG top
Definition: windef.h:297
static MONITORINFO mi
Definition: win.c:7331
LONG left
Definition: windef.h:296
LONG right
Definition: windef.h:298
RECT rcMonitor
Definition: winuser.h:3727
GLfloat GLfloat GLfloat GLfloat h
Definition: glext.h:7723
#define GetMonitorInfo
Definition: winuser.h:5657
#define MONITOR_CENTER
Definition: utils.h:67
#define MONITOR_WORKAREA
Definition: utils.h:69
GLbitfield flags
Definition: glext.h:7161
DWORD cbSize
Definition: winuser.h:3726
#define min(a, b)
Definition: monoChain.cc:55
HMONITOR WINAPI MonitorFromRect(LPCRECT, DWORD)
LONG bottom
Definition: windef.h:299

◆ ClipOrCenterWindowToMonitor()

VOID ClipOrCenterWindowToMonitor ( HWND  hWnd,
UINT  flags 
)

Definition at line 216 of file utils.c.

Referenced by CreatePropSheet().

217 {
218  RECT rc;
219  GetWindowRect(hWnd, &rc);
221  SetWindowPos(hWnd, NULL, rc.left, rc.top, 0, 0, SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE);
222 }
VOID ClipOrCenterRectToMonitor(LPRECT prc, UINT flags)
Definition: utils.c:173
LONG top
Definition: windef.h:297
LONG left
Definition: windef.h:296
#define SWP_NOZORDER
Definition: winuser.h:1232
smooth NULL
Definition: ftsmooth.c:416
#define SWP_NOACTIVATE
Definition: winuser.h:1227
GLbitfield flags
Definition: glext.h:7161
#define SWP_NOSIZE
Definition: winuser.h:1230
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)

◆ FormatDateTime()

LPWSTR FormatDateTime ( IN LPSYSTEMTIME  pDateTime)

Definition at line 41 of file utils.c.

Referenced by AddService().

42 {
43  LPWSTR lpszDateTime = NULL;
44  int iDateBufSize, iTimeBufSize;
45 
46  if (pDateTime == NULL) return NULL;
47 
48  iDateBufSize = GetDateFormatW(LOCALE_USER_DEFAULT,
49  /* Only for Windows 7 : DATE_AUTOLAYOUT | */ DATE_SHORTDATE,
50  pDateTime,
51  NULL,
52  NULL,
53  0);
54  iTimeBufSize = GetTimeFormatW(LOCALE_USER_DEFAULT,
55  0,
56  pDateTime,
57  NULL,
58  NULL,
59  0);
60 
61  if ( (iDateBufSize > 0) && (iTimeBufSize > 0) )
62  {
63  lpszDateTime = (LPWSTR)MemAlloc(0, (iDateBufSize + iTimeBufSize) * sizeof(WCHAR));
64 
66  /* Only for Windows 7 : DATE_AUTOLAYOUT | */ DATE_SHORTDATE,
67  pDateTime,
68  NULL,
69  lpszDateTime,
70  iDateBufSize);
71  if (iDateBufSize > 0) lpszDateTime[iDateBufSize-1] = L' ';
73  0,
74  pDateTime,
75  NULL,
76  lpszDateTime + iDateBufSize,
77  iTimeBufSize);
78  }
79 
80  return lpszDateTime;
81 }
PVOID MemAlloc(IN DWORD dwFlags, IN DWORD dwBytes)
Definition: utils.c:33
#define LOCALE_USER_DEFAULT
#define DATE_SHORTDATE
Definition: winnls.h:193
#define WCHAR
Definition: msvc.h:43
smooth NULL
Definition: ftsmooth.c:416
static const WCHAR L[]
Definition: oid.c:1087
INT WINAPI GetDateFormatW(LCID lcid, DWORD dwFlags, const SYSTEMTIME *lpTime, LPCWSTR lpFormat, LPWSTR lpDateStr, INT cchOut)
Definition: lcformat.c:916
WCHAR * LPWSTR
Definition: xmlstorage.h:184
INT WINAPI GetTimeFormatW(LCID lcid, DWORD dwFlags, const SYSTEMTIME *lpTime, LPCWSTR lpFormat, LPWSTR lpTimeStr, INT cchOut)
Definition: lcformat.c:1016

◆ FreeDateTime()

VOID FreeDateTime ( IN LPWSTR  lpszDateTime)

Definition at line 84 of file utils.c.

Referenced by AddService().

85 {
86  if (lpszDateTime)
87  MemFree(lpszDateTime);
88 }
BOOL MemFree(IN PVOID lpMem)
Definition: utils.c:26

◆ GetExecutableVendor()

LPWSTR GetExecutableVendor ( IN LPCWSTR  lpszFilename)

Definition at line 288 of file utils.c.

Referenced by AddService().

289 {
290  LPWSTR lpszVendor = NULL;
291  DWORD dwHandle = 0;
292  DWORD dwLen;
293 
294  LPVOID lpData;
295 
296  LPVOID pvData = NULL;
297  UINT BufLen = 0;
298  WORD wCodePage = 0, wLangID = 0;
299  LPWSTR lpszStrFileInfo = NULL;
300 
301  LPWSTR lpszData = NULL;
302 
303  if (lpszFilename == NULL) return NULL;
304 
305  dwLen = GetFileVersionInfoSizeW(lpszFilename, &dwHandle);
306  if (dwLen == 0) return NULL;
307 
308  lpData = MemAlloc(0, dwLen);
309  if (!lpData) return NULL;
310 
311  GetFileVersionInfoW(lpszFilename, dwHandle, dwLen, lpData);
312 
313  if (VerQueryValueW(lpData, L"\\VarFileInfo\\Translation", &pvData, &BufLen))
314  {
315  wCodePage = LOWORD(*(DWORD*)pvData);
316  wLangID = HIWORD(*(DWORD*)pvData);
317 
318  lpszStrFileInfo = FormatString(L"StringFileInfo\\%04X%04X\\CompanyName",
319  wCodePage,
320  wLangID);
321  }
322 
323  VerQueryValueW(lpData, lpszStrFileInfo, (LPVOID*)&lpszData, &BufLen);
324  if (lpszData)
325  {
326  lpszVendor = (LPWSTR)MemAlloc(0, BufLen * sizeof(WCHAR));
327  if (lpszVendor)
328  wcscpy(lpszVendor, lpszData);
329  }
330  else
331  {
332  lpszVendor = NULL;
333  }
334 
335  MemFree(lpszStrFileInfo);
336  MemFree(lpData);
337 
338  return lpszVendor;
339 }
BOOL MemFree(IN PVOID lpMem)
Definition: utils.c:26
#define BufLen
Definition: fatfs.h:167
__wchar_t WCHAR
Definition: xmlstorage.h:180
PVOID MemAlloc(IN DWORD dwFlags, IN DWORD dwBytes)
Definition: utils.c:33
DWORD FormatString(DWORD dwFlags, HINSTANCE hInstance, DWORD dwStringId, DWORD dwLanguageId, LPWSTR lpBuffer, DWORD nSize, va_list *Arguments)
Definition: fontview.c:48
_In_ ULONG _In_opt_ PVOID pvData
Definition: winddi.h:3748
smooth NULL
Definition: ftsmooth.c:416
unsigned int UINT
Definition: ndis.h:50
unsigned short WORD
Definition: ntddk_ex.h:93
unsigned long DWORD
Definition: ntddk_ex.h:95
_CRTIMP wchar_t *__cdecl wcscpy(_Out_writes_z_(_String_length_(_Source)+1) wchar_t *_Dest, _In_z_ const wchar_t *_Source)
static const WCHAR L[]
Definition: oid.c:1087
DWORD WINAPI GetFileVersionInfoSizeW(LPCWSTR filename, LPDWORD handle)
Definition: version.c:616
BOOL WINAPI GetFileVersionInfoW(LPCWSTR filename, DWORD handle, DWORD datasize, LPVOID data)
Definition: version.c:850
#define HIWORD(l)
Definition: typedefs.h:246
WCHAR * LPWSTR
Definition: xmlstorage.h:184
#define LOWORD(l)
Definition: pedump.c:82
BOOL WINAPI VerQueryValueW(LPCVOID pBlock, LPCWSTR lpSubBlock, LPVOID *lplpBuffer, PUINT puLen)
Definition: version.c:1054

◆ IsPreVistaOSVersion()

BOOL IsPreVistaOSVersion ( VOID  )

Definition at line 275 of file utils.c.

Referenced by Initialize().

276 {
277  OSVERSIONINFOW osvi = {0};
278  osvi.dwOSVersionInfoSize = sizeof(osvi);
279 
280  if (!GetVersionExW(&osvi))
281  return FALSE;
282 
283  /* Vista+-class OSes are NT >= 6 */
284  return ( (osvi.dwPlatformId == VER_PLATFORM_WIN32_NT) ? (osvi.dwMajorVersion < 6) : FALSE );
285 }
#define VER_PLATFORM_WIN32_NT
Definition: rtltypes.h:236
OSVERSIONINFO osvi
Definition: ver.c:28
BOOL WINAPI GetVersionExW(IN LPOSVERSIONINFOW lpVersionInformation)
Definition: version.c:37
ULONG dwMajorVersion
Definition: rtltypes.h:243
ULONG dwOSVersionInfoSize
Definition: rtltypes.h:242
ULONG dwPlatformId
Definition: rtltypes.h:246

◆ IsWindowsOS()

BOOL IsWindowsOS ( VOID  )

Definition at line 226 of file utils.c.

Referenced by Initialize().

227 {
228  BOOL bIsWindowsOS = FALSE;
229 
230  OSVERSIONINFOW osvi = {0};
231  osvi.dwOSVersionInfoSize = sizeof(osvi);
232 
233  if (!GetVersionExW(&osvi))
234  return FALSE;
235 
237  return FALSE;
238 
239  /* ReactOS reports as Windows NT 5.2 */
240 
241  if ( (osvi.dwMajorVersion == 5 && osvi.dwMinorVersion >= 2) ||
242  (osvi.dwMajorVersion > 5) )
243  {
244  HKEY hKey = NULL;
245 
247  L"SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion",
248  0, KEY_QUERY_VALUE, &hKey) == ERROR_SUCCESS)
249  {
250  LONG ret;
251  DWORD dwType = 0, dwBufSize = 0;
252 
253  ret = RegQueryValueExW(hKey, L"ProductName", NULL, &dwType, NULL, &dwBufSize);
254  if (ret == ERROR_SUCCESS && dwType == REG_SZ)
255  {
256  LPTSTR lpszProductName = (LPTSTR)MemAlloc(0, dwBufSize);
257  RegQueryValueExW(hKey, L"ProductName", NULL, &dwType, (LPBYTE)lpszProductName, &dwBufSize);
258 
259  bIsWindowsOS = (FindSubStrI(lpszProductName, _T("Windows")) != NULL);
260 
261  MemFree(lpszProductName);
262  }
263 
264  RegCloseKey(hKey);
265  }
266  }
267  else
268  {
269  bIsWindowsOS = TRUE;
270  }
271 
272  return bIsWindowsOS;
273 }
#define VER_PLATFORM_WIN32_NT
Definition: rtltypes.h:236
#define TRUE
Definition: types.h:120
BOOL MemFree(IN PVOID lpMem)
Definition: utils.c:26
#define ERROR_SUCCESS
Definition: deptool.c:10
OSVERSIONINFO osvi
Definition: ver.c:28
PVOID MemAlloc(IN DWORD dwFlags, IN DWORD dwBytes)
Definition: utils.c:33
BOOL WINAPI GetVersionExW(IN LPOSVERSIONINFOW lpVersionInformation)
Definition: version.c:37
CHAR * LPTSTR
Definition: xmlstorage.h:192
LONG WINAPI RegCloseKey(HKEY hKey)
Definition: reg.c:423
unsigned char * LPBYTE
Definition: typedefs.h:52
long LONG
Definition: pedump.c:60
smooth NULL
Definition: ftsmooth.c:416
#define _T(x)
Definition: vfdio.h:22
unsigned int BOOL
Definition: ntddk_ex.h:94
ULONG dwMajorVersion
Definition: rtltypes.h:243
LONG WINAPI RegQueryValueExW(_In_ HKEY hkeyorg, _In_ LPCWSTR name, _In_ LPDWORD reserved, _In_ LPDWORD type, _In_ LPBYTE data, _In_ LPDWORD count)
Definition: reg.c:4134
ULONG dwOSVersionInfoSize
Definition: rtltypes.h:242
unsigned long DWORD
Definition: ntddk_ex.h:95
int ret
static const WCHAR L[]
Definition: oid.c:1087
ULONG dwPlatformId
Definition: rtltypes.h:246
LPTSTR FindSubStrI(LPCTSTR str, LPCTSTR strSearch)
Definition: stringutils.c:183
#define KEY_QUERY_VALUE
Definition: nt_native.h:1016
ULONG dwMinorVersion
Definition: rtltypes.h:244
LONG WINAPI RegOpenKeyExW(HKEY hKey, LPCWSTR lpSubKey, DWORD ulOptions, REGSAM samDesired, PHKEY phkResult)
Definition: reg.c:3381
#define HKEY_LOCAL_MACHINE
Definition: winreg.h:12
#define REG_SZ
Definition: layer.c:22

◆ LoadConditionalResourceStringEx()

LPWSTR LoadConditionalResourceStringEx ( IN HINSTANCE  hInstance,
IN BOOL  bCondition,
IN UINT  uIDifTrue,
IN UINT  uIDifFalse,
IN size_t *pSize  OPTIONAL 
)

Definition at line 120 of file utils.c.

125 {
127  (bCondition ? uIDifTrue : uIDifFalse),
128  pSize);
129 }
LPWSTR LoadResourceStringEx(IN HINSTANCE hInstance, IN UINT uID, OUT size_t *pSize OPTIONAL)
Definition: utils.c:91
HINSTANCE hInstance
Definition: charmap.c:20

◆ LoadResourceStringEx()

LPWSTR LoadResourceStringEx ( IN HINSTANCE  hInstance,
IN UINT  uID,
OUT size_t *pSize  OPTIONAL 
)

Definition at line 91 of file utils.c.

Referenced by LoadConditionalResourceStringEx().

94 {
95  LPWSTR lpszDestBuf = NULL, lpszResourceString = NULL;
96  size_t iStrSize = 0;
97 
98  // When passing a zero-length buffer size, LoadString(...) returns a
99  // read-only pointer buffer to the program's resource string.
100  iStrSize = LoadStringW(hInstance, uID, (LPWSTR)&lpszResourceString, 0);
101 
102  if ( lpszResourceString && ( (lpszDestBuf = (LPWSTR)MemAlloc(0, (iStrSize + 1) * sizeof(WCHAR))) != NULL ) )
103  {
104  wcsncpy(lpszDestBuf, lpszResourceString, iStrSize);
105  lpszDestBuf[iStrSize] = L'\0'; // NULL-terminate the string
106 
107  if (pSize)
108  *pSize = iStrSize + 1;
109  }
110  else
111  {
112  if (pSize)
113  *pSize = 0;
114  }
115 
116  return lpszDestBuf;
117 }
__wchar_t WCHAR
Definition: xmlstorage.h:180
PVOID MemAlloc(IN DWORD dwFlags, IN DWORD dwBytes)
Definition: utils.c:33
int WINAPI LoadStringW(_In_opt_ HINSTANCE hInstance, _In_ UINT uID, _Out_writes_to_(cchBufferMax, return+1) LPWSTR lpBuffer, _In_ int cchBufferMax)
HINSTANCE hInstance
Definition: charmap.c:20
smooth NULL
Definition: ftsmooth.c:416
static const WCHAR L[]
Definition: oid.c:1087
_CRTIMP wchar_t *__cdecl wcsncpy(wchar_t *_Dest, const wchar_t *_Source, size_t _Count)
WCHAR * LPWSTR
Definition: xmlstorage.h:184

◆ MemAlloc()

◆ MemFree()

◆ RunCommand()

DWORD RunCommand ( IN LPCWSTR  lpszCommand,
IN LPCWSTR  lpszParameters,
IN INT  nShowCmd 
)

Definition at line 132 of file utils.c.

Referenced by GeneralPageWndProc(), and TOOL::Run().

135 {
136  DWORD dwRes;
137 
138  DWORD dwNumOfChars;
139  LPWSTR lpszExpandedCommand;
140 
141  dwNumOfChars = ExpandEnvironmentStringsW(lpszCommand, NULL, 0);
142  lpszExpandedCommand = (LPWSTR)MemAlloc(0, dwNumOfChars * sizeof(WCHAR));
143  ExpandEnvironmentStringsW(lpszCommand, lpszExpandedCommand, dwNumOfChars);
144 
145  dwRes = (DWORD_PTR)ShellExecuteW(NULL,
146  NULL /* and not L"open" !! */,
147  lpszExpandedCommand,
148  lpszParameters,
149  NULL,
150  nShowCmd);
151  MemFree(lpszExpandedCommand);
152 
153  return dwRes;
154 }
BOOL MemFree(IN PVOID lpMem)
Definition: utils.c:26
#define DWORD_PTR
Definition: treelist.c:76
__wchar_t WCHAR
Definition: xmlstorage.h:180
PVOID MemAlloc(IN DWORD dwFlags, IN DWORD dwBytes)
Definition: utils.c:33
smooth NULL
Definition: ftsmooth.c:416
unsigned long DWORD
Definition: ntddk_ex.h:95
DWORD WINAPI ExpandEnvironmentStringsW(IN LPCWSTR lpSrc, IN LPWSTR lpDst, IN DWORD nSize)
Definition: environ.c:519
HINSTANCE WINAPI ShellExecuteW(HWND hwnd, LPCWSTR lpVerb, LPCWSTR lpFile, LPCWSTR lpParameters, LPCWSTR lpDirectory, INT nShowCmd)
Definition: shlexec.cpp:2236
WCHAR * LPWSTR
Definition: xmlstorage.h:184