ReactOS 0.4.15-dev-8434-g155a7c7
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}
INT LengthOfStrResource(IN HINSTANCE hInst, IN UINT uID)
Definition: misc.c:23
#define NULL
Definition: types.h:112
HINSTANCE hInst
Definition: dxdiag.c:13
HLOCAL NTAPI LocalAlloc(UINT uFlags, SIZE_T dwBytes)
Definition: heapmem.c:1390
HLOCAL NTAPI LocalFree(HLOCAL hMem)
Definition: heapmem.c:1594
int32_t INT
Definition: typedefs.h:58
#define LMEM_FIXED
Definition: winbase.h:368
#define LoadString
Definition: winuser.h:5828
char TCHAR
Definition: xmlstorage.h:189
CHAR * LPTSTR
Definition: xmlstorage.h:192

◆ 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}
#define err(...)
#define LANG_NEUTRAL
Definition: nls.h:22
#define MAKELANGID(p, s)
Definition: nls.h:15
#define SUBLANG_DEFAULT
Definition: nls.h:168
#define _T(x)
Definition: vfdio.h:22
#define FormatMessage
Definition: winbase.h:3795
DWORD WINAPI GetLastError(void)
Definition: except.c:1042
#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 MB_ICONERROR
Definition: winuser.h:787
#define MB_OK
Definition: winuser.h:790
#define MessageBox
Definition: winuser.h:5831
const CHAR * LPCTSTR
Definition: xmlstorage.h:193

◆ GetTextFromEdit()

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

Definition at line 164 of file misc.c.

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}
GLenum GLsizei len
Definition: glext.h:6722
#define GetWindowTextLength
Definition: winuser.h:5808
#define GetDlgItemText
Definition: winuser.h:5794
HWND WINAPI GetDlgItem(_In_opt_ HWND, _In_ int)

◆ 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}
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
GLint GLint GLint GLint GLint x
Definition: gl.h:1548
unsigned int UINT
Definition: ndis.h:50
#define RT_STRING
Definition: pedump.c:368
_In_ LPCSTR lpName
Definition: winbase.h:2789
#define MAKEINTRESOURCE
Definition: winuser.h:591
__wchar_t WCHAR
Definition: xmlstorage.h:180
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
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}
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 AllocAndLoadString(OUT LPTSTR *lpTarget, IN HINSTANCE hInst, IN UINT uID)
Definition: misc.c:59
HINSTANCE hInstance
Definition: charmap.c:19
unsigned long DWORD
Definition: ntddk_ex.h:95
LPCWSTR lpFormat
Definition: trayclock.cpp:32
#define FORMAT_MESSAGE_FROM_STRING
Definition: winbase.h:421

◆ 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 {
128 (WPARAM)PartId,
129 (LPARAM)lpStr);
130 LocalFree((HLOCAL)lpStr);
131 }
132
134 }
135
136 return Ret;
137}
HWND hStatusBar
Definition: main.c:36
#define FALSE
Definition: types.h:117
unsigned int BOOL
Definition: ntddk_ex.h:94
#define BOOL
Definition: nt_native.h:43
#define SB_SETTEXT
Definition: commctrl.h:1949
LONG_PTR LPARAM
Definition: windef.h:208
UINT_PTR WPARAM
Definition: windef.h:207
#define SendMessage
Definition: winuser.h:5852

◆ 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 {
154 (WPARAM)PartId,
155 (LPARAM)lpStr);
156 LocalFree((HLOCAL)lpStr);
157 }
158
159 return Ret;
160}