user-0 提问: windows编程

回复:
user: user-1
content: sscanf, swscanf Read formatted data from a string.  int sscanf( const char *buffer, const char *format [, argument ] ... );  int swscanf( const wchar_t *buffer, const wchar_t *format [, argument ] ... );  Routine Required Header Compatibility  sscanf <stdio.h> ANSI, Win 95, Win NT  swscanf <stdio.h> or <wchar.h> ANSI, Win 95, Win NT    For additional compatibility information, see Compatibility in the Introduction.  Libraries  LIBC.LIB Single thread static library, retail version  LIBCMT.LIB Multithread static library, retail version  MSVCRT.LIB Import library for MSVCRT.DLL, retail version    Return Value  Each of these functions returns the number of fields successfully converted and assigned; the return value does not include fields that were read but not assigned. A return value of 0 indicates that no fields were assigned. The return value is EOF for an error or if the end of the string is reached before the first conversion.  Parameters  buffer  Stored data  format  Format-control string  argument  Optional arguments  For more information, see Format Specifications.  Remarks  The sscanf function reads data from buffer into the location given by each argument. Every argument must be a pointer to a variable with a type that corresponds to a type specifier in format. The format argument controls the interpretation of the input fields and has the same form and function as the format argument for the scanf function; see scanf for a complete description of format. If copying takes place between strings that overlap, the behavior is undefined.  swscanf is a wide-character version of sscanf; the arguments to swscanf are wide-character strings. sscanf does not handle multibyte hexadecimal characters. swscanf does not handle Unicode fullwidth hexadecimal or “compatibility zone” characters. Otherwise, swscanf and sscanf behave identically.  Generic-Text Routine Mappings  TCHAR.H Routine  _UNICODE & _MBCS Not Defined _MBCS Defined _UNICODE Defined  _stscanf sscanf sscanf swscanf    Example  /* SSCANF.C: This program uses sscanf to read data items  * from a string named tokenstring, then displays them.  */  #include <stdio.h>  void main( void ) {    char  tokenstring[] = "15 12 14...";    char  s[81];    char  c;    int   i;    float fp;     /* Input various data from tokenstring: */    sscanf( tokenstring, "%s", s );    sscanf( tokenstring, "%c", &c );    sscanf( tokenstring, "%d", &i );    sscanf( tokenstring, "%f", &fp );     /* Output the data read */    printf( "String    = %s\n", s );    printf( "Character = %c\n", c );    printf( "Integer:  = %d\n", i );    printf( "Real:     = %f\n", fp ); }   Output  String    = 15 Character = 1 Integer:  = 15 Real:     = 15.000000   Stream I/O Routines  See Also   fscanf, scanf, sprintf, _snprintf

user: user-0
content: 囧么转换，为什么我转换得的结果是那种不认识的字符。我使用createwindow创建的edit，不是dialog哦

user: user-2
content: CEdit *pEdit = (CEdit*)GetDlgItem(IDC_EDIT1);///IDC_EDIT1改成你的 CString str1; pEdit->GetWindowText(str1); int a = = _ttoi(str1);//将CString ->int

user: user-2
content: 4楼的方法可以做;将一个INT变量和文本框关联起来（这里电脑会自己帮你判断是否输入的是数字） 另一方法是每次要用时，获取文本框的内容，然后将其转化为INT(这里你要自己来判断输入是不是数字)

user: user-3
content: 不是有可以添加变量吗？添加变量，然后变量类型设置为int，不就可以啦？

user: user-4
content: TCHAR tchText[64]={0};  GetDlgItemText(IDC_EDIT_ANTENNA_COMAZ,tchText,64); int iEdit = _ttoi(tchText);   BOOL flag; UINT ui=GetDlgItemInt(IDC_EDIT1,&flag,true);

user: user-0
content: 是用哪一个组件，edit还是dlg，能不能给我一下核心代码

user: user-5
content: GetDlgItemInt