ReactOS  0.4.15-dev-1632-g4e289ce
misc.c
Go to the documentation of this file.
1 #include "precomp.h"
2 
3 static INT
5  IN UINT uID)
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 }
38 
39 INT
42  IN UINT uID)
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 }
64 
65 DWORD
67  IN UINT uID,
68  OUT LPTSTR *lpTarget,
69  ...)
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 }
96 
97 BOOL
99  IN INT PartId,
101  IN UINT uID,
102  ...)
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 }
138 
139 BOOL
141  IN INT PartId,
143  IN UINT uID)
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 }
161 
162 
163 INT
165  IN HWND hDlg,
166  IN UINT Res)
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 }
181 
182 
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 }
204 
#define MAKEINTRESOURCE
Definition: winuser.h:591
#define IN
Definition: typedefs.h:39
const CHAR * LPCTSTR
Definition: xmlstorage.h:193
INT GetTextFromEdit(OUT LPWSTR lpString, IN HWND hDlg, IN UINT Res)
Definition: misc.c:174
static BOOL
Definition: misc.c:84
#define LANG_NEUTRAL
Definition: nls.h:22
#define FORMAT_MESSAGE_FROM_STRING
Definition: winbase.h:402
#define SUBLANG_DEFAULT
Definition: nls.h:168
_In_ LPCSTR lpName
Definition: winbase.h:2752
DWORD WINAPI GetLastError(VOID)
Definition: except.c:1044
LPVOID WINAPI LockResource(HGLOBAL handle)
Definition: res.c:550
GLint GLint GLint GLint GLint x
Definition: gl.h:1548
UINT_PTR WPARAM
Definition: windef.h:207
int32_t INT
Definition: typedefs.h:58
HRSRC WINAPI FindResourceW(HINSTANCE hModule, LPCWSTR name, LPCWSTR type)
Definition: res.c:176
CHAR * LPTSTR
Definition: xmlstorage.h:192
VOID GetError(VOID)
Definition: misc.c: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
HGLOBAL WINAPI LoadResource(HINSTANCE hModule, HRSRC hRsrc)
Definition: res.c:532
LONG_PTR LPARAM
Definition: windef.h:208
char * va_list
Definition: acmsvcex.h:78
DWORD LoadAndFormatString(IN HINSTANCE hInstance, IN UINT uID, OUT LPTSTR *lpTarget,...)
Definition: misc.c:86
#define FORMAT_MESSAGE_FROM_SYSTEM
Definition: winbase.h:404
#define LMEM_FIXED
Definition: winbase.h:349
char TCHAR
Definition: xmlstorage.h:189
#define _T(x)
Definition: vfdio.h:22
#define GetDlgItemText
Definition: winuser.h:5760
HWND WINAPI GetDlgItem(_In_opt_ HWND, _In_ int)
__wchar_t WCHAR
Definition: xmlstorage.h:180
unsigned long DWORD
Definition: ntddk_ex.h:95
HWND hStatusBar
Definition: main.cpp:35
va_start(ap, x)
#define FormatMessage
Definition: winbase.h:3635
#define SB_SETTEXT
Definition: commctrl.h:1945
#define MB_ICONERROR
Definition: winuser.h:781
GLenum GLsizei len
Definition: glext.h:6722
#define RT_STRING
Definition: pedump.c:368
#define MessageBox
Definition: winuser.h:5797
LPCWSTR lpFormat
Definition: trayclock.cpp:32
#define err(...)
#define FORMAT_MESSAGE_IGNORE_INSERTS
Definition: winbase.h:401
HINSTANCE hInst
Definition: dxdiag.c:13
HLOCAL NTAPI LocalFree(HLOCAL hMem)
Definition: heapmem.c:1577
INT AllocAndLoadString(OUT LPWSTR *lpTarget, IN HINSTANCE hInst, IN UINT uID)
Definition: misc.c:50
unsigned int UINT
Definition: ndis.h:50
#define NULL
Definition: types.h:112
#define MB_OK
Definition: winuser.h:784
#define SendMessage
Definition: winuser.h:5818
#define OUT
Definition: typedefs.h:40
static LPWSTR
Definition: misc.c:35
#define GetWindowTextLength
Definition: winuser.h:5774
#define MAKELANGID(p, s)
Definition: nls.h:15
BOOL StatusBarLoadAndFormatString(IN HWND hStatusBar, IN INT PartId, IN HINSTANCE hInstance, IN UINT uID,...)
Definition: misc.c:108
HLOCAL NTAPI LocalAlloc(UINT uFlags, SIZE_T dwBytes)
Definition: heapmem.c:1373
WCHAR * LPWSTR
Definition: xmlstorage.h:184
INT LengthOfStrResource(IN HINSTANCE hInst, IN UINT uID)
Definition: misc.c:23
#define LoadString
Definition: winuser.h:5794
BOOL StatusBarLoadString(IN HWND hStatusBar, IN INT PartId, IN HINSTANCE hInstance, IN UINT uID)
Definition: misc.c:150