How to create a waveform display

zhaozj2021-02-11  188

1> Purpose: Create a waveform display 2> Steps: * Inherited a class from CWnd, including the four functions, respectively: uint setpos (uint npos), set location points; void setRange (uint nlower, uint Nupper), set the waveform height range; Plotting article void DrawBar (); update drawing void InvalidateCtrl (); overloaded virtual BOOL Create (LPCTSTR lpszClassName, LPCTSTR lpszWindowName, DWORD dwStyle, const RECT & rect, CWnd * pParentWnd, UINT nID, CCreateContext * pContext = NULL) Mapping the AFX_MSG Void onPaint () message function. * Define five variables uint m_nvertical; range minimum uint m_nlower; range maximum uint m_nupper; position uint m_npos; device CDC m_memdc; bitmap cbitmap m_bitmap; * Initialization data CADUIOSHOW :: Caduioshow () {file: // Initialization data 100, bottom 0. The start point is 0 m_npos = 0; m_nlower = 0; m_nupper = 100;}

* // The following registration application classes, if the style is set to the high window, when the window width is changed from the drawing the entire BOOL CAduioShow :: Create (LPCTSTR lpszClassName, LPCTSTR lpszWindowName, DWORD dwStyle, const RECT & rect, CWnd * pParentWnd, UINT nID, CCreateContext * PCONTEXT) {// Todo: Add Your Specialized Code: // The following registration class, style set to the high-grade window static cstring classname = afxregisterWndclass (CS_HREDRAW) if the window is high and wide change | CS_VREDRAW); return CWnd :: CreateEx (WS_EX_CLIENTEDGE | WS_EX_STATICEDGE, classname, NULL, dwStyle, rect.left, rect.top, rect.right-rect.left, rect.bottom-rect.top, pParentWnd-> GetSafeHwnd () , (HMENU) NID); file: // (HMENU) NID is the picture box ID in the program

}

* Set the dynamic position of the strobe strip and return to the initial location uint caduioshow :: setPos (uint npos) {file: // set the position maximum and minimum value if (npos> m_nupper) npos = m_nupper; if (NpOS

UINT NOLD = m_npos; m_npos = npos; file: // Draw a variable strip Drawbar (); invalidate () ;;

Return nold;

* Set the range of variable bars Void Caduioshow :: setRreg (uint nlower, uint Nupper) {m_nlower = nlower; m_nupper = NUPPER; INVALIDATECTRL ();} * Transform coordinate Void Caduioshow :: onpaint () {cpaintdddc DC (this); / / Device Context for Painting // Todo: Add Your Message Handler Code Here CRECT RCCLIENT; GetClientRect (rcclient);

IF (m_memdc.getsafehdc ()! = null) {dc.bitblt (0, rcclient.width (), rcclient.height (), & m_memdc, 0,0, srcopy;}

// do not call cWnd :: onpaint () for Painting Messages}

* Draw bar graph Void Caduioshow :: Drawbar () {uint nrange = m_nupper-m_nlower; cRect Reclient; getClientRect (Reclient);

IF (m_memdc.getsafehdc ()! = null) {m_memdc.bitblt (0, 0, reclient.width (), Reclient.Height (), & M_MEMDC, 4, 0, SRCCOPY;

CRECT RETOP (Reclient.right-4,0, Reclient.right-2, Reclient.Bottom); File: // Calculate Height Retop.top.top = ((FLOAT) ((M_NPOS-M_NLOWER) / NRANGE) * RECLIENT.HEIGHT ()); file: // Calculate the width of the bar chart CRECT RERTINT = Reclient; Right.Left = RERHT.Right-4; file: // Draw CBRUSH BKBRUSH (HS_HORIZONTAL, RGB (0,128,128)) ; M_memdc.fillRect (RGB (0,255,0)); m_memdc.FillRect (RETOP, & BBRUSH);

}

* Void CAduioShow :: InvalidateCtrl () {CClientDC dc (this); CRect reClient; GetClientRect (reClient); file: // invalid update if (m_MemDC.GetSafeHdc () == NULL) {m_MemDC.CreateCompatibleDC (& dc); m_Bitmap. CreateCompatibleBitmap (& dc, reClient.Width (), reClient.Height ()); m_MemDC.SelectObject (m_Bitmap); m_MemDC.SetBkColor (RGB (0,0,0)); CBrush bkBrush (HS_HORIZONTAL, RGB (0,128,0)) ; M_memdc.fillRect (Reclient, & bkbrush);} invalidateect (reclient);

}

转载请注明原文地址:https://www.9cbs.com/read-4503.html

New Post(0)