In GTK, the default form of character encoding is UTF-8, where all of the displayed strings need to be UTF8 encoded for normal display.
As a result, several character-coded conversion functions become important. Of course, the function of character encoding conversion is also important in some other development frameworks. These work determines whether our program will display garbled characters when it is executed.
The following are several conversion functions in G_lib.
In the use of these functions, the first to understand the local character encoding format, so, to write a good transplant program, pay attention to the localized control code, that is, need to study the locale of things.
Gchar *g_locale_to_utf8 (const Gchar *opsysstring, Gssize len, Gsize *bytes_read, Gsize *bytes_written, GError **error);
Gchar *g_locale_from_utf8 (const Gchar *utf8string,gssize len, gsize *bytes_read, Gsize *bytes_written, GError **error);
These two functions convert the encoded format of a string into utf8 and local encodings.
Char *_ (char *string)
{
Return (G_locale_to_utf8 (string,-1, NULL, NULL, NULL));
}
Char *__ (char *string)
{
Return (G_locale_from_utf8 (string,-1, NULL, NULL, NULL));
}
This is the effect of encapsulation, the direct use of the call _ ("we") can be transformed.
If you want to display Chinese characters on the GTK + widget, use G_convert ("China", -1, "UTF-8", "GB2312", null,null,null);
In the GTK + program to read a file containing a Chinese character path in the console display or fopen (), use the
G_convert ("China", -1, "GB2312", "UTF-8", Null,null,null).
Of course, not necessarily is GB2312, this is to be based on local specific circumstances to set.