4 LengthOfStrResource(IN HINSTANCE hInst
,
16 /* There are always blocks of 16 strings */
17 lpName
= (LPWSTR
)MAKEINTRESOURCE((uID
>> 4) + 1);
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
)))
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
++)
30 lpStr
+= (*lpStr
) + 1;
33 /* Found the string */
40 AllocAndLoadString(OUT LPTSTR
*lpTarget
,
46 ln
= LengthOfStrResource(hInst
,
50 (*lpTarget
) = (LPTSTR
)LocalAlloc(LMEM_FIXED
,
52 if ((*lpTarget
) != NULL
)
55 if (!(Ret
= LoadString(hInst
, uID
, *lpTarget
, ln
)))
57 LocalFree((HLOCAL
)(*lpTarget
));
66 LoadAndFormatString(IN HINSTANCE hInstance
,
75 if (AllocAndLoadString(&lpFormat
,
79 va_start(lArgs
, lpTarget
);
80 /* let's use FormatMessage to format it because it has the ability to allocate
81 memory automatically */
82 Ret
= FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER
| FORMAT_MESSAGE_FROM_STRING
,
91 LocalFree((HLOCAL
)lpFormat
);
98 StatusBarLoadAndFormatString(IN HWND hStatusBar
,
100 IN HINSTANCE hInstance
,
105 LPTSTR lpFormat
, lpStr
;
108 if (AllocAndLoadString(&lpFormat
,
112 va_start(lArgs
, uID
);
113 /* let's use FormatMessage to format it because it has the ability to allocate
114 memory automatically */
115 Ret
= FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER
| FORMAT_MESSAGE_FROM_STRING
,
126 Ret
= (BOOL
)SendMessage(hStatusBar
,
130 LocalFree((HLOCAL
)lpStr
);
133 LocalFree((HLOCAL
)lpFormat
);
140 StatusBarLoadString(IN HWND hStatusBar
,
142 IN HINSTANCE hInstance
,
148 if (AllocAndLoadString(&lpStr
,
152 Ret
= (BOOL
)SendMessage(hStatusBar
,
156 LocalFree((HLOCAL
)lpStr
);
164 GetTextFromEdit(OUT LPTSTR lpString
,
168 INT len
= GetWindowTextLength(GetDlgItem(hDlg
, Res
));
183 VOID
GetError(DWORD err
)
188 err
= GetLastError();
190 FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER
|
191 FORMAT_MESSAGE_FROM_SYSTEM
|
192 FORMAT_MESSAGE_IGNORE_INSERTS
,
195 MAKELANGID(LANG_NEUTRAL
, SUBLANG_DEFAULT
),
200 MessageBox(NULL
, (LPCTSTR
) lpMsgBuf
, _T("Error!"), MB_OK
| MB_ICONERROR
);