缓冲区经过GetDlgItemText函数好的数据变化
程序代码:
//读文件数据 //DpathFile为要保存的文件的全文件路径名 void readData(HWND hwnd, char *DpathFile) { char szFile[MAX_PATH]; //第一种情况 //初始化str char str[1024]; // ZeroMemory(str,sizeof(str)); char sz[256]; char *lpFp; //获取源文件全路径 GetDlgItemText(hwnd, IDC_PATHFILE,szFile,sizeof(szFile)/sizeof(char)); ShowError(str); [local]1[/local] //lpFp = strrchr(szFile, '\\');//获取文件名 int LineNum = GetLineCount(szFile);//文件中的行数 int icount=0; //发送消息给进程条 SendDlgItemMessage(hwnd, IDC_PROGRESS, PBM_SETRANGE, 0, MAKELPARAM(0,LineNum)); ShowError(str); //打开文件读操作 //第二种情况初始化str //char str[1024]; HANDLE hFileread; DWORD dwRead; DWORD dwWrite; hFileread = CreateFile(szFile,GENERIC_READ,0, 0, OPEN_EXISTING,FILE_ATTRIBUTE_NORMAL, 0); if (hFileread == INVALID_HANDLE_VALUE) { MessageBox(NULL, TEXT("CreateFile to read error!"),TEXT("error"), MB_OK); } //创建新的文件写 HANDLE hFile; hFile = CreateFile(DpathFile,GENERIC_WRITE,0, NULL, CREATE_ALWAYS,FILE_ATTRIBUTE_NORMAL, NULL); if (hFile == INVALID_HANDLE_VALUE) { MessageBox(NULL, TEXT("CreateFile to write error!"),TEXT("error"), MB_OK); return ; } ShowError(str); while(true) { //初始化缓冲区 ZeroMemory(str,sizeof(str)); int bRet=ReadFile(hFileread,str,1024,&dwRead,NULL);//读取1024字节 if(bRet==FALSE) { MessageBox(NULL,"Read Buf ERROR!","Error",MB_OK); break; } else if(dwRead==0)//如果读到的字节数为0标示文件读取完毕 { MessageBox(NULL,"Send file OK!","OK",MB_OK); break; } else { WriteFile(hFile,str,dwRead,&dwWrite,NULL);//recv()接收到多少就写多少 } SendDlgItemMessage(hwnd, IDC_PROGRESS, PBM_SETPOS, icount, 0); wsprintf(sz,"%i", icount); SetDlgItemText(hwnd, IDC_PATHFILE, sz); icount++; } CloseHandle(hFileread); CloseHandle(hFile);我想问一下为什么我的程序中定义的缓冲区,经过GetDlgItemText函数后
会在该缓冲区最后面加上从编辑框得到的数据szFile。