VC to realize the waveform does not flicker dynamic drawing

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.