2 * PROJECT: ReactOS API Test GUI
3 * LICENSE: GPL - See COPYING in the top level directory
5 * PURPOSE: miscallanous functions
6 * COPYRIGHT: Copyright 2005 Thomas Weidenmueller <w3seek@reactos.org>
7 * Copyright 2006 - 2008 Ged Murphy <gedmurphy@gmail.com>
14 LengthOfStrResource(IN HINSTANCE hInst
,
26 /* There are always blocks of 16 strings */
27 lpName
= (LPWSTR
)MAKEINTRESOURCEW((uID
>> 4) + 1);
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
)))
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
++)
40 lpStr
+= (*lpStr
) + 1;
43 /* Found the string */
50 AllocAndLoadString(OUT LPWSTR
*lpTarget
,
56 ln
= LengthOfStrResource(hInst
,
60 (*lpTarget
) = (LPTSTR
)LocalAlloc(LMEM_FIXED
,
62 if ((*lpTarget
) != NULL
)
65 if (!(Ret
= LoadStringW(hInst
, uID
, *lpTarget
, ln
)))
67 LocalFree((HLOCAL
)(*lpTarget
));
76 LoadAndFormatString(IN HINSTANCE hInstance
,
85 if (AllocAndLoadString(&lpFormat
,
89 va_start(lArgs
, lpTarget
);
90 /* let's use Format to format it because it has the ability to allocate
91 memory automatically */
92 Ret
= FormatMessageW(FORMAT_MESSAGE_ALLOCATE_BUFFER
| FORMAT_MESSAGE_FROM_STRING
,
101 LocalFree((HLOCAL
)lpFormat
);
108 StatusBarLoadAndFormatString(IN HWND hStatusBar
,
110 IN HINSTANCE hInstance
,
115 LPWSTR lpFormat
, lpStr
;
118 if (AllocAndLoadString(&lpFormat
,
122 va_start(lArgs
, uID
);
123 /* let's use FormatMessage to format it because it has the ability to allocate
124 memory automatically */
125 Ret
= FormatMessageW(FORMAT_MESSAGE_ALLOCATE_BUFFER
| FORMAT_MESSAGE_FROM_STRING
,
136 Ret
= (BOOL
)SendMessageW(hStatusBar
,
140 LocalFree((HLOCAL
)lpStr
);
143 LocalFree((HLOCAL
)lpFormat
);
150 StatusBarLoadString(IN HWND hStatusBar
,
152 IN HINSTANCE hInstance
,
158 if (AllocAndLoadString(&lpStr
,
162 Ret
= (BOOL
)SendMessageW(hStatusBar
,
166 LocalFree((HLOCAL
)lpStr
);
174 GetTextFromEdit(OUT LPWSTR lpString
,
178 INT len
= GetWindowTextLengthW(GetDlgItem(hDlg
, Res
));
181 GetDlgItemTextW(hDlg
,
192 VOID
DisplayError(INT err
)
194 LPWSTR lpMsgBuf
= NULL
;
196 FormatMessageW(FORMAT_MESSAGE_ALLOCATE_BUFFER
|
197 FORMAT_MESSAGE_FROM_SYSTEM
|
198 FORMAT_MESSAGE_IGNORE_INSERTS
,
201 MAKELANGID(LANG_NEUTRAL
, SUBLANG_DEFAULT
),
206 MessageBoxW(NULL
, lpMsgBuf
, L
"Error!", MB_OK
| MB_ICONERROR
);
211 VOID
DisplayMessage(LPWSTR lpMsg
)
213 MessageBoxW(NULL
, lpMsg
, L
"Note!", MB_ICONEXCLAMATION
|MB_OK
);
219 InitImageList(UINT StartResource
,
225 HIMAGELIST hImageList
;
229 /* Create the toolbar icon image list */
230 hImageList
= ImageList_Create(Width
,
232 ILC_MASK
| ILC_COLOR32
,
233 EndResource
- StartResource
,
235 if (hImageList
== NULL
)
238 /* Add all icons to the image list */
239 for (i
= StartResource
; i
<= EndResource
; i
++)
241 hIcon
= (HICON
)LoadImageW(hInstance
,
250 Ret
= ImageList_AddIcon(hImageList
,
262 ImageList_Destroy(hImageList
);
267 AnsiToUnicode(LPCSTR lpSrcStr
,
273 length
= strlen(lpSrcStr
) + 1;
275 *lpDstStr
= (LPWSTR
)HeapAlloc(GetProcessHeap(), 0, length
* sizeof(WCHAR
));
278 ret
= MultiByteToWideChar(CP_ACP
,
290 UnicodeToAnsi(LPCWSTR lpSrcStr
,
296 length
= wcslen(lpSrcStr
) + 1;
298 *lpDstStr
= (LPSTR
)HeapAlloc(GetProcessHeap(), 0, length
);
301 ret
= WideCharToMultiByte(CP_ACP
,