16,371
社区成员




// Fill a string array in hex format
BOOL CShowHexDoc::StringBin()
{
BYTE *pTmp=m_pBuffer;
CString tmp;
CString prompt;
BYTE comment[40];
// if is there an old
m_HexStrArray.RemoveAll();
//
int FullRows=m_nSize/16;
int PartRow=m_nSize%16;
//
for(int rr=0;rr < FullRows ; rr++)
{//
tmp.Format("%05X:", 16*rr);//"10000:" 16 bytes
prompt+=tmp;
for(int col = 0;col < 16; col++)
{
if((*pTmp>' ') && (*pTmp<'z')) comment[col]=*pTmp;
else comment[col]='.';
tmp.Format("%02X ", *pTmp++);
prompt+=tmp;
}
comment[col]=0;
prompt+=" ";
prompt+=comment;
prompt+="\r\n";
m_HexStrArray.Add(prompt);
prompt.Empty();
}
//
if(PartRow!=0)
{
tmp.Format("%05X:", 8*rr);
prompt+=tmp;
for(int col = 0;col < PartRow; col++)
{
if((*pTmp>' ') && (*pTmp<'z')) comment[col]=*pTmp;
else comment[col]='.';
tmp.Format("%02X ", *pTmp++);
prompt+=tmp;
}
comment[col]=0;
while(col<16)
{// more spaces
prompt+=" ";//3
col++;
}
prompt+=" ";
prompt+=comment;
prompt+="\r\n";
m_HexStrArray.Add(prompt);
prompt.Empty();
}
//
return TRUE;
}
// ANSI To UNCODE转换
CString AnsiToUnicode(char * szAnsi, int len=0);
// ANSI To UNCODE转换
CString CStringProc::AnsiToUnicode(char * szAnsi, int len)
{
CString str;
// ansi to unicode
//预转换,得到所需空间的大小
int wcsLen;
if(len>0)
wcsLen=len;
else
wcsLen= ::MultiByteToWideChar(CP_ACP, NULL, szAnsi, strlen(szAnsi), NULL, 0);
//分配空间要给'\0'留个空间,MultiByteToWideChar不会给'\0'空间
wchar_t* wszString = new wchar_t[wcsLen + 1];
//转换
::MultiByteToWideChar(CP_ACP, NULL, szAnsi, strlen(szAnsi), wszString, wcsLen);
//最后加上'\0'
wszString[wcsLen] = '\0'; // UNICODE字串
str=wszString;
delete wszString;
return str;
}
调用此函数
CString P;
P=AnsiToUnicode(str);
GetDlgItem(IDC_EDIT1)->SetWindowText(P);