ReactOS 0.4.15-dev-8096-ga0eec98
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 LPWSTR *lpTarget, IN HINSTANCE hInst, IN UINT uID)
 
DWORD LoadAndFormatString (IN HINSTANCE hInstance, IN UINT uID, OUT LPWSTR *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 LPWSTR lpString, IN HWND hDlg, IN UINT Res)
 
VOID DisplayError (INT err)
 
VOID DisplayMessage (LPWSTR lpMsg)
 
HIMAGELIST InitImageList (UINT StartResource, UINT EndResource, UINT Width, UINT Height)
 
DWORD AnsiToUnicode (LPCSTR lpSrcStr, LPWSTR *lpDstStr)
 
DWORD UnicodeToAnsi (LPCWSTR lpSrcStr, LPSTR *lpDstStr)
 

Function Documentation

◆ AllocAndLoadString()

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

Definition at line 50 of file misc.c.

53{
54 INT ln;
55
57 uID);
58 if (ln++ > 0)
59 {
60 (*lpTarget) = (LPTSTR)LocalAlloc(LMEM_FIXED,
61 ln * sizeof(TCHAR));
62 if ((*lpTarget) != NULL)
63 {
64 INT Ret;
65 if (!(Ret = LoadStringW(hInst, uID, *lpTarget, ln)))
66 {
67 LocalFree((HLOCAL)(*lpTarget));
68 }
69 return Ret;
70 }
71 }
72 return 0;
73}
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
int WINAPI LoadStringW(_In_opt_ HINSTANCE hInstance, _In_ UINT uID, _Out_writes_to_(cchBufferMax, return+1) LPWSTR lpBuffer, _In_ int cchBufferMax)
char TCHAR
Definition: xmlstorage.h:189
CHAR * LPTSTR
Definition: xmlstorage.h:192

◆ AnsiToUnicode()

DWORD AnsiToUnicode ( LPCSTR  lpSrcStr,
LPWSTR lpDstStr 
)

Definition at line 267 of file misc.c.

269{
270 INT length;
271 INT ret = 0;
272
273 length = strlen(lpSrcStr) + 1;
274
275 *lpDstStr = (LPWSTR)HeapAlloc(GetProcessHeap(), 0, length * sizeof(WCHAR));
276 if (*lpDstStr)
277 {
279 0,
280 lpSrcStr,
281 -1,
282 *lpDstStr,
283 length);
284 }
285
286 return ret;
287}
ACPI_SIZE strlen(const char *String)
Definition: utclib.c:269
#define GetProcessHeap()
Definition: compat.h:736
#define CP_ACP
Definition: compat.h:109
#define HeapAlloc
Definition: compat.h:733
#define MultiByteToWideChar
Definition: compat.h:110
GLuint GLsizei GLsizei * length
Definition: glext.h:6040
int ret
__wchar_t WCHAR
Definition: xmlstorage.h:180
WCHAR * LPWSTR
Definition: xmlstorage.h:184

◆ DisplayError()

VOID DisplayError ( INT  err)

Definition at line 192 of file misc.c.

193{
194 LPWSTR lpMsgBuf = NULL;
195
199 NULL,
200 err,
202 (VOID*)&lpMsgBuf,
203 0,
204 NULL );
205
206 MessageBoxW(NULL, lpMsgBuf, L"Error!", MB_OK | MB_ICONERROR);
207
208 LocalFree(lpMsgBuf);
209}
DWORD WINAPI FormatMessageW(DWORD dwFlags, LPCVOID lpSource, DWORD dwMessageId, DWORD dwLanguageId, LPWSTR lpBuffer, DWORD nSize, __ms_va_list *args)
Definition: format_msg.c:583
#define L(x)
Definition: ntvdm.h:50
#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 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
int WINAPI MessageBoxW(_In_opt_ HWND hWnd, _In_opt_ LPCWSTR lpText, _In_opt_ LPCWSTR lpCaption, _In_ UINT uType)
#define MB_ICONERROR
Definition: winuser.h:787
#define MB_OK
Definition: winuser.h:790

◆ DisplayMessage()

VOID DisplayMessage ( LPWSTR  lpMsg)

Definition at line 211 of file misc.c.

212{
213 MessageBoxW(NULL, lpMsg, L"Note!", MB_ICONEXCLAMATION|MB_OK);
214}
#define MB_ICONEXCLAMATION
Definition: winuser.h:785

◆ GetTextFromEdit()

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

Definition at line 174 of file misc.c.

177{
179 if(len > 0)
180 {
181 GetDlgItemTextW(hDlg,
182 Res,
183 lpString,
184 len + 1);
185 }
186 else
187 lpString = NULL;
188
189 return len;
190}
GLenum GLsizei len
Definition: glext.h:6722
UINT WINAPI GetDlgItemTextW(HWND hDlg, int nIDDlgItem, LPWSTR lpString, int nMaxCount)
Definition: dialog.c:2263
HWND WINAPI GetDlgItem(_In_opt_ HWND, _In_ int)
int WINAPI GetWindowTextLengthW(_In_ HWND)

◆ InitImageList()

HIMAGELIST InitImageList ( UINT  StartResource,
UINT  EndResource,
UINT  Width,
UINT  Height 
)

Definition at line 219 of file misc.c.

223{
224 HICON hIcon;
225 HIMAGELIST hImageList;
226 UINT i;
227 INT Ret;
228
229 /* Create the toolbar icon image list */
230 hImageList = ImageList_Create(Width,
231 Height,
233 EndResource - StartResource,
234 0);
235 if (hImageList == NULL)
236 return NULL;
237
238 /* Add all icons to the image list */
239 for (i = StartResource; i <= EndResource; i++)
240 {
244 Width,
245 Height,
247 if (hIcon == NULL)
248 goto fail;
249
250 Ret = ImageList_AddIcon(hImageList,
251 hIcon);
252
254
255 if (Ret == -1)
256 goto fail;
257 }
258
259 return hImageList;
260
261fail:
262 ImageList_Destroy(hImageList);
263 return NULL;
264}
HINSTANCE hInstance
Definition: charmap.c:19
BOOL WINAPI ImageList_Destroy(HIMAGELIST himl)
Definition: imagelist.c:928
HIMAGELIST WINAPI ImageList_Create(INT cx, INT cy, UINT flags, INT cInitial, INT cGrow)
Definition: imagelist.c:804
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
static HICON
Definition: imagelist.c:84
HICON hIcon
Definition: msconfig.c:44
unsigned int UINT
Definition: ndis.h:50
#define ILC_COLOR32
Definition: commctrl.h:358
#define ImageList_AddIcon(himl, hicon)
Definition: commctrl.h:415
#define ILC_MASK
Definition: commctrl.h:351
_In_ HFONT _Out_ PUINT _Out_ PUINT Width
Definition: font.h:89
_In_ HFONT _Out_ PUINT Height
Definition: font.h:88
#define IMAGE_ICON
Definition: winuser.h:212
HANDLE WINAPI LoadImageW(_In_opt_ HINSTANCE hInst, _In_ LPCWSTR name, _In_ UINT type, _In_ int cx, _In_ int cy, _In_ UINT fuLoad)
Definition: cursoricon.c:2234
#define LR_DEFAULTCOLOR
Definition: winuser.h:1087
#define MAKEINTRESOURCEW(i)
Definition: winuser.h:582
BOOL WINAPI DestroyIcon(_In_ HICON)
Definition: cursoricon.c:2084

◆ LengthOfStrResource()

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

Definition at line 14 of file misc.c.

16{
17 HRSRC hrSrc;
18 HGLOBAL hRes;
19 LPWSTR lpName, lpStr;
20
21 if (hInst == NULL)
22 {
23 return -1;
24 }
25
26 /* There are always blocks of 16 strings */
27 lpName = (LPWSTR)MAKEINTRESOURCEW((uID >> 4) + 1);
28
29 /* Find the string table block */
30 if ((hrSrc = FindResourceW(hInst, lpName, (LPWSTR)RT_STRING)) &&
31 (hRes = LoadResource(hInst, hrSrc)) &&
32 (lpStr = (WCHAR*) LockResource(hRes)))
33 {
34 UINT x;
35
36 /* Find the string we're looking for */
37 uID &= 0xF; /* position in the block, same as % 16 */
38 for (x = 0; x < uID; x++)
39 {
40 lpStr += (*lpStr) + 1;
41 }
42
43 /* Found the string */
44 return (int)(*lpStr);
45 }
46 return -1;
47}
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
#define RT_STRING
Definition: pedump.c:368
_In_ LPCSTR lpName
Definition: winbase.h:2789

◆ LoadAndFormatString()

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

Definition at line 76 of file misc.c.

80{
81 DWORD Ret = 0;
83 va_list lArgs;
84
87 uID) > 0)
88 {
89 va_start(lArgs, lpTarget);
90 /* let's use Format to format it because it has the ability to allocate
91 memory automatically */
94 0,
95 0,
96 (LPTSTR)lpTarget,
97 0,
98 &lArgs);
99 va_end(lArgs);
100
102 }
103
104 return Ret;
105}
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
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 108 of file misc.c.

113{
114 BOOL Ret = FALSE;
115 LPWSTR lpFormat, lpStr;
116 va_list lArgs;
117
119 hInstance,
120 uID) > 0)
121 {
122 va_start(lArgs, uID);
123 /* let's use FormatMessage to format it because it has the ability to allocate
124 memory automatically */
126 lpFormat,
127 0,
128 0,
129 (VOID*)&lpStr,
130 0,
131 &lArgs);
132 va_end(lArgs);
133
134 if (lpStr != NULL)
135 {
138 (WPARAM)PartId,
139 (LPARAM)lpStr);
140 LocalFree((HLOCAL)lpStr);
141 }
142
144 }
145
146 return Ret;
147}
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
LRESULT WINAPI SendMessageW(_In_ HWND, _In_ UINT, _In_ WPARAM, _In_ LPARAM)

◆ StatusBarLoadString()

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

Definition at line 150 of file misc.c.

154{
155 BOOL Ret = FALSE;
156 LPWSTR lpStr;
157
158 if (AllocAndLoadString(&lpStr,
159 hInstance,
160 uID) > 0)
161 {
164 (WPARAM)PartId,
165 (LPARAM)lpStr);
166 LocalFree((HLOCAL)lpStr);
167 }
168
169 return Ret;
170}

◆ UnicodeToAnsi()

DWORD UnicodeToAnsi ( LPCWSTR  lpSrcStr,
LPSTR lpDstStr 
)

Definition at line 290 of file misc.c.

292{
293 INT length;
294 INT ret = 0;
295
296 length = wcslen(lpSrcStr) + 1;
297
298 *lpDstStr = (LPSTR)HeapAlloc(GetProcessHeap(), 0, length);
299 if (*lpDstStr)
300 {
302 0,
303 lpSrcStr,
304 -1,
305 *lpDstStr,
306 length,
307 NULL,
308 NULL);
309 }
310
311 return ret;
312}
#define WideCharToMultiByte
Definition: compat.h:111
_CRTIMP size_t __cdecl wcslen(_In_z_ const wchar_t *_Str)
char * LPSTR
Definition: xmlstorage.h:182