My YUV player MFC small Note: Unicode encoding, wide character

Source: Internet
Author: User
Tags character set locale locale setting lowercase sprintf strcmp string format strlen
The previous MFC project, the character set is based on multibyte, and now this project, unintentionally using the Unicode character set, in its process, there are many functions used differently than before. Of course, you can also modify the character set in the project properties after the project is established. This article records something about the Unicode project. In retrospect, these days have been written in the MFC article is more than the end of the gap. This series of estimates is no longer written. The 4.0 version released last night is the end version. The tool is finished. The first is the string constants in MFC to use _t (). For example, define the resolution statement: M_straddedsize = _t ("160x120;176x144;320x240;352x288;640x480;704x576;720x480;1280x720;1600x1200; 1920x1080 "); For example, create a Registry node statement: RegCreateKey (HKEY_CURRENT_USER, _t ("software\\yuvplayer-latelee.org\\setting"), &hkey); The wide character version corresponding to the char type is wchar_t. Other functions related to string processing must also use the corresponding wide-character version. For example, sprintf corresponds to the wide character function is swprintf,sscanf corresponding to is swscanf (safe version is in swscanf_s). The string comparison function strcmp corresponds to WCSCMP. Computes the length of the string strlen corresponds to Wcslen. The function of parsing the file name given in the previous article does not take into account the wide character, so the project's wide character is converted to ordinary characters and then passed into the function. The sample code is as follows://Find File name
wchar_t* tmp = WCSRCHR (pfilepathname, ' \ \ ');
Char szfilename[256] = {0};
WideCharToMultiByte (CP_ACP, 0, tmp+1, wcslen (tmp+1), szFileName, n, null, NULL); M_psettingdlg->parsefilename (szFileName);
The following is a relatively comprehensive wide character and ordinary character manipulation function found on the network.


Wide character Functions normal C function Description
Iswalnum () Isalnum () Test whether a character is a number or a letter
Iswalpha () Isalpha () Test whether the character is a letter
Iswcntrl () Iscntrl () Test whether a character is a control
Iswdigit () IsDigit () Test whether a character is a number
Iswgraph () Isgraph () Test whether a character is a visible character
Iswlower () Islower () Test whether the character is lowercase characters
Iswprint () Isprint () Test whether a character is a printable character
Iswpunct () Ispunct () Test whether a character is a punctuation mark
Iswspace () Isspace () Test whether a character is a blank symbol
Iswupper () Isupper () Test whether a character is uppercase characters
Iswxdigit () Isxdigit () Test whether the character is a hexadecimal digit

Case conversion:

Wide character Functions normal C function Description
Towlower () ToLower () Convert a character to lowercase
Towupper () ToUpper () Convert characters to uppercase

Character comparisons:

Wide character Functions normal C function Description
Wcscoll () Strcoll () Comparing strings

Date and Time conversion:

Wide character Functions Description
Strftime () Formats the date and time according to the specified string format and locale setting
Wcsftime () Formats the date and time according to the specified string format and locale, and returns a wide string
Strptime () Converts a string to a time value according to the specified format, which is the inverse of the strftime


Print and Scan strings:

Wide character Functions Description
fprintf ()/fwprintf () Formatted output using the VARARG parameter
FSCANF ()/fwscanf () Format read-in
printf () Format output to standard output using the VARARG parameter
scanf () Format read-in from standard input
sprintf ()/swprintf () Format a string according to the vararg parameter table
SSCANF () Format read-in as a string
vfprintf ()/vfwprintf () Format output to a file using the Stdarg parameter table
vprintf () Format output to standard output using the Stdarg parameter table
vsprintf ()/vswprintf () Format stdarg parameter table and write to string


Digital conversions:

Wide character Functions normal C function Description
Wcstod () Strtod () Converts the initial part of a wide character to a double-precision floating-point number
Wcstol () Strtol () Converts the initial part of a wide character to a long integer
Wcstoul () Strtoul () Converts the initial part of a wide character to an unsigned long integer


Multibyte character and wide character conversion and manipulation:

Wide character Functions Description
Mblen () Determines the number of bytes of a character based on locale settings
MBSTOWCS () Convert a multibyte string to a wide string
MBTOWC ()/BTOWC () Convert multi-byte characters to wide characters
Wcstombs () Convert a wide string to a multibyte string
Wctomb ()/wctob () Convert wide characters to multibyte characters


Input and output:

Wide character Functions normal C function Description
FGETWC () FGETC () Reads a character from the stream and converts it to a wide character
Fgetws () Fgets () Reads a string from the stream and converts it to a wide string
FPUTWC () FPUTC () Converts wide characters to multibyte characters and outputs to standard output
Fputws () Fputs () Converts a wide string to multibyte characters and outputs to a standard output string
GETWC () GETC () Read characters from standard input and convert to wide characters
Getwchar () GetChar () Read characters from standard input and convert to wide characters
None Gets () Using Fgetws ()
PUTWC () PUTC () Converts wide characters to multibyte characters and writes to standard output
Putwchar () GetChar () Converts wide characters to multibyte characters and writes to standard output
None Puts () Using Fputws ()
UNGETWC () UNGETC () Descriptors a wide character back into the input stream


String manipulation:

Wide character Functions normal C function Description
Wcscat () Strcat () Take a string to the tail of another string
Wcsncat () Strncat () Similar to Wcscat (), and specifies the glue length of the bonded string.
WCSCHR () STRCHR () Find the first position of a substring
WCSRCHR () STRRCHR () Finds the first occurrence of a substring starting at the tail
WCSPBRK () STRPBRK () Finds the first occurrence of any character in another string from a character string
Wcswcs ()/wcsstr () STRCHR () Finds the position of the first occurrence of another string in a string
WCSCSPN () STRCSPN () Returns the initial number that does not contain a second string
WCSSPN () STRSPN () Returns the initial number that contains the second string
wcscpy () strcpy () Copy string
wcsncpy () strncpy () Similar to wcscpy (), specifying the number of copies
WCSCMP () strcmp () Comparison of two wide strings
WCSNCMP () STRNCMP () Similar to WCSCMP (), also specify the number of comparison character strings
Wcslen () Strlen () Get the number of wide strings
Wcstok () Strtok () Break wide strings into a series of strings based on identifiers
Wcswidth () None Get the width of a wide string
Wcwidth () None Get the width of a wide character

The C language Wide character function can be found in the header file <wchar.h>. Reference: http://www.cplusplus.com/reference/cwchar/
Li Yu 2015.8.19 Night

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.