• <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>
            posts - 29,comments - 10,trackbacks - 0
            1、CProgressBar.h
            class CProgressBar : public CProgressCtrl
            {
            // Construction
            public:
                CProgressBar();
                CProgressBar(LPCTSTR strMessage, 
            int nSize=100int MaxValue=100
                    BOOL bSmooth
            =FALSE, int nPane=0);
                
            virtual ~CProgressBar();
                BOOL Create(LPCTSTR strMessage, 
            int nSize=100int MaxValue=100
                    BOOL bSmooth
            =FALSE, int nPane=0);
                
                
            //DECLARE_DYNCREATE(CProgressBar)

            // Attributes
            public:
                BOOL SetRange(
            int nLower, int nUpper, int nStep = 1);
                BOOL SetText(LPCTSTR strMessage);
                BOOL SetSize(
            int nSize);
                COLORREF SetBarColour(COLORREF clrBar);
                COLORREF SetBkColour(COLORREF clrBk);
                
            int  SetPos(int nPos);
                
            int  OffsetPos(int nPos);
                
            int  SetStep(int nStep);
                
            int  StepIt();
                
            void Clear();
            // Operations
            public:
                
            int        m_nSize;        // Percentage size of control
                int        m_nPane;        // ID of status bar pane progress bar is to appear in
                CString    m_strMessage;    // Message to display to left of control
                CString m_strPrevText;  // Previous text in status bar
                CRect    m_Rect;            // Dimensions of the whole thing
                
                CStatusBar 
            *GetStatusBar();
                BOOL Resize();
            // Overrides
                
            // ClassWizard generated virtual function overrides
                
            //{{AFX_VIRTUAL(CProgressBar)
                
            //}}AFX_VIRTUAL

            // Implementation
            public:

                
            // Generated message map functions
            protected:
                
            //{{AFX_MSG(CProgressBar)
                afx_msg BOOL OnEraseBkgnd(CDC* pDC);
                
            //}}AFX_MSG

                DECLARE_MESSAGE_MAP()
            };
            2、CProgressBar.cpp
            // ProgressBar.cpp : implementation file
            //

            #include 
            "stdafx.h"
            #include 
            "StateBar.h"
            #include 
            "ProgressBar.h"

            #ifdef _DEBUG
            #define new DEBUG_NEW
            #undef THIS_FILE
            static char THIS_FILE[] = __FILE__;
            #endif

            /////////////////////////////////////////////////////////////////////////////
            // CProgressBar

            CProgressBar::CProgressBar()
            {
                m_Rect.SetRect(
            0,0,0,0);
            }


            CProgressBar::CProgressBar(LPCTSTR strMessage, 
            int nSize/* =100 */int MaxValue/* =100 */, BOOL bSmooth/* =FALSE */int nPane/* =0 */)
            {
                Create(strMessage,nSize,MaxValue,bSmooth,nPane);
            }

            CProgressBar::
            ~CProgressBar()
            {
                Clear();
            }


            BEGIN_MESSAGE_MAP(CProgressBar, CProgressCtrl)
                
            //{{AFX_MSG_MAP(CProgressBar)
                ON_WM_ERASEBKGND()
                
            //}}AFX_MSG_MAP
            END_MESSAGE_MAP()

            /////////////////////////////////////////////////////////////////////////////
            // CProgressBar message handlers

            void CProgressBar::Clear()
            {
                
            if(!IsWindow(GetSafeHwnd()))
                    
            return;

                ModifyStyle(WS_VISIBLE,
            0);

                CString str;
                
            if(m_nPane==0)
                    str.LoadString(AFX_IDS_IDLEMESSAGE);
                
            else
                    str
            =m_strPrevText;

                CStatusBar
            * pStatusBar=GetStatusBar();
                
            if(pStatusBar)
                
            {
                    pStatusBar
            ->SetPaneText(m_nPane,str);
                    pStatusBar
            ->UpdateWindow();
                }

            }


            BOOL CProgressBar::Create(LPCTSTR strMessage, 
            int nSize/* =100 */int MaxValue/* =100 */, BOOL bSmooth/* =FALSE */int nPane/* =0 */)
            {
                BOOL bSuccess 
            = FALSE;

                CStatusBar 
            * pStatusBar = GetStatusBar();
                
            if(!pStatusBar)
                    
            return FALSE;

                DWORD dwStyle
            =WS_CHILD|WS_VISIBLE;
            #ifdef PBS_SMOOTH
                
            if(bSmooth)
                    dwStyle
            |=PBS_SMOOTH;
            #endif

                CRect PaneRect;
                pStatusBar
            ->GetItemRect(nPane,&PaneRect);

                bSuccess
            =CProgressCtrl::Create(dwStyle,PaneRect,pStatusBar,1);
                ASSERT(bSuccess);
                
            if(!bSuccess)
                    
            return FALSE;

                SetRange(
            0,MaxValue);
                SetStep(
            1);

                m_strMessage
            =strMessage;
                m_nPane
            =nPane;
                m_nSize
            =nSize;
                m_strPrevText
            =pStatusBar->GetPaneText(m_nPane);

                Resize();

                
            return TRUE;
            }


            CStatusBar
            * CProgressBar::GetStatusBar()
            {
                CWnd 
            *pMainWnd = AfxGetMainWnd();
                
            //主窗口指針。多文檔、單文檔返回的是CMainFrame指針,對話框的是主對話框的CDialog指針 

                
            if (!pMainWnd)
                    
            return NULL;
                
                
            // If main window is a frame window, use normal methods
                if (pMainWnd->IsKindOf(RUNTIME_CLASS(CFrameWnd)))//如果對象對應于該類
                {
                    CWnd
            * pMessageBar = ((CFrameWnd*)pMainWnd)->GetMessageBar();
                    
            return DYNAMIC_DOWNCAST(CStatusBar, pMessageBar);
                }

                
            // otherwise traverse children to try and find the status bar
                else
                    
            return DYNAMIC_DOWNCAST(CStatusBar, 
                    pMainWnd
            ->GetDescendantWindow(AFX_IDW_STATUS_BAR));
            }


            BOOL CProgressBar::SetText(LPCTSTR strMessage)

                m_strMessage 
            = strMessage; 
                
            return Resize(); 
            }


            BOOL CProgressBar::SetSize(
            int nSize)
            {
                m_nSize 
            = nSize; 
                
            return Resize();
            }


            COLORREF CProgressBar::SetBarColour(COLORREF clrBar)
            {
            #ifdef PBM_SETBKCOLOR
                
            if (!IsWindow(GetSafeHwnd()))
                      
            return CLR_DEFAULT;

                
            return SendMessage(PBM_SETBARCOLOR, 0, (LPARAM) clrBar);
            #else
                UNUSED(clrBar);
                
            return CLR_DEFAULT;
            #endif
            }


            COLORREF CProgressBar::SetBkColour(COLORREF clrBk)
            {
            #ifdef PBM_SETBKCOLOR
                
            if (!IsWindow(GetSafeHwnd()))
                    
            return CLR_DEFAULT;

                
            return SendMessage(PBM_SETBKCOLOR, 0, (LPARAM) clrBk);
            #else
                UNUSED(clrBk);
                
            return CLR_DEFAULT;
            #endif
            }


            BOOL CProgressBar::SetRange(
            int nLower, int nUpper, int nStep /* = 1 */)    
            {     
                
            if (!IsWindow(GetSafeHwnd()))
                    
            return FALSE;

                
            // To take advantage of the Extended Range Values we use the PBM_SETRANGE32
                
            // message intead of calling CProgressCtrl::SetRange directly. If this is
                
            // being compiled under something less than VC 5.0, the necessary defines
                
            // may not be available.

            #ifdef PBM_SETRANGE32
                ASSERT(
            -0x7FFFFFFF <= nLower && nLower <= 0x7FFFFFFF);
                ASSERT(
            -0x7FFFFFFF <= nUpper && nUpper <= 0x7FFFFFFF);
                SendMessage(PBM_SETRANGE32, (WPARAM) nLower, (LPARAM) nUpper);
            #else
                ASSERT(
            0 <= nLower && nLower <= 65535);
                ASSERT(
            0 <= nUpper && nUpper <= 65535);
                CProgressCtrl::SetRange(nLower, nUpper);
            #endif
                
                CProgressCtrl::SetStep(nStep);
                
            return TRUE;
            }


            int CProgressBar::SetPos(int nPos)       
            {
                
            if (!IsWindow(GetSafeHwnd()))
                    
            return 0;

            #ifdef PBM_SETRANGE32
                ASSERT(
            -0x7FFFFFFF <= nPos && nPos <= 0x7FFFFFFF);
            #else
                ASSERT(
            0 <= nPos && nPos <= 65535);
            #endif

                ModifyStyle(
            0,WS_VISIBLE);
                
            return CProgressCtrl::SetPos(nPos);
            }


            int CProgressBar::OffsetPos(int nPos) 

                
            if (!IsWindow(GetSafeHwnd()))
                    
            return 0;

                ModifyStyle(
            0,WS_VISIBLE);
                
            return CProgressCtrl::OffsetPos(nPos);
            }


            int CProgressBar::SetStep(int nStep)

                
            if (!IsWindow(GetSafeHwnd()))
                    
            return 0;

                ModifyStyle(
            0,WS_VISIBLE);
                
            return CProgressCtrl::SetStep(nStep);     
            }


            int CProgressBar::StepIt()             

                
            if (!IsWindow(GetSafeHwnd()))
                    
            return 0;

                ModifyStyle(
            0,WS_VISIBLE);
                
            return CProgressCtrl::StepIt();    
            }


            BOOL CProgressBar::Resize() 
            {
                
            if (!IsWindow(GetSafeHwnd()))
                
            //IsWindow:該函數確定給定的窗口句柄是否識別一個已存在的窗口。
                
            //當我們想得到一個窗口對象(CWnd的派生對象)指針的句柄(HWND)時,最安全的方法是使用GetSafeHwnd()函數
                    return FALSE;

                CStatusBar 
            *pStatusBar = GetStatusBar();
                
            if (!pStatusBar)
                    
            return FALSE;

                
            // Redraw the window text
                if (IsWindowVisible())//該函數獲得給定窗口的可視狀態
                {
                    pStatusBar
            ->SetPaneText(m_nPane, m_strMessage);//設置StatusBar的文本
                    pStatusBar->UpdateWindow();
                }


                
            // Calculate how much space the text takes up
                CClientDC dc(pStatusBar);
                CFont 
            *pOldFont = dc.SelectObject(pStatusBar->GetFont());
                CSize size 
            = dc.GetTextExtent(m_strMessage);
                
            //使用該函數獲得所選字體中指定字符串的高度和寬度
                int margin = dc.GetTextExtent(_T(" ")).cx * 2;        // Text margin
                dc.SelectObject(pOldFont);

                
            // Now calculate the rectangle in which we will draw the progress bar
                CRect rc;
                pStatusBar
            ->GetItemRect(m_nPane, rc);

                
            // Position left of progress bar after text and right of progress bar
                
            // to requested percentage of status bar pane
                if (!m_strMessage.IsEmpty())
                    rc.left 
            += (size.cx + 2*margin);
                rc.right 
            -= (rc.right - rc.left) * (100 - m_nSize) / 100;

                
            if (rc.right < rc.left) rc.right = rc.left;
                
                
            // Leave a litle vertical margin (10%) between the top and bottom of the bar
                int Height = rc.bottom - rc.top;
                rc.bottom 
            -= Height/10;
                rc.top      
            += Height/10;

                
            // If the window size has changed, resize the window
                if (rc != m_Rect)
                
            {
                    MoveWindow(
            &rc);
                    m_Rect 
            = rc;
                }


                
            return TRUE;
            }


            BOOL CProgressBar::OnEraseBkgnd(CDC
            * pDC) 
            {
                    Resize();
                
            return CProgressCtrl::OnEraseBkgnd(pDC);
            }
            3、關于CProgressBar類的簡單應用
            成員函數 說明
            BOOL Success() 用于確定該類的構造是否成功
            COLORREF SetBarColour(COLORREF clrBar) 設置進度條的填充色
            COLORREF SetBkColour(COLORREF clrBar) 設置進度條的背景色
            int SetPos(int nPos) 把進度條的當前位置設置為指定的值并重繪新位置
            int OffsetPos(int nPos) 通過在當前位置基礎上加上由nPos指定的值,并使進度條控件的當前位置向前移動,然后重繪進度條,以反映新的位置
            int SetStep(int nStep) 設置進度條控件的步長增量(和StepIt函數一起使用)。在CProgressBar創建時,這個值默認為1
            int StepIt() 按通過SetStep函數指定的量使進度條的當前位置向前移動
            void Clear() 清除進度條
            void SetRange(int nLower,int nUpper,int nStep=1) 設置低限、高限以及步長值
            void SetText(LPCTSTR strMessage) 指定與進度條控件一起出現的文本消息,通常類似于“x%”,其中,x表示進度條的當前位置
            void SetSize(int nSize) 設置進度條的水平大小

            void CMainFrame::OnSmooth() 
            {
                
            // TODO: Add your command handler code here
                CProgressBar bar(_T("Progress"), 4010000,TRUE);
                
                
            for (int i = 0; i < 10000; i++) {
                    
                    CString str;
                    str.Format(
            "%d%% complete", i*100/10000);
                    bar.SetText(str);
                    
                    bar.StepIt();
                    PeekAndPump();
                }    
            }

            void CMainFrame::OnNsmooth() 
            {
                
            // TODO: Add your command handler code here
                CProgressBar bar(_T("Progress"), 4010000);
                
                
            for (int i = 0; i < 10000; i++) {
                    
                    CString str;
                    str.Format(
            "%d%% complete", i*100/10000);
                    bar.SetText(str);
                    
                    bar.StepIt();
                    PeekAndPump();
                }    
            }
            1)CProgressBar bar(_T("Progress"), 4010000,TRUE);創建一個進度條,Progress為其開始的文本,40表示進度條的大小,10000是進度條的最大值,TRUE表示是否平滑。
            2)  str.Format("%d%% complete", i*100/10000);bar.SetText(str);設置進度條前面的文本,表示進度讀條的百分比
            3)PeekAndPump();加入該函數則進度條滾動時可以與窗口進行交互(比如改變窗口大小)
            posted on 2009-07-03 20:18 The_Moment 閱讀(1992) 評論(0)  編輯 收藏 引用 所屬分類: VC實踐
            久久青草国产手机看片福利盒子| 久久精品aⅴ无码中文字字幕不卡 久久精品aⅴ无码中文字字幕重口 | 91亚洲国产成人久久精品网址| 久久精品国产亚洲av麻豆色欲| 亚洲国产精品综合久久网络| 亚洲国产天堂久久综合| 国内精品久久久久久久coent| 久久99精品久久久久久秒播| 99久久精品九九亚洲精品| 国产精自产拍久久久久久蜜| 久久午夜综合久久| 无码人妻久久久一区二区三区 | 久久AAAA片一区二区| 久久久久久国产精品无码下载 | 久久精品国产亚洲Aⅴ香蕉| 99久久精品国产一区二区| 国产99久久九九精品无码| 国产999精品久久久久久| 人人狠狠综合久久亚洲| 亚洲国产精品一区二区久久hs| 亚洲精品无码久久千人斩| 久久偷看各类wc女厕嘘嘘| 污污内射久久一区二区欧美日韩| 久久免费大片| 国产精品国色综合久久| 三级韩国一区久久二区综合| 精品久久久久久久久免费影院| 国产精品欧美久久久天天影视| 青青青青久久精品国产h久久精品五福影院1421| 青青草原综合久久| 久久国内免费视频| 久久天天躁狠狠躁夜夜不卡| 久久午夜免费视频| 久久亚洲综合色一区二区三区| 亚洲国产精品一区二区三区久久| 久久精品中文闷骚内射| 国产91久久综合| 国内精品久久久久伊人av| 性高朝久久久久久久久久| 国产精品久久久亚洲| 中文字幕久久精品|