2 * PROJECT: ReactOS Services
3 * LICENSE: GPL - See COPYING in the top level directory
4 * FILE: base/system/servman/misc.c
5 * PURPOSE: miscallanous functions
6 * COPYRIGHT: Copyright 2005 Thomas Weidenmueller <w3seek@reactos.org>
7 * Copyright 2006 Ged Murphy <gedmurphy@gmail.com>
14 LengthOfStrResource(IN HINSTANCE hInst
,
26 /* There are always blocks of 16 strings */
27 lpName
= (LPWSTR
)MAKEINTRESOURCE((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 LPTSTR
*lpTarget
,
56 ln
= LengthOfStrResource(hInst
,
60 (*lpTarget
) = (LPTSTR
)LocalAlloc(LMEM_FIXED
,
62 if ((*lpTarget
) != NULL
)
65 if (!(Ret
= LoadString(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
= FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER
| FORMAT_MESSAGE_FROM_STRING
,
101 LocalFree((HLOCAL
)lpFormat
);
108 StatusBarLoadAndFormatString(IN HWND hStatusBar
,
110 IN HINSTANCE hInstance
,
115 LPTSTR 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
= FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER
| FORMAT_MESSAGE_FROM_STRING
,
136 Ret
= (BOOL
)SendMessage(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
)SendMessage(hStatusBar
,
166 LocalFree((HLOCAL
)lpStr
);
174 GetTextFromEdit(OUT LPTSTR lpString
,
178 INT len
= GetWindowTextLength(GetDlgItem(hDlg
, Res
));
194 LPTSTR lpMsgBuf
= NULL
;
196 FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER
|
197 FORMAT_MESSAGE_FROM_SYSTEM
|
198 FORMAT_MESSAGE_IGNORE_INSERTS
,
201 MAKELANGID(LANG_NEUTRAL
, SUBLANG_DEFAULT
),
206 MessageBox(NULL
, lpMsgBuf
, _T("Error!"), MB_OK
| MB_ICONERROR
);
211 VOID
DisplayString(PTCHAR Msg
)
213 MessageBox(NULL
, Msg
, _T("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_COLOR24
,
233 EndResource
- StartResource
,
235 if (hImageList
== NULL
)
238 /* Add all icons to the image list */
239 for (i
= StartResource
; i
<= EndResource
; i
++)
241 hBitmap
= (HBITMAP
) LoadImage(hInstance
,
250 Ret
= ImageList_AddMasked(hImageList
,
256 DeleteObject(hBitmap
);