15,471
社区成员
发帖
与我相关
我的任务
分享
//给子进程发送文本
WriteFile(hWritePipe1,strsend2,strlen(strsend2)+1,&bytewrite,NULL);
memset(recestr,'\0',50);
//读管道
ReadFile(hReadPipe,recestr,50,&byteread,NULL);//recestr是全局变量
//向主窗口发送自定义消息,表示也有数据从管道流过来
SendMessage(*((HWND*)pParam),WM_MYMESSAGE,0,0);
//把文本显示到编辑框
SendMessage (hEdit1, EM_REPLACESEL, 0, (LPARAM)recestr); //向显示框中添加新输入的文本
#define SZ 1
BYTE *KillHalfHZ(BYTE *pData,UINT len)
{
static BYTE HalfHZ=0;
BYTE firstHalf=0;
UINT HalfAt=0;
UINT total=0;
BYTE *copy=0;
BYTE *pTmp=0;
//
if(HalfHZ !=0)
{// add last half HZ to new line
copy=new BYTE[len+1+SZ];
memset(copy,0,len+1+SZ);
copy[0]=HalfHZ;
HalfHZ=0;
memcpy(©[1],pdata,len);
total=len+1;
}
else
{// keep original
copy=new BYTE[len+SZ];
memset(copy,0,len+SZ);
memcpy(copy,pdata,len);
total=len;
}
pTmp=copy;
// check this new line
for(UINT i=0;i<total;i++)
{
if(*pTmp >= 0x80)
{
if(firstHalf==0)
{
firstHalf = *pTmp;
HalfAt = i+1;
}
else
{// has half HZ
if(i == HalfAt)
{// 1 hz
firstHalf=0;
HalfAt=0;
}
else
{// *pTmp='?'
}
}
}
pTmp++;
}
if(HalfAt == 0)
{ // new line no half HZ
copy[total]=0;
}
else if (HalfAt==total)
{// new line has half HZ at end
HalfHZ= firstHalf;
copy[total-1]=0;// sz
}
// delete it after use
return copy;
}
调用时给原读来的数组和长度,返回后直接使用新产生的copy。
BYTE *pstr=KillHalfHZ(pData,len);
replace到edit。
用完delete []pstr