none
API 控件中读取数据 RRS feed

  • 常规讨论

  •    case IDC_BI_ADD:
        {
         TCHAR Date[WRITIME],
           Date_Year[WRITIME],
           Date_Month[WRITIME],
           Date_Day[WRITIME],
           Quntity[QUANTICHAR],
           Writer[WRITER],
           BookName[BOOKNAME],
           About[ABOUTBOOK],
           Temp_Combo[IDLIBRARY],
           IDLocation[IDLIBRARY],
           IDBookType[IDTYPE];
         int  iLength,i,Index;


         //////////////////////////////
         iLength = GetWindowTextLength(hwnd_Quntity );
         if( iLength !=0 )
          GetWindowText(hwnd_Quntity, Quntity ,iLength + 1); //由于字符串最后一位\0占用,所以加一
         else
         {
          MessageBox(hwnd,TEXT("请输入书本数量"),TEXT("错误"),MB_OK);
          return FALSE;
         }
         //////////////////////////////
         iLength = GetWindowTextLength(hwnd_Writer );
         if( iLength !=0 )
          GetWindowText(hwnd_Writer, Writer ,iLength + 1); //由于字符串最后一位\0占用,所以加一
         else
          Writer[0]=TEXT('\0');
         //////////////////////////////
         iLength = GetWindowTextLength(hwnd_BookName );
         if( iLength !=0 )
          GetWindowText(hwnd_BookName, BookName ,iLength + 1); //由于字符串最后一位\0占用,所以加一
         else
         {
          MessageBox(hwnd,TEXT("请输入书名"),TEXT("错误"),MB_OK);
          return FALSE;
         }
         //////////////////////////////
         iLength = GetWindowTextLength(hwnd_About );
         if( iLength !=0 )
          GetWindowText(hwnd_About, About ,iLength + 1); //由于字符串最后一位\0占用,所以加一
         else
          About[0]=TEXT('\0');
         //////////////////////////////
         iLength = GetWindowTextLength(hwnd_Date_Year );
         if( iLength !=0 )
         {
          GetWindowText(hwnd_Date_Year, Date_Year ,iLength + 1); //由于字符串最后一位\0占用,所以加一
          if(lstrlen(Date_Year) != 4 )
          {
           MessageBox(hwnd,TEXT("请正确输入年"),TEXT("错误"),MB_OK);
           return FALSE;
          }
          iLength = GetWindowTextLength(hwnd_Date_Month );
          GetWindowText(hwnd_Date_Month, Date_Month ,iLength + 1); //由于字符串最后一位\0占用,所以加一
          if ( _ttoi(Date_Month) > 12  || iLength != 2 )
          {
           MessageBox(hwnd,TEXT("请正确输入月"),TEXT("错误"),MB_OK);
           return FALSE;
          }
          iLength = GetWindowTextLength(hwnd_Date_Day );
          GetWindowText(hwnd_Date_Day, Date_Day ,iLength + 1); //由于字符串最后一位\0占用,所以加一
          if ( _ttoi(Date_Day) > 32  || iLength != 2 )
          {
           MessageBox(hwnd,TEXT("请正确输入日"),TEXT("错误"),MB_OK);
           return FALSE;
          }
          lstrcpy(Date , Date_Year );
          lstrcat(Date , Date_Month );
          lstrcat(Date , Date_Day );
         }
         else
          Date[0]=TEXT('\0');

         //下拉菜单处理
         Index = SendMessage(hwnd_ComboSecond,CB_GETCURSEL, 0 , 0 );
         if ( Index != -1 )
         {
          SendMessage(hwnd_ComboSecond,CB_GETLBTEXT, Index , (LPARAM)Temp_Combo );
          for(i=0;  ; i++ )//取得数字
          {
           if(Temp_Combo[i] == TEXT(' ') )
            break;
           IDBookType[i] = Temp_Combo[i];
          }
          IDBookType[i] = TEXT('\0');
         }
         else
         {
          MessageBox(hwnd,TEXT("请选择书本类型"),TEXT("错误"),MB_OK);
          return FALSE;
         }
         ////////////////////////////
         Index = SendMessage(hwnd_ComboLocation,CB_GETCURSEL, 0 , 0 );
         if ( Index != -1 )
         {
          SendMessage(hwnd_ComboLocation,CB_GETLBTEXT, Index , (LPARAM)Temp_Combo );
          for(i=0;  ; i++ )//取得数字
          {
           if(Temp_Combo[i] == TEXT(' ') )
            break;
           IDLocation[i] = Temp_Combo[i];
          }
          IDLocation[i] = TEXT('\0');
         }
         else
         {
          MessageBox(hwnd,TEXT("请选择书本存放地点"),TEXT("错误"),MB_OK);
          return FALSE;
         }
    Date数据运行到Index = SendMessage(hwnd_ComboSecond,CB_GETCURSEL, 0 , 0 );
    之前一切正常,在从下拉菜单中取得数据后
    Date的数据会被莫名其妙的改变,改变为SendMessage(hwnd_ComboLocation,CB_GETLBTEXT, Index , (LPARAM)Temp_Combo );取得的ComboBox数据Temp_Combo的后半段
    而其它数据都不会变化

    如果将读取字符串的顺序改变
       case IDC_BI_ADD:
        {
         TCHAR Date[WRITIME],
           Date_Year[WRITIME],
           Date_Month[WRITIME],
           Date_Day[WRITIME],
           Quntity[QUANTICHAR],
           Writer[WRITER],
           BookName[BOOKNAME],
           About[ABOUTBOOK],
           Temp_Combo[IDLIBRARY],
           IDLocation[IDLIBRARY],
           IDBookType[IDTYPE];
         int  iLength,i,Index;


         //下拉菜单处理
         Index = SendMessage(hwnd_ComboSecond,CB_GETCURSEL, 0 , 0 );
         if ( Index != -1 )
         {
          SendMessage(hwnd_ComboSecond,CB_GETLBTEXT, Index , (LPARAM)Temp_Combo );
          for(i=0;  ; i++ )//取得数字
          {
           if(Temp_Combo[i] == TEXT(' ') )
            break;
           IDBookType[i] = Temp_Combo[i];
          }
          IDBookType[i] = TEXT('\0');
         }
         else
         {
          MessageBox(hwnd,TEXT("请选择书本类型"),TEXT("错误"),MB_OK);
          return FALSE;
         }
         ////////////////////////////
         Index = SendMessage(hwnd_ComboLocation,CB_GETCURSEL, 0 , 0 );
         if ( Index != -1 )
         {
          SendMessage(hwnd_ComboLocation,CB_GETLBTEXT, Index , (LPARAM)Temp_Combo );
          for(i=0;  ; i++ )//取得数字
          {
           if(Temp_Combo[i] == TEXT(' ') )
            break;
           IDLocation[i] = Temp_Combo[i];
          }
          IDLocation[i] = TEXT('\0');
         }
         else
         {
          MessageBox(hwnd,TEXT("请选择书本存放地点"),TEXT("错误"),MB_OK);
          return FALSE;
         }

         //Edit文本
         iLength = GetWindowTextLength(hwnd_Quntity );
         if( iLength !=0 )
          GetWindowText(hwnd_Quntity, Quntity ,iLength + 1); //由于字符串最后一位\0占用,所以加一
         else
         {
          MessageBox(hwnd,TEXT("请输入书本数量"),TEXT("错误"),MB_OK);
          return FALSE;
         }
         //////////////////////////////
         iLength = GetWindowTextLength(hwnd_Writer );
         if( iLength !=0 )
          GetWindowText(hwnd_Writer, Writer ,iLength + 1); //由于字符串最后一位\0占用,所以加一
         else
          Writer[0]=TEXT('\0');
         //////////////////////////////
         iLength = GetWindowTextLength(hwnd_BookName );
         if( iLength !=0 )
          GetWindowText(hwnd_BookName, BookName ,iLength + 1); //由于字符串最后一位\0占用,所以加一
         else
         {
          MessageBox(hwnd,TEXT("请输入书名"),TEXT("错误"),MB_OK);
          return FALSE;
         }
         //////////////////////////////
         iLength = GetWindowTextLength(hwnd_About );
         if( iLength !=0 )
          GetWindowText(hwnd_About, About ,iLength + 1); //由于字符串最后一位\0占用,所以加一
         else
          About[0]=TEXT('\0');
         //////////////////////////////
         iLength = GetWindowTextLength(hwnd_Date_Year );
         if( iLength !=0 )
         {
          GetWindowText(hwnd_Date_Year, Date_Year ,iLength + 1); //由于字符串最后一位\0占用,所以加一
          if(lstrlen(Date_Year) != 4 )
          {
           MessageBox(hwnd,TEXT("请正确输入年"),TEXT("错误"),MB_OK);
           return FALSE;
          }
          iLength = GetWindowTextLength(hwnd_Date_Month );
          GetWindowText(hwnd_Date_Month, Date_Month ,iLength + 1); //由于字符串最后一位\0占用,所以加一
          if ( _ttoi(Date_Month) > 12  || iLength != 2 )
          {
           MessageBox(hwnd,TEXT("请正确输入月"),TEXT("错误"),MB_OK);
           return FALSE;
          }
          iLength = GetWindowTextLength(hwnd_Date_Day );
          GetWindowText(hwnd_Date_Day, Date_Day ,iLength + 1); //由于字符串最后一位\0占用,所以加一
          if ( _ttoi(Date_Day) > 32  || iLength != 2 )
          {
           MessageBox(hwnd,TEXT("请正确输入日"),TEXT("错误"),MB_OK);
           return FALSE;
          }
          lstrcpy(Date , Date_Year );
          lstrcat(Date , Date_Month );
          lstrcat(Date , Date_Day );
         }
         else
          Date[0]=TEXT('\0');
    不知道问题出在什么地方
    以下为RC
    ADDBOOK DIALOGEX 0, 0, 420, 240
    STYLE DS_SETFONT | DS_MODALFRAME | DS_CENTER | WS_POPUP | WS_CLIPSIBLINGS | WS_CAPTION | WS_SYSMENU
    CAPTION "Add Book"
    FONT 14, "Times New Roman", 400, 0, 0x0
    BEGIN
        LTEXT           "Код Книги:",IDC_STATIC,10,7,41,8
        LTEXT           "0000000000",IDC_BI_BOOKCODE,50,7,42,10,SS_WORDELLIPSIS | WS_BORDER,WS_EX_STATICEDGE
        LTEXT           "Автор Книги:",IDC_STATIC,10,42,46,8
        LTEXT           "Название Книги:",IDC_STATIC,10,97,56,8
        LTEXT           "Местоположение:",IDC_STATIC,10,60,63,8
        LTEXT           "Дата Выхода:",IDC_STATIC,10,24,45,8
        LTEXT           "Каличество:",IDC_STATIC,174,24,42,8
        LTEXT           "Аннотация:",IDC_STATIC,10,133,40,8
        EDITTEXT        IDC_BI_QUNTITY,218,23,45,12,ES_AUTOHSCROLL | ES_NUMBER,WS_EX_STATICEDGE
        EDITTEXT        IDC_BI_YEAR,71,23,22,12,ES_AUTOHSCROLL | ES_NUMBER,WS_EX_STATICEDGE
        EDITTEXT        IDC_BI_MONTH,104,23,13,12,ES_AUTOHSCROLL | ES_NUMBER,WS_EX_STATICEDGE
        EDITTEXT        IDC_BI_DAY,128,23,13,12,ES_AUTOHSCROLL | ES_NUMBER,WS_EX_STATICEDGE
        EDITTEXT        IDC_BI_WRITER,71,40,192,12,ES_AUTOHSCROLL,WS_EX_STATICEDGE
        COMBOBOX        IDC_BI_LOCATION,71,60,243,105,CBS_DROPDOWNLIST | CBS_SORT | WS_VSCROLL | WS_TABSTOP
        COMBOBOX        IDC_BI_MAINTYPE,41,80,162,103,CBS_DROPDOWNLIST | CBS_SORT | WS_VSCROLL | WS_TABSTOP
        COMBOBOX        IDC_BI_SECONDTYPE,254,80,156,103,CBS_DROPDOWNLIST | CBS_SORT | WS_VSCROLL | WS_TABSTOP
        EDITTEXT        IDC_BI_BOOKNAME,10,106,400,24,ES_MULTILINE | ES_AUTOVSCROLL | WS_VSCROLL,WS_EX_STATICEDGE
        EDITTEXT        IDC_BI_ABOUTBOOK,10,144,400,67,ES_MULTILINE | ES_AUTOVSCROLL | WS_VSCROLL,WS_EX_STATICEDGE
        LTEXT           "Категория:",IDC_STATIC,214,81,39,8
        LTEXT           "Главная :",IDC_STATIC,10,81,30,8
        PUSHBUTTON      "Add",IDC_BI_ADD,114,214,68,16
        PUSHBUTTON      "Cancel",IDCANCEL,238,214,68,16
        LTEXT           "--",IDC_STATIC,96,24,8,8
        LTEXT           "--",IDC_STATIC,120,24,8,8

    2009年5月13日 19:30

全部回复