Can set the schedule of the scale

xiaoxiao2021-03-30  236

The software now to use graphics to display the size of the signal value, the easiest way to pass the serial port, which is not shown in the progress bar. But in the process of use, one problem is found, that is, there is no scale. If there is a unforgettable, the problem is resolved. If there is no unforgettable situation, I have to do DIY myself.

Since I didn't have a control before, I found a reference to the reference, so I found the code of the color gradual progress. This code is strictly in full, and the progress bar can only be slightly unable. After reading the color gradient force, I made a scaffolding feature control. Currently, this control I did has the following functions:

1, set the foreground color

2, set the background color

3, set there is no scale, scale position, scale quantity

4, set the progress bar with boundless box

5, set text display

The header file is as follows:

#if! defined (AFX_GRADIENTPROGRESSCTRL_H__91ECB8BC_A7DA_42EB_B2C5_37419D31B753__INCLUDED _) # define AFX_GRADIENTPROGRESSCTRL_H__91ECB8BC_A7DA_42EB_B2C5_37419D31B753__INCLUDED_ # endif

#if _MSC_VER> 1000 # prgma overce # endif //_MSC_VER> 1000

#if! defined (afX_MEMDC_H__A68B97E6_DDB4_4B4F_8A18_429844C3659C__INCluded _) # define afX_MEMDC_H__A68B97E6_DDB4_4B4F_8A18_429844C3659C__included_ # Endif

Class CMEMDC: PUBLIC CMEMDC: CMEMDC (CDC * PDC); cmemdc * Operator -> () {returnid;} Operator cmemdc * () {Return this;} Virtual ~ cmemdc (); private: cbitmap m_bitmap; cbitmap * M_PoldBitmap; CDC * m_pdc; crect m_rect; bool m_bmemdc;};

/// cscaleprogressctrl window

Class CscaleProgressCtrl: Public CProgressCtrl {// Constructionpublic: cscaleprogressctrl ();

// Set_function void SetTextColor (COLORREF color) {m_clrText = color;} // set the text color, the default is void SetBkColor (COLORREF color) {m_clrBkGround = color;} // set the background color progress bar void SetForeColor (COLORREF color) {m_FaceColor = Color;} // Set progress bar foreground color setShowFrame (BOOL frame) {m_frame = frame;} // Set whether to display progress strip // void setndColor {m_clrend = color;} // percent txt showed in the Progress void SetShowPercent (BOOL bShowPercent = TRUE) {m_bShowPercent = bShowPercent;} // whether to display the text // get_Function COLORREF GetTextColor (void) {return m_clrText;} COLORREF GetBkColor (void) {return m_clrBkGround;} COLORREF GetFaceColor (void) {return m_FaceColor;} // Attributespublic: int m_nLower; // setrange minimum int m_nUpper; // setrange maximum int m_nStep; // step int m_nCurrentPosition; // setpos value COLORREF m_FaceColor, m_clrBkGround, m_clrText; / / Foreground color, background color, text color variable BOOL M_BSHOWPERCENT; / / Whether to display text variables

Bool m_scaleline; // There is no scale int m_side; // Direction, such as 0 indicates that there is a scale on the left or on the upper side, 1 indicates the mark on the right or lower, and 3 means that both sides have an int m_scalenumber; // scale BOOL M_FRAME; // There is boundless box // OperationsPublic:

// Overrides // ClassWizard generated virtual function overrides // {{AFX_VIRTUAL (CSCaleProgressCtrl) //}} AFX_VIRTUAL

// ImplementationPublic: int setPos (INT NPOS); Void Straleline, Int Side, Int Scalenumber; // ScaleLine is a tick, false is no scale, True is the position of the scale // Side represents the position, When it is vertical, 0 indicates that there is a scale on the left. Quantity, straight from 3 to setRange maximum

int SetStep (int nStep); // setting step void SetRange (int nLower, int nUpper); virtual ~ CScaleProgressCtrl (); // Generated message map functionsprotected: void DrawGradient (CPaintDC * pDC, RECT & rectClient, const int & nMaxWidth) ; // Plug the progress bar when the progress bar is drawn Drawndup (CPAINTDC * PDC, Rect & RectClient, Const Int & Maxhigh); // Dropping // {{AFX_MSG (CscaleProgressCtrl) AFX_MSG Bool OneRaseBkGnd (CDC * PDC) AFX_MSG void onpaint (); //}} AFX_MSG

Declare_message_map ()

public: afx_msg int OnCreate (LPCREATESTRUCT lpCreateStruct); public: virtual BOOL Create (DWORD dwStyle, const RECT & rect, CWnd * pParentWnd, UINT nID); public: virtual BOOL CreateEx (DWORD dwExStyle, DWORD dwStyle, const RECT & rect, CWnd * pParentWnd , Uint NID); protected: Virtual Bool PrecreateWindow (CreateStruct & Cs); Virtual Void PRESUBCLASSWINDOW ();

The CPP file is as follows:

// ScaleProgressCtrl.cpp: importation file //

#include "stdafx.h" #include "scaleprogressctrl.h" #include "assert.h" // # include "memdc.h"

#ifdef _debug # undef this_filestatic char this_file [] = __ file __; # Define new debug_new # Endif

//// construction / destruction //

CMEMDC :: CMEMDC (CDC * PDC): CDC () {

ASSERT (PDC! = Null);

m_pDC = pDC; m_pOldBitmap = NULL; m_bMemDC = pDC-> IsPrinting ();! // if (m_bMemDC) {pDC-> GetClipBox (& m_rect); CreateCompatibleDC (pDC); m_bitmap.CreateCompatibleBitmap (pDC, m_rect.Width (), m_rect.height ()); m_poldbitmap = selectObject (& m_bitmap); setWindoworg (m_rect.left, m_rect.top);} else // Prepare print {m_bprinting = PDC-> m_bprinting; m_hdc = PDC-> ///BPRINTI m_hdc; m_hattribdc = pdc-> m_hattribdc;}

}

CMEMDC :: ~ cmemdc () {if (m_bmemdc) {m_pdc-> bitblt (m_rect.width (), m_rect.height (), m_rect.height (), this, m_rect.left, m_rect.top, srccopy ; SelectObject (m_poldbitmap);} else {m_hdc = m_hattribdc = null;}}

/// cscaleprogressctrl

CscaleProgressCtrl :: cscaleprogressCtrl () {m_nlower = 0; // setRANGE minimum m_nupper = 100; // setRange maximum m_ncurrentPosition = 0; // setpos value m_nstep = 10; // setstep value m_scaleline = false; // default No scale m_scalenumber = 10; // Default 10 scale line m_side = 0; // The default is the mark m_frame = true when the default is vertical, the left is m_frame = true; // Default Bless Box

// Initial Color of Show M_FaceColor = ColorRef (RGB (0, 0, 255)); // m_clrend = ColorRef (RGB (255, 0)); m_clrbkground = :: getSysColor (color_3dface); m_clrtext = RGB (255, 255, 255); // Default text color is white // not show word m_bshowpercent = false;}

CscaleProgressCtrl :: ~ cscaleprogressctrl () {}

BEGIN_MESSAGE_MAP (CScaleProgressCtrl, CProgressCtrl) // {{AFX_MSG_MAP (CScaleProgressCtrl) ON_WM_ERASEBKGND () ON_WM_PAINT () //}} AFX_MSG_MAP ON_WM_CREATE () END_MESSAGE_MAP ()

/// cscaleprogressctrl message handlers

void CScaleProgressCtrl :: SetRange (int nLower, int nUpper) {// This Function is to Set Range of the progress m_nLower = nLower; m_nUpper = nUpper; m_nCurrentPosition = nLower; CProgressCtrl :: SetRange (nLower, nUpper);}

INT CSCaleProgressCtrl :: setstep (int nstep) {m_nstep = nstep; return (CProgressCtrl :: setstep (nstep));}

BOOL CScaleProgressCtrl :: OnEraseBkgnd (CDC * pDC) {// TODO: Add your message handler code here and / or call default return TRUE; // CProgressCtrl :: OnEraseBkgnd (pDC);} void CScaleProgressCtrl :: DrawEndUp (CPaintDC * pDC, Rect & RectClient, Const Int & Maxhigh {Rect RectFill; // Display Area Float Fstep; // Each step of the Grand Brush; // Displayed Color Brush

CMEMDC MEMDC (PDC); CRECT A1, B1; if (m_scaleline == true) {if (m_side == 0) RectClient.Light = 5; if (m_side == 1) RectClient.Right- = 5; if (m_side = = 2) {RectClient.Left = 5; RectClient.right- = 5;} a1.top = RectClient.top; a1.right = RectClient.Bott; A1.BOTTOM = RectClient.bottom; a1.left = RectClient.Bottom; A1.LEFT = RectClient.beft- 5; b1.top = RectClient.top; b1.right = RectClient.Right 5; b1.bottom = RectClient.bittom; b1.left = RectClient.right;} int nsteps = ABS (m_nupper-m_nlower); fstep = FLOAT) (RectClient.top-RectClient.bottom) / (m_nupper-m_nlower); // Fill the customer area using the background color :: setRect (& RectFill, // below is the left upper left corner X of the filling rectangular area X, Y and lower right angle x, y RectClient.Left, // on the left X RectClient.top, RectClient.right, // Right X RectClient.bottom; // Right Y Verify (brush.createsolidbrush); MEMDC. FillRect (& rectFill, & brush); // fill background color VERIFY (brush.DeleteObject ()); if (m_ScaleLine == TRUE) {COLORREF colorside; colorside = :: GetSysColor (COLOR_3DFACE); VERIFY (brush.CreateSolidBrush (colorside)) ; MEMDC.FILLRECT (&) A1, & Brush); MEMDC.FILLRECT (& B1, & Brush); Verify (brush.deleteObject ());} // Draw Process Bar / / / // {:: SetRect (& RectFill, RectFill) .left, rectClient.bottom-m_nCurrentPosition * fStep, rectClient.right, rectClient.bottom); VERIFY (brush.CreateSolidBrush (m_FaceColor)); memDC.FillRect (& rectFill, & brush); VERIFY (brush.DeleteObject ()); if ( m_ScaleLine == TRUE) {COLORREF colorside; colorside = :: GetSysColor (COLOR_3DFACE); VERIFY (brush.CreateSolidBrush (colorside)); memDC.FillRect (& a1, & brush); memDC.FillRect (& b1, & brush);

Verify (brush.deleteObject ()); int m_step; m_step = (RectClient.bottom-RectClient.top-1) / m_scalenumber; // This is not -1 might have a scale not on the bottom or rightmost intimate INT Temp = ABS (RectClient.top-RectClient.bottom); for (int y = RectClient.bottom-1; y> = 0; y- = m_step) // Draw Tissue {IF (M_SIDE == 0) {MEMDC. Moveto (0, y); MEMDC.LINETO (5, y);} if (m_side == 1) {MEMDC.MOVETO (RectClient.Right, Y); MEMDC.LINETO (RectClient.Right 5, Y); IF (m_side == 2) {MEMDC.Moveto (0, y); MEMDC.LINETO (5, y); MEMDC.MOVETO (RectClient.right, Y); MEMDC.LineTo (RectClient.Right 5, Y); }} //} return;}} void CScaleProgressCtrl :: DrawGradient (CPaintDC * pDC, RECT & rectClient, const int & nMaxWidth) {RECT rectFill; // display region float fStep; // every step of the long web CBrush brush; // display Color painting CMEMDC MEMDC (PDC); CRECT A1, B1; IF (m_scaleline == true) {if (m_side == 0) RectClient.top = 5; if (m_side == 1) RectClient.bottom- = 5; IF (m_side == 2) {RectClient.top = 5; RectClient.bottom- = 5;} a1. TOP = RectClient.top-5; a1.let = RectClient.top; a1.right = RectClient.Right; b1.top = RectClient.Right; b1.right = RectClient.right; b1. Bottom = RectClient.bottom 5; b1.left = RectClient.Left;} int nsteps = ABS (m_nupper-m_nlower); // Total number fstep = (float) (ABS (RectClient.right-RectClient.LEFT) / (m_nupper-m_nlower; // Each step number // Fill customer area using background colors :: setRect (& RectFill, // below is the left upper left corner X, Y, Y, Y and lower right angle of the filling rectangular area x, y RectClient left, // 上 x RectClient.top, // On the left Y RectClient.right, // Right X RectClient.bottom);

// lower right Y VERIFY (brush.CreateSolidBrush (m_clrBkGround)); memDC.FillRect (& rectFill, & brush); // fill background color VERIFY (brush.DeleteObject ()); if (m_ScaleLine == TRUE) {COLORREF colorside; colorside = :: GetSysColor (COLOR_3DFACE); VERIFY (brush.CreateSolidBrush (colorside)); memDC.FillRect (& a1, & brush); memDC.FillRect (& b1, & brush); VERIFY (brush.DeleteObject ());} // process of drawing Article if (rectFill.right> = nMaxWidth) {:: SetRect (& rectFill, rectFill.left, rectClient.top, rectClient.left m_nCurrentPosition * fStep, rectClient.bottom); VERIFY (brush.CreateSolidBrush (m_FaceColor)); memDC. FillRect (& rectFill, & brush); VERIFY (brush.DeleteObject ()); if (m_ScaleLine == TRUE) {COLORREF colorside; colorside = :: GetSysColor (COLOR_3DFACE); VERIFY (brush.CreateSolidBrush (colorside)); memDC.FillRect ( & a1, & brush); MEMDC.FILLRECT (& B1, & Brush); Verify (brush.deleteObject ()); int m_step; m_step = (RectClient.right-RectClient.Left-1) / m_scalenumber; // Tightening Step Int Temp = ABS (RectClient.right-RectClient.Left); for (int x = 0; x <= Temp; x = m_step) // Draw Dragment {IF (M_SIDE == 0) {MEMDC.Moveto (x, 0); MEMDC.LINETO (X, 5);} if (m_side == 1) {MEMDC .MOVETO (X, RectClient.bottom); MEMDC.LINETO (X, RectClient.bottom 5);} if (m_side == 2) {MEMDC.MOVETO (x, 0); MEMDC.LINETO (X, 5); MEMDC.MOVETO (X, RectClient.bottom); MEMDC.LINETO (X, RectClient.bottom 5);}}} return

Void cscaleprogressCtrl :: onpaint () {if (! m_frame) {this-> modifystyleex (ws_ex_staticedge, 0); this-> invalidate (false); // These two sentences are the border of Progress and display} DWORD Y = this- > GetStyle (); y = y & 4; CPaintDC dc (this); // device context for painting CRect rectClient; GetClientRect (rectClient); float maxWidth ((float) m_nCurrentPosition / (float) m_nUpper * (float) rectClient.right); FLOAT MaxHigh (Float) m_ncurrentposition / (float) m_nupper * (float) RectClient.Bottom); // Draw IF (Y == 4) Drawndup (& DC, RectClient, (int) maxHigh); if (y == 0) DrawGradient (& DC, RectClient, (int)); // Displays process strip test text if (m_bshowpercent) {cstring percent; percent.format ("% D %%", (int) (100 * (float) m_ncurrentPosition / m_nupper )); // displays the percentage dc.SetTextColor current value (m_clrText); dc.SetBkMode (TRANSPARENT); dc.DrawText (percent, & rectClient, DT_VCENTER | DT_CENTER | DT_SINGLELINE);} // Do not call CProgressCtrl :: OnPaint ( .).

INT CSCaleProgressCtrl :: setpos (int NPOS) {// set the position of the progress m_ncurrentposition = npos; return (CPROGRESSCTRL :: setPos (NPOS));}

INT CSCaleProgressCtrl :: OnCreate (lpcreatestruct lpcreatestruct) {if (CPROGRESSCTRL :: OnCreate (lpcreateStruct) == -1) Return -1;

// Todo: Add your dedicated creation code here

Return 0;}

Bool CscaleProgressCtrl :: Create (DWORD DWSTYLE, Const Rect, uint NID) {// Todo: Add a private code and / or call base class

Return CProgressCtrl :: Create (DWStyle, Rect, PparentWnd, NID);

Bool CscaleProgressCtrl :: Createex (DWORD DWEXSTYLE, DWORD DWSTYLE, CONST RECT, CWND * PPARENTWND, UINT NID) {// Todo: Add special code and / or call base class

Return CProgressCtrl :: Createex (DwexStyle, DWStyle, Rect, PparentWnd, NID);

Bool CscaleProgressCtrl :: PrecreateWindow (CreateStruct & Cs) {// Todo: Add special code and / or call the base class Return CProgressCtrl :: PrecreateWindow (CS);

Void CscaleProgressCtrl :: PRESUBCLASSWINDOW () {// Todo: Add a special code and / or call the base class

CProgressCtrl :: PreSubclassWindow ();} void CScaleProgressCtrl :: SetShowScale (BOOL scaleline, int side, int scalenumber) {assert (scaleline == 0 || scaleline == 1); m_ScaleLine = scaleline; assert (scalenumber> 2 && scalenumber < m_nupper); m_scalenumber = scalenumber; assert (Side <3 && Side> = 0); m_side = side; return;}

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

New Post(0)