15,979
社区成员
发帖
与我相关
我的任务
分享
void CMfcdocView::OnDraw(CDC* pDC)
{
CMfcdocDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
// TODO: add draw code for native data here
pDC->TextOut(0,0,myStr);//随着程序的运行,myStr变量越来越大,不利于程序稳定
}
void CMfcdocView::OnComm()
{
int inCount;
CString str;
VARIANT input;
BYTE rxdata[1024];
long len,k,i=0;
COleSafeArray safearray;
CByteArray Array;
switch(myComm.GetCommEvent())
{
case 2:
{
inCount=myComm.GetInBufferCount();
input=myComm.GetInput();
safearray=input;
len=safearray.GetOneDimSize();
for (k=0;k<len;k++)
{
safearray.GetElement(&k,rxdata+k);
if(rxdata[k]=='\n')
{
myStr+="\r\n";
}
else
{
str.Format(_T("%c"),rxdata[k]);
myStr+=str;
}
}
//MessageBox(myStr);
//;
Invalidate();
break;
}
default:
break;
}
}
CListBox list;
// 列表框的获取代码就不写了, 主要是写怎么按顺序插入数据
int nIndex = 0;
for (int i = 0; i < 100; i++)
{
TCHAR szValue[128];
::wsprintf(szValue, L"Test%d", i + 1);
nIndex = list.InsertString(nIndex, szValue);
}
void GetDrawMetrics(CDC* pDC, CFont* pFont, int* pCharWidth, int* pCharHeight)
{
// retrieve title font
CFont* pOldFont = pDC->SelectObject(pFont);
TEXTMETRIC tm;
pDC->GetTextMetrics(&tm);
// get average character width and title bar height
*pCharWidth = tm.tmAveCharWidth;
*pCharHeight = tm.tmHeight + tm.tmExternalLeading;
pDC->SelectObject(pOldFont);
}