• <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>

            為生存而奔跑

               :: 首頁 :: 聯系 :: 聚合  :: 管理
              271 Posts :: 0 Stories :: 58 Comments :: 0 Trackbacks

            留言簿(5)

            我參與的團隊

            搜索

            •  

            積分與排名

            • 積分 - 328615
            • 排名 - 74

            最新評論

            閱讀排行榜

            評論排行榜

            CLongOperation is a class designed to give visual feedback for long-lasting operations. It has support for:

            • Displaying a wait cursor
            • Showing a text in the status bar
            • Displaying a progress bar in a dynamically created status bar pane

            We can use in the following 3 ways:

            1、In the simplest case, this class can be used as a replacement for MFC's CWaitCursor:

            	CLongOperation wait;
            // some hard work going here...

            2、To display some textual progress information in the status bar:

            	CLongOperation wait;
            wait.SetText("Pass 1");
            // ...
            wait.SetText("Pass 2");
            // ...

            3、To display a progress bar in the status bar:

            	CLongOperation wait;
            for (int i = 1; i < 100; i++)
            {
            wait.Step(i);
            // ...do something.
            }
            wait.Stop();
            When using this,我們必須把項目的字符集改為使用多字節符集,IDS_PLEASE_WAIT是一個字符串資源
            ///////////////////////////////////////////////////////////////// // LongOperation.h // (c) 1997, Klaus Gütter class CLongOperation : public CObject { public: // IDS_PLEASE_WAIT is a string resource ID for the default text, // e.g. "Please wait..." CLongOperation(UINT nIDText = IDS_PLEASE_WAIT, bool bStart = true); CLongOperation(LPCTSTR lpszText, bool bStart = true); ~CLongOperation(); void Start(); void Stop(); void Step(int nPercentage = -1); void SetText(LPCTSTR lpszText); protected: CString m_strText; bool m_bStarted; HWND m_hwndProgress; void CreateProgressControl(); }; ///////////////////////////////////////////////////////////////// // LongOperation.cpp // (c) 1997, Klaus Gütter #include "stdafx.h" #include <afxpriv.h> // defines WM_SETMESSAGESTRING #include "LongOperation.h" #ifdef _DEBUG #undef THIS_FILE #define new DEBUG_NEW static char BASED_CODE THIS_FILE[] = __FILE__; #endif CLongOperation::CLongOperation(UINT nIDText, bool bStart) : m_bStarted(false) , m_hwndProgress(NULL) { VERIFY(m_strText.LoadString(nIDText)); if (bStart) Start(); } CLongOperation::CLongOperation(LPCTSTR lpszText, bool bStart) : m_strText(lpszText) , m_bStarted(false) , m_hwndProgress(NULL) { if (bStart) Start(); } CLongOperation::~CLongOperation() { if (m_bStarted) Stop(); } void CLongOperation::Start() { if (m_bStarted) Stop(); // display text in the status bar CWnd* pMainWnd = ::AfxGetMainWnd(); if (pMainWnd) pMainWnd->SendMessage(WM_SETMESSAGESTRING, 0, (LPARAM)(LPCTSTR)m_strText); // switch on wait cursor ::AfxGetApp()->BeginWaitCursor(); m_bStarted = true; } void CLongOperation::Stop() { if (!m_bStarted) return; if (m_hwndProgress) { // clean up and destroy progress bar CStatusBar* pStatusBar = DYNAMIC_DOWNCAST(CStatusBar, CWnd::FromHandle(::GetParent(m_hwndProgress))); ASSERT_VALID(pStatusBar); ::DestroyWindow(m_hwndProgress); m_hwndProgress = NULL; // remove progress bar pane int anPart[32]; int nParts = pStatusBar->GetStatusBarCtrl().GetParts(31, anPart); nParts--; pStatusBar->GetStatusBarCtrl().SetParts(nParts, anPart+1); } // switch back to standard text in the status bar CWnd* pMainWnd = ::AfxGetMainWnd(); if (pMainWnd) pMainWnd->SendMessage(WM_SETMESSAGESTRING, AFX_IDS_IDLEMESSAGE, 0); // switch off wait cursor ::AfxGetApp()->EndWaitCursor(); m_bStarted = false; } void CLongOperation::Step(int nPercentage) { if (!m_bStarted) Start(); ::AfxGetApp()->RestoreWaitCursor(); if (nPercentage >= 0) { ASSERT(nPercentage <= 100); // create or update a progress control in the status bar if (m_hwndProgress == NULL) CreateProgressControl(); if (m_hwndProgress) ::SendMessage(m_hwndProgress, PBM_SETPOS, (WPARAM)nPercentage, 0); } } void CLongOperation::SetText(LPCTSTR lpszText) { m_strText = lpszText; CWnd* pMainWnd = ::AfxGetMainWnd(); if (pMainWnd) pMainWnd->SendMessage(WM_SETMESSAGESTRING, 0, (LPARAM)(LPCTSTR)m_strText); } void CLongOperation::CreateProgressControl() { ASSERT(m_hwndProgress == NULL); // find status bar CWnd* pMainWnd = ::AfxGetMainWnd(); if (pMainWnd == NULL) return; CStatusBar* pStatusBar = DYNAMIC_DOWNCAST(CStatusBar, pMainWnd->GetDescendantWindow(AFX_IDW_STATUS_BAR, TRUE)); if (pStatusBar == NULL || pStatusBar->m_hWnd == NULL) return; CRect rc; // this will be the location for the progress bar pane pStatusBar->GetItemRect(0, rc); if (!m_strText.IsEmpty()) { // adjust so that the text in the leftmost pane will not be covered CClientDC dc(pStatusBar); dc.SelectObject(pStatusBar->GetFont()); CSize sz = dc.GetTextExtent(m_strText); TEXTMETRIC tm; dc.GetTextMetrics(&tm); rc.left += sz.cx + 2*tm.tmAveCharWidth; } int cx = rc.Width(); if (cx < 20) { // no sense in displaying such a small progress bar TRACE0("ProgressDisplay would be too small\n"); return; } else if (cx > 200) { // arbitrarily limiting progress bar width to 200 pixel cx = 200; rc.left = rc.right - cx; } // add a pane between the text and the currently leftmost pane int anPart[32]; int nParts = pStatusBar->GetStatusBarCtrl().GetParts(31, anPart+1); anPart[0] = rc.left; nParts++; pStatusBar->GetStatusBarCtrl().SetParts(nParts, anPart); pStatusBar->GetStatusBarCtrl().GetRect(1, rc); // create progress bar control m_hwndProgress = ::CreateWindow(PROGRESS_CLASS, "", WS_CHILD | WS_VISIBLE, rc.left, rc.top, rc.Width(), rc.Height(), pStatusBar->m_hWnd, (HMENU)1, AfxGetInstanceHandle(), NULL); pStatusBar->UpdateWindow(); }
            posted on 2009-07-24 11:15 baby-fly 閱讀(218) 評論(0)  編輯 收藏 引用 所屬分類: MFC
            国产精品欧美亚洲韩国日本久久| 久久久久国产精品嫩草影院| 久久精品国产亚洲AV影院 | 国产91久久精品一区二区| AV色综合久久天堂AV色综合在 | 亚洲精品乱码久久久久久蜜桃不卡| 久久久www免费人成精品| 97久久国产亚洲精品超碰热| 国产国产成人久久精品| 亚洲国产小视频精品久久久三级| 综合久久国产九一剧情麻豆 | 一级做a爰片久久毛片看看| 人妻无码久久一区二区三区免费| 亚洲综合婷婷久久| 久久精品九九亚洲精品| 无码国内精品久久人妻麻豆按摩| 久久综合九色综合精品| 久久精品国产2020| 久久久亚洲精品蜜桃臀| 国产午夜精品理论片久久影视| 欧美伊人久久大香线蕉综合| 久久精品国产精品亜洲毛片| 国产精品99久久99久久久| 97精品伊人久久大香线蕉| 女同久久| 亚洲精品综合久久| 精品人妻伦九区久久AAA片69| 国产成人精品白浆久久69| 日韩精品无码久久久久久| 99久久国产宗和精品1上映 | 7777久久亚洲中文字幕| 久久久婷婷五月亚洲97号色| 色妞色综合久久夜夜| 区亚洲欧美一级久久精品亚洲精品成人网久久久久 | 99久久免费国产精品| 免费国产99久久久香蕉| 久久精品国产亚洲AV无码娇色| 青青草原综合久久大伊人| 久久无码AV中文出轨人妻| 久久频这里精品99香蕉久| 久久亚洲国产成人影院|