ReactOS  0.4.15-dev-1068-g467feb9
misc.c File Reference
#include "precomp.h"
Include dependency graph for misc.c:

Go to the source code of this file.

Functions

static INT LengthOfStrResource (IN HINSTANCE hInst, IN UINT uID)
 
INT AllocAndLoadString (OUT LPTSTR *lpTarget, IN HINSTANCE hInst, IN UINT uID)
 
DWORD LoadAndFormatString (IN HINSTANCE hInstance, IN UINT uID, OUT LPTSTR *lpTarget,...)
 
BOOL StatusBarLoadAndFormatString (IN HWND hStatusBar, IN INT PartId, IN HINSTANCE hInstance, IN UINT uID,...)
 
BOOL StatusBarLoadString (IN HWND hStatusBar, IN INT PartId, IN HINSTANCE hInstance, IN UINT uID)
 
INT GetTextFromEdit (OUT LPTSTR lpString, IN HWND hDlg, IN UINT Res)
 
VOID GetError (DWORD err)
 

Function Documentation

◆ AllocAndLoadString()

INT AllocAndLoadString ( OUT LPTSTR lpTarget,
IN HINSTANCE  hInst,
IN UINT  uID 
)

Definition at line 40 of file misc.c.

43 {
44  INT ln;
45 
47  uID);
48  if (ln++ > 0)
49  {
50  (*lpTarget) = (LPTSTR)LocalAlloc(LMEM_FIXED,
51  ln * sizeof(TCHAR));
52  if ((*lpTarget) != NULL)
53  {
54  INT Ret;
55  if (!(Ret = LoadString(hInst, uID, *lpTarget, ln)))
56  {
57  LocalFree((HLOCAL)(*lpTarget));
58  }
59  return Ret;
60  }
61  }
62  return 0;
63 }
int32_t INT
Definition: typedefs.h:58
CHAR * LPTSTR
Definition: xmlstorage.h:192
smooth NULL
Definition: ftsmooth.c:416
#define LMEM_FIXED
Definition: winbase.h:349
char TCHAR
Definition: xmlstorage.h:189
HINSTANCE hInst
Definition: dxdiag.c:13
HLOCAL NTAPI LocalFree(HLOCAL hMem)
Definition: heapmem.c:1577
HLOCAL NTAPI LocalAlloc(UINT uFlags, SIZE_T dwBytes)
Definition: heapmem.c:1373
INT LengthOfStrResource(IN HINSTANCE hInst, IN UINT uID)
Definition: misc.c:23
#define LoadString
Definition: winuser.h:5794

◆ GetError()

VOID GetError ( DWORD  err)

Definition at line 183 of file misc.c.

184 {
185  LPVOID lpMsgBuf;
186 
187  if (err == 0)
188  err = GetLastError();
189 
193  NULL,
194  err,
196  (LPTSTR) &lpMsgBuf,
197  0,
198  NULL );
199 
200  MessageBox(NULL, (LPCTSTR) lpMsgBuf, _T("Error!"), MB_OK | MB_ICONERROR);
201 
202  LocalFree(lpMsgBuf);
203 }
const CHAR * LPCTSTR
Definition: xmlstorage.h:193
#define LANG_NEUTRAL
Definition: nls.h:22
#define SUBLANG_DEFAULT
Definition: nls.h:168
DWORD WINAPI GetLastError(VOID)
Definition: except.c:1044
CHAR * LPTSTR
Definition: xmlstorage.h:192
#define FORMAT_MESSAGE_ALLOCATE_BUFFER
Definition: winbase.h:400
smooth NULL
Definition: ftsmooth.c:416
#define FORMAT_MESSAGE_FROM_SYSTEM
Definition: winbase.h:404
#define _T(x)
Definition: vfdio.h:22
#define FormatMessage
Definition: winbase.h:3635
#define MB_ICONERROR
Definition: winuser.h:781
#define MessageBox
Definition: winuser.h:5797
#define err(...)
#define FORMAT_MESSAGE_IGNORE_INSERTS
Definition: winbase.h:401
HLOCAL NTAPI LocalFree(HLOCAL hMem)
Definition: heapmem.c:1577
#define MB_OK
Definition: winuser.h:784
#define MAKELANGID(p, s)
Definition: nls.h:15

◆ GetTextFromEdit()

INT GetTextFromEdit ( OUT LPTSTR  lpString,
IN HWND  hDlg,
IN UINT  Res 
)

Definition at line 164 of file misc.c.

167 {
168  INT len = GetWindowTextLength(GetDlgItem(hDlg, Res));
169  if(len > 0)
170  {
171  GetDlgItemText(hDlg,
172  Res,
173  lpString,
174  len + 1);
175  }
176  else
177  lpString = NULL;
178 
179  return len;
180 }
int32_t INT
Definition: typedefs.h:58
smooth NULL
Definition: ftsmooth.c:416
#define GetDlgItemText
Definition: winuser.h:5760
HWND WINAPI GetDlgItem(_In_opt_ HWND, _In_ int)
GLenum GLsizei len
Definition: glext.h:6722
#define GetWindowTextLength
Definition: winuser.h:5774

◆ LengthOfStrResource()

static INT LengthOfStrResource ( IN HINSTANCE  hInst,
IN UINT  uID 
)
static

Definition at line 4 of file misc.c.

6 {
7  HRSRC hrSrc;
8  HGLOBAL hRes;
9  LPWSTR lpName, lpStr;
10 
11  if (hInst == NULL)
12  {
13  return -1;
14  }
15 
16  /* There are always blocks of 16 strings */
17  lpName = (LPWSTR)MAKEINTRESOURCE((uID >> 4) + 1);
18 
19  /* Find the string table block */
20  if ((hrSrc = FindResourceW(hInst, lpName, (LPWSTR)RT_STRING)) &&
21  (hRes = LoadResource(hInst, hrSrc)) &&
22  (lpStr = (WCHAR*) LockResource(hRes)))
23  {
24  UINT x;
25 
26  /* Find the string we're looking for */
27  uID &= 0xF; /* position in the block, same as % 16 */
28  for (x = 0; x < uID; x++)
29  {
30  lpStr += (*lpStr) + 1;
31  }
32 
33  /* Found the string */
34  return (int)(*lpStr);
35  }
36  return -1;
37 }
#define MAKEINTRESOURCE
Definition: winuser.h:591
_In_ LPCSTR lpName
Definition: winbase.h:2752
LPVOID WINAPI LockResource(HGLOBAL handle)
Definition: res.c:550
GLint GLint GLint GLint GLint x
Definition: gl.h:1548
HRSRC WINAPI FindResourceW(HINSTANCE hModule, LPCWSTR name, LPCWSTR type)
Definition: res.c:176
HGLOBAL WINAPI LoadResource(HINSTANCE hModule, HRSRC hRsrc)
Definition: res.c:532
smooth NULL
Definition: ftsmooth.c:416
__wchar_t WCHAR
Definition: xmlstorage.h:180
#define RT_STRING
Definition: pedump.c:368
HINSTANCE hInst
Definition: dxdiag.c:13
unsigned int UINT
Definition: ndis.h:50
static LPWSTR
Definition: misc.c:35
WCHAR * LPWSTR
Definition: xmlstorage.h:184

◆ LoadAndFormatString()

DWORD LoadAndFormatString ( IN HINSTANCE  hInstance,
IN UINT  uID,
OUT LPTSTR lpTarget,
  ... 
)

Definition at line 66 of file misc.c.

70 {
71  DWORD Ret = 0;
73  va_list lArgs;
74 
76  hInstance,
77  uID) > 0)
78  {
79  va_start(lArgs, lpTarget);
80  /* let's use FormatMessage to format it because it has the ability to allocate
81  memory automatically */
83  lpFormat,
84  0,
85  0,
86  (LPTSTR)lpTarget,
87  0,
88  &lArgs);
89  va_end(lArgs);
90 
92  }
93 
94  return Ret;
95 }
#define FORMAT_MESSAGE_FROM_STRING
Definition: winbase.h:402
CHAR * LPTSTR
Definition: xmlstorage.h:192
HINSTANCE hInstance
Definition: charmap.c:20
#define va_end(ap)
Definition: acmsvcex.h:90
#define FORMAT_MESSAGE_ALLOCATE_BUFFER
Definition: winbase.h:400
char * va_list
Definition: acmsvcex.h:78
unsigned long DWORD
Definition: ntddk_ex.h:95
#define FormatMessage
Definition: winbase.h:3635
LPCWSTR lpFormat
Definition: trayclock.cpp:32
HLOCAL NTAPI LocalFree(HLOCAL hMem)
Definition: heapmem.c:1577
INT AllocAndLoadString(OUT LPWSTR *lpTarget, IN HINSTANCE hInst, IN UINT uID)
Definition: misc.c:50
#define va_start(ap, A)
Definition: acmsvcex.h:91

◆ StatusBarLoadAndFormatString()

BOOL StatusBarLoadAndFormatString ( IN HWND  hStatusBar,
IN INT  PartId,
IN HINSTANCE  hInstance,
IN UINT  uID,
  ... 
)

Definition at line 98 of file misc.c.

103 {
104  BOOL Ret = FALSE;
105  LPTSTR lpFormat, lpStr;
106  va_list lArgs;
107 
109  hInstance,
110  uID) > 0)
111  {
112  va_start(lArgs, uID);
113  /* let's use FormatMessage to format it because it has the ability to allocate
114  memory automatically */
116  lpFormat,
117  0,
118  0,
119  (LPTSTR)&lpStr,
120  0,
121  &lArgs);
122  va_end(lArgs);
123 
124  if (lpStr != NULL)
125  {
126  Ret = (BOOL)SendMessage(hStatusBar,
127  SB_SETTEXT,
128  (WPARAM)PartId,
129  (LPARAM)lpStr);
130  LocalFree((HLOCAL)lpStr);
131  }
132 
134  }
135 
136  return Ret;
137 }
static BOOL
Definition: misc.c:84
#define FORMAT_MESSAGE_FROM_STRING
Definition: winbase.h:402
UINT_PTR WPARAM
Definition: windef.h:207
CHAR * LPTSTR
Definition: xmlstorage.h:192
HINSTANCE hInstance
Definition: charmap.c:20
#define va_end(ap)
Definition: acmsvcex.h:90
#define FALSE
Definition: types.h:117
unsigned int BOOL
Definition: ntddk_ex.h:94
#define FORMAT_MESSAGE_ALLOCATE_BUFFER
Definition: winbase.h:400
smooth NULL
Definition: ftsmooth.c:416
LONG_PTR LPARAM
Definition: windef.h:208
char * va_list
Definition: acmsvcex.h:78
HWND hStatusBar
Definition: main.cpp:35
#define FormatMessage
Definition: winbase.h:3635
#define SB_SETTEXT
Definition: commctrl.h:1945
LPCWSTR lpFormat
Definition: trayclock.cpp:32
HLOCAL NTAPI LocalFree(HLOCAL hMem)
Definition: heapmem.c:1577
INT AllocAndLoadString(OUT LPWSTR *lpTarget, IN HINSTANCE hInst, IN UINT uID)
Definition: misc.c:50
#define va_start(ap, A)
Definition: acmsvcex.h:91
#define SendMessage
Definition: winuser.h:5818

◆ StatusBarLoadString()

BOOL StatusBarLoadString ( IN HWND  hStatusBar,
IN INT  PartId,
IN HINSTANCE  hInstance,
IN UINT  uID 
)

Definition at line 140 of file misc.c.

144 {
145  BOOL Ret = FALSE;
146  LPTSTR lpStr;
147 
148  if (AllocAndLoadString(&lpStr,
149  hInstance,
150  uID) > 0)
151  {
152  Ret = (BOOL)SendMessage(hStatusBar,
153  SB_SETTEXT,
154  (WPARAM)PartId,
155  (LPARAM)lpStr);
156  LocalFree((HLOCAL)lpStr);
157  }
158 
159  return Ret;
160 }
static BOOL
Definition: misc.c:84
UINT_PTR WPARAM
Definition: windef.h:207
CHAR * LPTSTR
Definition: xmlstorage.h:192
HINSTANCE hInstance
Definition: charmap.c:20
#define FALSE
Definition: types.h:117
unsigned int BOOL
Definition: ntddk_ex.h:94
LONG_PTR LPARAM
Definition: windef.h:208
HWND hStatusBar
Definition: main.cpp:35
#define SB_SETTEXT
Definition: commctrl.h:1945
HLOCAL NTAPI LocalFree(HLOCAL hMem)
Definition: heapmem.c:1577
INT AllocAndLoadString(OUT LPWSTR *lpTarget, IN HINSTANCE hInst, IN UINT uID)
Definition: misc.c:50
#define SendMessage
Definition: winuser.h:5818