Popup progress window

Download source files (5 Kb) or a Sample project (38 Kb)

There are many occasions where it's nice to have a poopup window that shows the progress of a lengthy operation. Incorporating a dialog resource with a progress control and cancel button, then linking up the control messages for every project you wish to have the progress window can get monotonous and messy.

The class CProgressWnd is a simple drop in window that contains a progress control, a cancel button and a text area for messages. The text area can display 4 lines of text as default, although this can be changed using CProgressWnd::SetWindowSize() (below)

Construction

    CProgressWnd(); 
    CProgressWnd(CWnd* pParent, LPCTSTR strTitle, BOOL bSmooth=FALSE);
    BOOL Create(CWnd* pParent, LPCTSTR strTitle, BOOL bSmooth=FALSE);

Construction is either via the constructor or a two-step process using the constructor and the "Create" function. "pParent" is the parent of the progress window, "strTitle" is the window caption title. "bSmooth" will only be effective if you have the header files and commctrl32.dll from IE 3.0 or above (no problems for MS VC 5.0). It specifies whether the progress bar will be smooth or chunky.

Operations

    BOOL GoModal(LPCTSTR strTitle = _T("Progress"), BOOL bSmooth=FALSE); // Make window modal

    int  SetPos(int nPos);              // Same as CProgressCtrl
    int  OffsetPos(int nPos);           // Same as CProgressCtrl
    int  SetStep(int nStep);            // Same as CProgressCtrl
    int  StepIt();                      // Same as CProgressCtrl
    void SetRange(int nLower, int nUpper, int nStep = 1);
                                        // Set min, max and step size

    void Hide();                        // Hide the window
    void Show();                        // Show the window
    void Clear();                       // Clear the text and reset the progress bar
    void SetText(LPCTSTR fmt, ...);     // Set the text in the text area

    BOOL Cancelled()                    // Has the cancel button been pressed?

    void SetWindowSize(int nNumTextLines, int nWindowWidth = 390);
                                        // Sets the size of the window according to
                                        // the number of text lines specifed and the
                                        // desired window size in pixels.

    void PeekAndPump(BOOL bCancelOnESCkey = TRUE);  
                                        // Message pumping, with options of allowing
                                        // Cancel on ESC key.  

The PeekAndPump function allows messages to be pumped during long operations. The first parameter allows the window to be cancelled by pressing the ESC key.

You can also make the window modal by creating the window and calling GoModal(). This will disable the main window, and re-enable the main window when this window is destroyed. See the demo app for example code.

The window will also store and restore its position to and from the registry between incantations.

To use the window, just do something like:

    CProgressWnd wndProgress(this, "Progress");

    // wndProgress.GoModal(); // Call this if you want a modal window
    wndProgress.SetRange(0,5000);
    wndProgress.SetText("Processing...");         

    for (int i = 0; i < 5000; i++) {
        wndProgress.StepIt();
        wndProgress.PeekAndPump();

        if (wndProgress.Cancelled()) {
            MessageBox("Progress Cancelled");
            break;
        }
    }    
or it can be done two stage as:
    CProgressWnd wndProgress;
    
    if (!wndProgress.Create(this, "Progress"))
        return;

    wndProgress.SetRange(0,5000);
    wndProgress.SetText("Processing...");         


Comments

  • denne form for beats hovedtelefoner er blevet en snarere i mit liv.

    Posted by hbgdhd833 on 07/16/2013 11:57pm

    Uanset om du har brug for netværks personlig brug derhjemme, eller hvis du har brug for at udstyre dit barns skole, som er en meget sød, med henblik på at få en favorit Beats hovedtelefoner nysgerrig, jeg gravede lidt dybere, og jeg gotta jeg ser frem til i alle de basale behov klik her. Faktisk ønsker jeg dig til at bryde det ned til den korte form.Da jeg fik den elskede monster beats hovedtelefoner, og jeg føler meget glad og spændt, men hvad er den virkelige god pleje af det, selv om de nye hovedtelefoner altid vil indtage markedet hurtigt, men når jeg har beats er stadig som ny, tilfredshed aldrig forladt. Vi taler om nogle enkle opførsel om forlængelse af levetiden for headsettet [url=http://beatsbydrdredanmark.moonfruit.com/]beats by dre billigt[/url] Beats By Dr. Dre Beats Wireless har annonceret et trådløst Bluetooth-headset. Dette er udformningen af den populære Solo HD og kan let kobles med en smartphone eller tablet. Den nye model er også udstyret med ControlTalk, med en mikrofon i øret og alle nødvendige kontroller. Beats By Dr. Dre introducerer Beats trådløse Bluetooth hovedtelefoner Beats By Dr. Dre Beats introducerer den trådløse Bluetooth-hovedtelefoner lytteren fuld musikalsk frihed. [url=http://beatsbydrdredanmark.weebly.com/]Beats by dre Hovedtelefoner[/url] De Beats by Dr. Dre Wireless, kan du nyde fuld musikalsk frihed. Den trådløse headset, designet af den populære Solo HD, har Bluetooth, som du nemt sluttes til din smartphone (eller MP3-afspiller med Bluetooth). Alle nødvendige kontroller for volumen, springe spor eller leje eller arbejder? Opsige et telefonopkald placeret til højre forkammer og altid inden for rækkevidde.

    Reply
  • Où acheter pas cher lisseur ghd pink Onil en Norvège

    Posted by zzsafw973 on 07/16/2013 01:48pm

    Un magazine InStyle Best Buy de beauté depuis plusieurs années running.Hai sont des plaques en céramique sont recouvertes pour protéger les cheveux de la chaleur. Ce fer plat devient assez chaude pour défriser les cheveux (et des cheveux reste droit), mais pas trop chaud pour endommager vos cheveux. De plus, il est prêt à utiliser en moins de 30 secondes. Peut-être le meilleur fer plat sur le marché aujourd'hui, la piste de chaleur FHI est un favori parmi les pros, car il crée élégant, cheveux lisses avec seulement une ou deux passes, selon styliste Jonathan Hanousek dans le numéro 2009 de InStyle Magazine, qui a nommé un Meilleur beauté Acheter en 2009. Avec une étiquette de prix de plus de 300 $, la piste de FHI Heat (avec plaques de tourmaline, bien sûr) durent toute une vie. [url=http://ghdpascherfer.tripod.com/]lisseur ghd[/url] GHD droit tige conteneur livfullheten et lambeaux de cheveux Farget. Près de la rivière pour s'assurer que la chaleur est répartie uniformément, ne devient jamais Hoy, reduserer La fargebevaringsteknologi unique avec IONTEC décoloration av Fargen en stylisme de 70% * et rend le Fargen obtient appareils de coiffage beaucoup plus glansfull.GHD ne fait pas ditt de cheveux terne et sec. Moi, sur IMot: ils empêchent fuktighetstap de style par y infliger ditt de cheveux satengioner unique! Ces ladde négatif ionène célébrations segment à la chevelure ladde positif ditt et reduserer sec, krusete cheveux et tiltrekker fuktighetspartikler de Lufta et leur envoyer votre le Trenger de cheveux le plus. [url=http://bbeatsinorge.cabanova.com/]lisseur ghd[/url] Quand on sait ghd Norvège peut créer une variété de cheveux de style. Donc, nous voulons tous avoir un tel outil. Pour nous permettre easilycreate boucles et les vagues, ainsi que les cheveux raides parfait. Mais vous savez ce lisseur ghd sont le meilleur choix pour vous. Nous devons choisir lisseur ghd approprié pour vous, plutôt que de suivre le chemin de quelqu'un d'autre de l'acheter.

    Reply
  • Nice one there

    Posted by Slalaleasyday on 03/13/2013 08:33am

    Nice Post. ---------- I love http://youtube.com

    Reply
  • Fix for Windows XP and later

    Posted by evox on 06/25/2009 10:29am

    To run this code under Windows XP and later change function CProgressWnd::Create from: // Get the system window message font for use in the cancel button and text area NONCLIENTMETRICS ncm; ncm.cbSize = sizeof(NONCLIENTMETRICS); VERIFY(SystemParametersInfo(SPI_GETNONCLIENTMETRICS, sizeof(NONCLIENTMETRICS), &ncm, 0)); To: // Get os version OSVERSIONINFO osvi; ZeroMemory(&osvi, sizeof(OSVERSIONINFO)); osvi.dwOSVersionInfoSize = sizeof(OSVERSIONINFO); GetVersionEx(&osvi); BOOL bIsWindowsBeforeVista = osvi.dwMajorVersion < 6; // Get the system window message font for use in the cancel button and text area NONCLIENTMETRICS ncm; ncm.cbSize = sizeof(NONCLIENTMETRICS); if (bIsWindowsBeforeVista) ncm.cbSize -= sizeof(int); VERIFY(SystemParametersInfo(SPI_GETNONCLIENTMETRICS, ncm.cbSize, &ncm, 0));

    Reply
  • fix progress calculation in ProgressWnd.cpp:

    Posted by jauming on 02/28/2009 09:31am

    fix progress calculation in ProgressWnd.cpp:
    CProgressWnd::SetPos
    
    from :
    nPercentage = (nPos*100)/(m_nMaxValue - m_nMinValue);
    
    to:
    nPercentage = ((nPos-m_nMinValue)*100)/(m_nMaxValue - 
    m_nMinValue);

    Reply
  • where is other comments?

    Posted by habilmu on 08/02/2006 10:26pm

    is there nothing else cs.rasha's comment?

    Reply
  • The unique should be always noticed

    Posted by cs.rasha on 02/20/2005 11:00am

    Thank you very much for your effort

    Reply
Leave a Comment
  • Your email address will not be published. All fields are required.

Top White Papers and Webcasts

  • Today's agile organizations pose operations teams with a tremendous challenge: to deploy new releases to production immediately after development and testing is completed. To ensure that applications are deployed successfully, an automatic and transparent process is required. We refer to this process as Zero Touch Deployment™. This white paper reviews two approaches to Zero Touch Deployment--a script-based solution and a release automation platform. The article discusses how each can solve the key …

  • On-demand Event Event Date: December 18, 2014 The Internet of Things (IoT) incorporates physical devices into business processes using predictive analytics. While it relies heavily on existing Internet technologies, it differs by including physical devices, specialized protocols, physical analytics, and a unique partner network. To capture the real business value of IoT, the industry must move beyond customized projects to general patterns and platforms. Check out this webcast and join industry experts as …

Most Popular Programming Stories

More for Developers

RSS Feeds