ReactOS 0.4.15-dev-8109-gd7be748
misc.c
Go to the documentation of this file.
1#include "precomp.h"
2
3static 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
39INT
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
67 IN UINT uID,
68 OUT LPTSTR *lpTarget,
69 ...)
70{
71 DWORD Ret = 0;
73 va_list lArgs;
74
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 */
84 0,
85 0,
86 (LPTSTR)lpTarget,
87 0,
88 &lArgs);
89 va_end(lArgs);
90
92 }
93
94 return Ret;
95}
96
97BOOL
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 {
128 (WPARAM)PartId,
129 (LPARAM)lpStr);
130 LocalFree((HLOCAL)lpStr);
131 }
132
134 }
135
136 return Ret;
137}
138
139BOOL
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 {
154 (WPARAM)PartId,
155 (LPARAM)lpStr);
156 LocalFree((HLOCAL)lpStr);
157 }
158
159 return Ret;
160}
161
162
163INT
165 IN HWND hDlg,
166 IN UINT Res)
167{
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
char * va_list
Definition: acmsvcex.h:78
#define va_end(ap)
Definition: acmsvcex.h:90
#define va_start(ap, A)
Definition: acmsvcex.h:91
INT LengthOfStrResource(IN HINSTANCE hInst, IN UINT uID)
Definition: misc.c:23
INT AllocAndLoadString(OUT LPTSTR *lpTarget, IN HINSTANCE hInst, IN UINT uID)
Definition: misc.c:59
DWORD LoadAndFormatString(IN HINSTANCE hInstance, IN UINT uID, OUT LPTSTR *lpTarget,...)
Definition: misc.c:85
INT GetTextFromEdit(OUT LPWSTR lpString, IN HWND hDlg, IN UINT Res)
Definition: misc.c:174
VOID GetError(VOID)
Definition: misc.c:192
BOOL StatusBarLoadString(IN HWND hStatusBar, IN INT PartId, IN HINSTANCE hInstance, IN UINT uID)
Definition: misc.c:150
BOOL StatusBarLoadAndFormatString(IN HWND hStatusBar, IN INT PartId, IN HINSTANCE hInstance, IN UINT uID,...)
Definition: misc.c:108
HWND hStatusBar
Definition: main.c:36
HINSTANCE hInstance
Definition: charmap.c:19
#define NULL
Definition: types.h:112
#define FALSE
Definition: types.h:117
HRSRC WINAPI FindResourceW(HINSTANCE hModule, LPCWSTR name, LPCWSTR type)
Definition: res.c:176
LPVOID WINAPI LockResource(HGLOBAL handle)
Definition: res.c:550
HGLOBAL WINAPI LoadResource(HINSTANCE hModule, HRSRC hRsrc)
Definition: res.c:532
HINSTANCE hInst
Definition: dxdiag.c:13
unsigned int BOOL
Definition: ntddk_ex.h:94
unsigned long DWORD
Definition: ntddk_ex.h:95
GLint GLint GLint GLint GLint x
Definition: gl.h:1548
GLenum GLsizei len
Definition: glext.h:6722
HLOCAL NTAPI LocalAlloc(UINT uFlags, SIZE_T dwBytes)
Definition: heapmem.c:1390
HLOCAL NTAPI LocalFree(HLOCAL hMem)
Definition: heapmem.c:1594
unsigned int UINT
Definition: ndis.h:50
#define BOOL
Definition: nt_native.h:43
#define RT_STRING
Definition: pedump.c:368
#define SB_SETTEXT
Definition: commctrl.h:1949
#define err(...)
#define LANG_NEUTRAL
Definition: nls.h:22
#define MAKELANGID(p, s)
Definition: nls.h:15
#define SUBLANG_DEFAULT
Definition: nls.h:168
LPCWSTR lpFormat
Definition: trayclock.cpp:32
int32_t INT
Definition: typedefs.h:58
#define IN
Definition: typedefs.h:39
#define OUT
Definition: typedefs.h:40
#define _T(x)
Definition: vfdio.h:22
#define FormatMessage
Definition: winbase.h:3795
DWORD WINAPI GetLastError(void)
Definition: except.c:1042
#define FORMAT_MESSAGE_FROM_STRING
Definition: winbase.h:421
_In_ LPCSTR lpName
Definition: winbase.h:2789
#define FORMAT_MESSAGE_IGNORE_INSERTS
Definition: winbase.h:420
#define FORMAT_MESSAGE_FROM_SYSTEM
Definition: winbase.h:423
#define FORMAT_MESSAGE_ALLOCATE_BUFFER
Definition: winbase.h:419
#define LMEM_FIXED
Definition: winbase.h:368
LONG_PTR LPARAM
Definition: windef.h:208
UINT_PTR WPARAM
Definition: windef.h:207
#define GetWindowTextLength
Definition: winuser.h:5799
#define GetDlgItemText
Definition: winuser.h:5785
HWND WINAPI GetDlgItem(_In_opt_ HWND, _In_ int)
#define MB_ICONERROR
Definition: winuser.h:787
#define SendMessage
Definition: winuser.h:5843
#define MB_OK
Definition: winuser.h:790
#define LoadString
Definition: winuser.h:5819
#define MessageBox
Definition: winuser.h:5822
#define MAKEINTRESOURCE
Definition: winuser.h:591
char TCHAR
Definition: xmlstorage.h:189
__wchar_t WCHAR
Definition: xmlstorage.h:180
WCHAR * LPWSTR
Definition: xmlstorage.h:184
const CHAR * LPCTSTR
Definition: xmlstorage.h:193
CHAR * LPTSTR
Definition: xmlstorage.h:192