The waveform effect of the program running
In signal processing, it is usually necessary to display the real-time waveform of the acquisition signal. If you are drawing directly on the screen, there will be flicker, in order to overcome this problem, this article is the first in memory drawing, and then copied to the screen, so as to achieve dynamic drawing without blinking. The details are as follows:
2.1 First define the following private variables in the header file and place a picture control in the dialog resource
private:
CDC *pDC; //屏幕绘图设备
CDC memDC; //内存绘图设备
int m_High; //绘图起点
int m_Low; //绘图终点
int m_lCount[1024]; //数据存储数组
int m_now; //记录波形当前点
2.2 Initialize the variable in the implementation file and set the timer
BOOL CDrawTest::OnInitDialog()?
{
CDialog::OnInitDialog();
// TODO: Add extra initialization here
m_Low = 0;
m_High = 1024;
m_now =0;
SetTimer(1,100,NULL);
return TRUE; // return TRUE unless you set the focus to a control
// EXCEPTION: OCX Property Pages should return FALSE
}
2.3 Create a memory drawing device in the timer and call the drawing function to draw in the memory device, copy the diagram from the memory device to the screen after the drawing is finished
void Cdrawtest::ontimer (UINT nidevent)
{
Todo:add your message handler code here and/or call default
CRect rect;
Get a text box to draw coordinates
cwnd* pwnd = GetDlgItem (Idc_coord);
Get the window handle to the picture on the dialog box
Pwnd->getclientrect (&rect);
Pointer
PDC = Pwnd->getdc ();
Pwnd->invalidate ();
Pwnd->updatewindow ();
Memory drawing
CBitmap Membitmap;
cbitmap* poldbmp = NULL;
Creating a memory drawing device
Memdc.createcompatibledc (PDC);
Membitmap.createcompatiblebitmap (Pdc,rect.right,rect.bottom);
Poldbmp = Memdc.selectobject (&membitmap);
Memdc.bitblt (rect.left,rect.top,rect.right,rect.bottom,pdc,0,0,srccopy);
Custom drawing function, see source program in detail
Drawwave (&MEMDC);
Copy the memory drawing to the screen
Pdc->bitblt (rect.left,rect.top,rect.right,rect.bottom,&memdc,0,0,srccopy);
Memdc.selectobject (poldbmp);
Memdc.deletedc ();
Membitmap.deleteobject ();
Cdialog::ontimer (nidevent);
}
This article supporting source code