VC implements non-blinking Dynamic Waveform Drawing

Source: Internet
Author: User

I. waveform effect during program running

 

2. in signal processing, the Real-Time Waveform of the collected signal is usually displayed. If you directly draw a dynamic graph on the screen, it will flash. To overcome this problem, we will first draw the graph in the memory and then copy it to the screen, so as to achieve dynamic drawing without flashing. 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 box resource

PRIVATE:

CDC * PDC; // screen plotting Device

CDC memdc; // memory Drawing Device

Int m_high; // Drawing start point

Int m_low; // drawing end point

Int m_lcount [1024]; // data storage array

Int m_now; // record the current waveform point

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 shold return false

}

2.3 create a memory drawing device in the timer and call the drawing function to draw the device in the memory. After the drawing is completed, copy the image in the memory device to the screen.

Void cdrawtest: ontimer (uint nidevent)

{

// Todo: add your message handler code here and/or call default

Crect rect;

// Retrieve the text box for drawing coordinates

Cwnd * pwnd = getdlgitem (idc_coord );

// Obtain the picture window handle in the dialog box

Pwnd-> getclientrect (& rect );

// Pointer

PDC = pwnd-> getdc ();

Pwnd-> invalidate ();

Pwnd-> updatewindow ();

// Memory plotting

Cbitmap membitmap;

Cbitmap * poldbmp = NULL;

// Create 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, srccopy );

// Customize the plotting function. For details, see the source program.

Drawwave (& memdc );

// Copy the memory drawing to the screen

PDC-> bitblt (rect. Left, rect. Top, rect. Right, rect. Bottom, & memdc, 0, srccopy );

Memdc. SelectObject (poldbmp );

Memdc. deletedc ();

Membitmap. deleteobject ();

Cdialog: ontimer (nidevent );

}

From http://c.chinaitlab.com/vc/917462.html

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.