Progress bar with text

xiaoxiao2021-03-06  51

This is a class relating to the progress bar control. It can display the file name and percentage in the progress box, I want the reader to see when the software is installed. The most important feature of this class is to allow text to be displayed in the progress bar, as follows: void setShowText (Bool Bshow); You can set whether you can display text through this function. Settings text You can use CWnd :: SetWindowText, if you use the function setShowText (TRUE) to set the text, but you don't use CWnd :: SetWindowText to set the text you want to display, then this class will use the default settings Only the percentage of progress is displayed, and this is still paying attention. Since I am a rookie-level VC programming hand, I have not fully understood the content, that is, I haven't read the code, I hope the reader can read it and will be more beneficial.

Here is some of the functions of some of the functions, please laugh: Void setForeColour (ColorRef coL) Set Color Void SetBkcolour (ColorRef COL) in the Screens Setting the Platform Background Color Void SetTextForeColour (ColorRef COL) When the progress bar is not overwritten When the text, the color of the text void setTextBkcolour (ColorRef COL) When the progress bar covers text, the color corlorref getForeColour () gets the color corlorref getBkcolour () get the progress bar. CorlorRef getTextForeColour () When the progress bar when no cover text, color of the text obtained CORLORREF GetTextBkColour () when the progress bar overlay text, the text color is obtained following all code file // CPP file including H H the following documents are #if! defined (AFX_TEXTPROGRESSCTRL_H__4C78DBBE_EFB6_11D1_AB14_203E25000000__INCLUDED _) # define AFX_TEXTPROGRESSCTRL_H__4C78DBBE_EFB6_11D1_AB14_203E25000000__INCLUDED_ # if _MSC_VER> = 1000 # pragma once # endif // _MSC_VER> = 1000 // TextProgressCtrl.h: header file //// Written by Chris Maunder (chrismaunder@codeguru.com) // Copyright 1998./// CTextProgressCtrl WindowClass CtextProgressCtrl: Public CProgressCtrl {// ConstructionPublic: ctextprogressCtrl (); // attributespublic: // OperationSpublic: int SetPOS (INT N Pos); int StepIt (); void SetRange (int nLower, int nUpper); int OffsetPos (int nPos); int SetStep (int nStep); void SetForeColour (COLORREF col); void SetBkColour (COLORREF col); void SetTextForeColour (COLORREF ColorRef colorecolour (); colorref getBKCOLOUR (); colorref gettextforecolour (); colorref getTextBkcolour (); void setShowText (bool bshow);

// Overrides // ClassWizard generated virtual function overrides // {{AFX_VIRTUAL (CTextProgressCtrl) //}} AFX_VIRTUAL // Implementationpublic: virtual ~ CTextProgressCtrl (); // Generated message map functionsprotected: int m_nPos, m_nStepSize, m_nMax, m_nMin; CString m_strText; BOOL m_bShowText; int m_nBarWidth; COLORREF m_colFore, m_colBk, m_colTextFore, m_colTextBk; // {{aFX_MSG (CTextProgressCtrl) afx_msg BOOL OnEraseBkgnd (CDC * pDC); afx_msg void OnPaint (); afx_msg void OnSize (UINT nType, int cx, int cy); //}} aFX_MSG afx_msg LRESULT OnSetText (UINT, LPCTSTR szText); afx_msg LRESULT OnGetText (UINT cchTextMax, LPTSTR szText); DECLARE_MESSAGE_MAP ()}; /// {{AFX_INSERT_LOCATION}} // Microsoft Developer Studio will insert Additional Declarations Immediate Line. # endif //! defined (AFX_TextProgres SCTRL_H__4C78DBBE_EFB6_11D1_AB14_203E25000000__INCLUDED _) // The following is the CPP file // TextProgressCtrl.cpp: implementation file //// Written by Chris Maunder (chrismaunder@codeguru.com) // Copyright 1998.//// Modified: 26/05/98 Jeremy Davis, JMD @

jvf.co.uk// Added colour routines //// TextProgressCtrl is a drop-in replacement for the standard // CProgressCtrl that displays text in a progress control.//// This code may be used in compiled form in any way you desire. This // file may be redistributed by any means PROVIDING it is not sold for // profit without the authors written consent, and providing that this // notice and the authors name is included. If the source code in // this file is used in any commercial application then an email to // the me would be nice.//// This file is provided "as is" with no expressed or implied warranty.// The author accepts no liability if it causes any damage To Your // Computer, Causees Your Pet Cat Cat, Fall, Increases Baldness OR // Makes You Car Start Emitting Strange Noises When You Start It Up.//// Expect Bugs.// // Please Use and Enjoy. please lethaase Let ME KNOW OF ANY BUGS / MODS / IMPROVEMENTS // That You Have Found / Implement and I Will Fix / Incorporate THEM INTO this // File. #include "Stdafx.h" #include "TextProgressCtrl.h" #ifdef _DEBUG # define new DEBUG_NEW # undef THIS_FILEstatic char THIS_FILE [] = __FILE __; # endif # ifndef _MEMDC_H _ //// CMemDC - memory DC //// Author: Keith Rule // email: keithr@europa.com// Copyright 1996-1997, Keith rule /// May free use or modify this code provided this // Copyright is include in all derived version.//// history - 10 / 3/97 Fixed scrolling bug.// Added print support.//// This class implements a memory Device contextclass CMemDC: public CDC {public: // constructor sets up the memory DC CMemDC (CDC * pDC): CDC () { Assert (PDC! = Null); m_pdc = pdc; m_poldbitmap = null; m_bmemdc =

! PDC-> IsPrinting (); if (m_bMemDC) // Create a Memory DC {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 // Make a copy of the relevent parts of the current DC for printing {m_bPrinting = pDC-> m_bPrinting; m_hDC = pDC-> m_hDC ; m_hAttribDC = pDC-> m_hAttribDC;}} // Destructor copies the contents of the mem DC to the original DC ~ CMemDC () {if (m_bMemDC) {// Copy the offscreen bitmap onto the screen m_pDC-> BitBlt (m_rect. , m_rect.width (), m_rect.Height (), this, m_rect.left, m_rect.top, srccopy; // swap back the original bitmap. SelectObject (m_poldbitmap );} Else {// All we need to do is replace the DC with an illegal value, // this keeps us from accidently deleting the handles associated with // the CDC that was passed to the constructor m_hDC = m_hAttribDC = NULL.; }} // Allow usage as a pointer CMemDC * operator -> () {return this;} // Allow usage as a pointer operator CMemDC * () {return this;} private: CBitmap m_bitmap; // Offscreen bitmap CBitmap * m_pOldBitmap ; // bitmap Originally Found In CMEMDC CDC * m_pdc; // SAVES CDC Passed in Constructor CRECT M_RECT; // Rectangle of Drawing Area. BOOL M_BMEMDC;

// TRUE if CDC really is a Memory DC};. # Endif /// CTextProgressCtrlCTextProgressCtrl :: CTextProgressCtrl () {m_nPos = 0; m_nStepSize = 1; m_nMax = 100; m_nMin = 0; m_bShowText = TRUE; m_strText.Empty () ; m_colFore = :: GetSysColor (COLOR_HIGHLIGHT); m_colBk = :: GetSysColor (COLOR_WINDOW); m_colTextFore = :: GetSysColor (COLOR_HIGHLIGHT); m_colTextBk = :: GetSysColor (COLOR_WINDOW); m_nBarWidth = -1;} CTextProgressCtrl :: ~ CTextProgressCtrl () {} BEGIN_MESSAGE_MAP (CTextProgressCtrl, CProgressCtrl) // {{AFX_MSG_MAP (CTextProgressCtrl) ON_WM_ERASEBKGND () ON_WM_PAINT () ON_WM_SIZE () //}} AFX_MSG_MAP ON_MESSAGE (WM_SETTEXT, OnSetText) ON_MESSAGE (WM_GETTEXT, OnGetText) END_MESSAGE_MAP () /// CTextProgressCtrl message HandlerslResult ctextprogressCtrl :: OnsetText (uint, lpctstr sztext) {LRESULT results = default (); if ((! sztext && m_strtext.getlength ()) || (Sztext && (M_STRText ! = SzText))) {m_strText = szText; Invalidate ();} return result;} LRESULT CTextProgressCtrl :: OnGetText (UINT cchTextMax, LPTSTR szText) {if (_tcsncpy (szText, m_strText, cchTextMax)) return 0;! Else return min (cchTextMax, (UINT) m_strText.GetLength ());} BOOL CTextProgressCtrl :: OnEraseBkgnd (CDC * / * pDC * /) {return TRUE;} void CTextProgressCtrl :: OnSize (UINT nType, int cx, int cy) { CProgressCtrl :: OnSize (nType, cx, cy); m_nBarWidth = -1; // Force update if SetPos called} void CTextProgressCtrl :: OnPaint () {if (m_nMin> = m_nMax) return; CRect LeftRect, RightRect, ClientRect;

GetClientRect (ClientRect); Double Fraction = (Double) (M_NPOS - M_NMIN) / (m_nmax - m_nmin)); CPAINTDC PAINTDC (this); // Device Context for Painting CMEMDC DC (& PainTDC); // CPAINTDC DC (this); // device context for painting (if not double buffering) LeftRect = RightRect = ClientRect; LeftRect.right = LeftRect.left (int) ((LeftRect.right - LeftRect.left) * Fraction); dc.FillSolidRect (LeftRect, m_colFore); RightRect.left = LeftRect.right; dc.FillSolidRect (RightRect, m_colBk); if (m_bShowText) {CString str; if (m_strText.GetLength ()) str = m_strText; else str.Format ( "% D %%, (int)); dc.setbkmode (transparent); CRGN RGN; Rgn.createRectRgn (LeftRect.Right, LeftRect.bottom); dc.selectclipRgn & rgn); DC.SettextColor (m_coltextbk); DC.Drawtext (Str, ClientRect, DT_Center | DT_VCenter | DT_SINGLINE); RGN.DELETEOBJECT (); rgn.CreateRectRgn (RightRect.left, RightRect.top, RightRect.right, RightRect.bottom); dc.SelectClipRgn (& rgn); dc.SetTextColor (m_colTextFore); dc.DrawText (str, ClientRect, DT_CENTER | DT_VCENTER | DT_SINGLELINE); }} void CTextProgressCtrl :: SetForeColour (COLORREF col) {m_colFore = col;} void CTextProgressCtrl :: SetBkColour (COLORREF col) {m_colBk = col;} void CTextProgressCtrl :: SetTextForeColour (COLORREF col) {m_colTextFore = col;} void CTextProgressCtrl: : SetTextBkColour (COLORREF col) {m_colTextBk = col;} COLORREF CTextProgressCtrl :: GetForeColour () {return m_colFore;} COLORREF CTextProgressCtrl :: GetBkColour () {return m_colBk;

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

New Post(0)