Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members  

progressbar.cpp

Go to the documentation of this file.
00001 #include "stdafx.h"
00002 #include "progressbar.h"
00003 
00004 
00005 #ifdef _DEBUG
00006 #define new DEBUG_NEW
00007 #undef THIS_FILE
00008 static char THIS_FILE[] = __FILE__;
00009 #endif
00010 
00011 
00012 
00013 IMPLEMENT_DYNAMIC(CProgStatusBar, CStatusBar)
00014 BEGIN_MESSAGE_MAP(CProgStatusBar, CStatusBar)
00015         ON_WM_CREATE()
00016         ON_WM_SIZE()
00017 END_MESSAGE_MAP()
00018 
00019 CProgStatusBar::CProgStatusBar()
00020 {
00021 }
00022 
00023 CProgStatusBar::~CProgStatusBar()
00024 {
00025 }
00026 
00028 // Status bar created: create progress bar too.
00029 //
00030 int CProgStatusBar::OnCreate(LPCREATESTRUCT lpcs)
00031 {
00032         lpcs->style |= WS_CLIPCHILDREN;
00033         VERIFY(CStatusBar::OnCreate(lpcs) == 0);
00034         VERIFY(m_wndProgBar.Create(WS_CHILD, CRect(), this, 1));
00035         m_wndProgBar.SetRange(0,100);
00036         return 0;
00037 }
00038 
00040 // Status bar was sized: adjust size of progress bar to same as first
00041 // pane (ready message). Note that the progress bar may or may not be
00042 // visible.
00043 //
00044 void CProgStatusBar::OnSize(UINT nType, int cx, int cy)
00045 {
00046         CStatusBar::OnSize(nType, cx, cy); // call base class
00047         CRect rc;                                                                 // rectangle 
00048         GetItemRect(0, &rc);                                      // item 0 = first pane, "ready" message
00049         m_wndProgBar.MoveWindow(&rc,FALSE);// move progress bar
00050 }
00051 
00053 // Set progress bar position. pct is an integer from 0 to 100:
00054 //
00055 //  0 = hide progress bar and display ready message (done);
00056 // >0 = (assemed 0-100) set progress bar position
00057 //
00058 // You should call this from your main frame to update progress.
00059 // (See Mainfrm.cpp)
00060 //
00061 void CProgStatusBar::OnProgress(UINT udPos)
00062 {
00063         CProgressCtrl& pc = m_wndProgBar;
00064         DWORD dwOldStyle = pc.GetStyle();
00065         DWORD dwNewStyle = dwOldStyle;
00066         if (udPos > 0)
00067                 // positive progress: show prog bar
00068                 dwNewStyle |= WS_VISIBLE;
00069         else
00070                 // prog <= 0: hide prog bar
00071                 dwNewStyle &= ~WS_VISIBLE;
00072 
00073         if (dwNewStyle != dwOldStyle) {
00074                 // change state of hide/show
00075                 SetWindowText(NULL);                                                                                    // clear old text
00076                 SetWindowLong(pc.m_hWnd, GWL_STYLE, dwNewStyle);        // change style
00077         }
00078 
00079         // set progress bar position
00080         pc.SetPos(udPos);
00081         if (udPos == 0)
00082                 // display MFC idle (ready) message.
00083                 GetParent()->PostMessage(WM_SETMESSAGESTRING, AFX_IDS_IDLEMESSAGE);
00084 }
00085 
00086 
00087 void CProgStatusBar::OnProgressMinMax(int minPos, int maxPos) {
00088         m_wndProgBar.SetPos(0);
00089         m_wndProgBar.SetRange(minPos, maxPos);
00090 }

Generated on Thu Jan 30 21:35:43 2003 for 3DVis by doxygen1.3-rc2