Use of loadstring
If the program involves multiple languages, we cannot use drawtext (HDC, l "test",...) when writing on the screen ",...) instead, use the loadstring function to load string resources from the resource. In this way, you only need to replace the string resources when changing the language, without modifying the code.
The following is the prototype of the loadstring function:
Int Loadstring (
Hinstance Hinstance,
Uint UID,
Lptstr Lpbuffer,
Int Cchbuffermax
);
Parameter description:
Hinstance:
The instance handle of the resource.
NID: ID of the string resource.
Lpbuffer: the buffer used to store strings.
Cchbuffermax: buffer size. If cchbuffermax is greater than the string length, the string will be truncated and ended with/0. If the string length is greater than or equal to cchbuffermax, the program will crash due to buffer overflow.
For example, the following code: (ids_str_test = l "under test ")
Wchar temp [2]; <br/>: loadstring (null, ids_str_test, temp, sizeof (temp); <br/>: drawtext (HDC, temp, -1, & rect, dt_center | dt_vcenter); <br/>
This program will crash due to buffer overflow.
Loadstring also has a usage. You do not need to pass in the buffer, but directly set lpbuffer to null, and then forcibly convert the return value to lpwstr to obtain the pointer to the resource file. Because it is directly directed to the resource file, therefore, the obtained string is read-only.
Usage: (ids_str_test = l "testing ")
Lpwstr lpstr = (lpwstr): loadstring (null, ids_str_test, null, 0); <br/>:: drawtext (HDC, lpstr,-1, & rect, dt_center | dt_vcenter); <br/>
However, before using this method, we must add the-n flag to the resource compiler to ensure that the resulting string is ended with "/0. The settings in vs2005 are as follows:
In fact, the cstring function is almost encapsulated for us. We can also directly call the cstring member function to load the resource string.
Cstring s; <br/> S. loadstring (ids_str_test );