2 * PROJECT: ReactOS Device Managment
3 * LICENSE: GPL - See COPYING in the top level directory
4 * FILE: base/system/devmgmt/misc.c
5 * PURPOSE: miscallanous functions
6 * COPYRIGHT: Copyright 2006 Ged Murphy <gedmurphy@gmail.com>
13 LengthOfStrResource(IN HINSTANCE hInst
,
25 /* There are always blocks of 16 strings */
26 lpName
= (LPWSTR
)MAKEINTRESOURCE((uID
>> 4) + 1);
28 /* Find the string table block */
29 if ((hrSrc
= FindResourceW(hInst
, lpName
, (LPWSTR
)RT_STRING
)) &&
30 (hRes
= LoadResource(hInst
, hrSrc
)) &&
31 (lpStr
= (LPWSTR
)LockResource(hRes
)))
35 /* Find the string we're looking for */
36 uID
&= 0xF; /* position in the block, same as % 16 */
37 for (x
= 0; x
< uID
; x
++)
39 lpStr
+= (*lpStr
) + 1;
42 /* Found the string */
49 AllocAndLoadString(OUT LPTSTR
*lpTarget
,
55 ln
= LengthOfStrResource(hInst
,
59 (*lpTarget
) = (LPTSTR
)LocalAlloc(LMEM_FIXED
,
61 if ((*lpTarget
) != NULL
)
64 if (!(Ret
= LoadString(hInst
, uID
, *lpTarget
, ln
)))
66 LocalFree((HLOCAL
)(*lpTarget
));
75 LoadAndFormatString(IN HINSTANCE hInstance
,
84 if (AllocAndLoadString(&lpFormat
,
88 va_start(lArgs
, lpTarget
);
89 /* let's use FormatMessage to format it because it has the ability to allocate
90 memory automatically */
91 Ret
= FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER
| FORMAT_MESSAGE_FROM_STRING
,
100 LocalFree((HLOCAL
)lpFormat
);
107 StatusBarLoadAndFormatString(IN HWND hStatusBar
,
109 IN HINSTANCE hInstance
,
114 LPTSTR lpFormat
, lpStr
;
117 if (AllocAndLoadString(&lpFormat
,
121 va_start(lArgs
, uID
);
122 /* let's use FormatMessage to format it because it has the ability to allocate
123 memory automatically */
124 Ret
= FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER
| FORMAT_MESSAGE_FROM_STRING
,
135 Ret
= (BOOL
)SendMessage(hStatusBar
,
139 LocalFree((HLOCAL
)lpStr
);
142 LocalFree((HLOCAL
)lpFormat
);
149 StatusBarLoadString(IN HWND hStatusBar
,
151 IN HINSTANCE hInstance
,
157 if (AllocAndLoadString(&lpStr
,
161 Ret
= (BOOL
)SendMessage(hStatusBar
,
165 LocalFree((HLOCAL
)lpStr
);
173 GetTextFromEdit(OUT LPTSTR lpString
,
177 INT len
= GetWindowTextLength(GetDlgItem(hDlg
, Res
));
193 InitImageList(UINT StartResource
,
199 HIMAGELIST hImageList
;
203 /* Create the toolbar icon image list */
204 hImageList
= ImageList_Create(Width
,
206 ILC_MASK
| ILC_COLOR24
,
207 EndResource
- StartResource
,
209 if (hImageList
== NULL
)
212 /* Add all icons to the image list */
213 for (i
= StartResource
; i
<= EndResource
; i
++)
215 hBitmap
= (HBITMAP
)LoadImage(hInstance
,
224 Ret
= ImageList_AddMasked(hImageList
,
230 DeleteObject(hBitmap
);
241 FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER
|
242 FORMAT_MESSAGE_FROM_SYSTEM
|
243 FORMAT_MESSAGE_IGNORE_INSERTS
,
246 MAKELANGID(LANG_NEUTRAL
, SUBLANG_DEFAULT
),
251 MessageBox(NULL
, lpMsgBuf
, _T("Error!"), MB_OK
| MB_ICONERROR
);
257 VOID
DisplayString(LPTSTR Msg
)
259 MessageBox(NULL
, Msg
, _T("Note!"), MB_ICONEXCLAMATION
|MB_OK
);