Creating an Application that Demonstrates the Progress Bar (Windows Embedded CE 6.0)

1/6/2010

The following steps describe how to build a simple application that demonstrates the behavior of a plain horizontal progress bar in a run-time image.

To create the source code for a progress bar demonstration application

  1. From the File menu, choose New, and then select Subproject.

    The Windows Embedded CE Subproject Wizard appears.

  2. Choose WCE Application.

  3. Type the name ProgBarDemo in the Project name box, and click Next.

  4. Select An empty subproject and click Finish.

    Note that a new node called ProgBarDemo appears in the Subprojects node in the Solution Explorer window.

  5. Right-click on the ProgBarDemo node, select Add, and then select New Item.

    The Add New Item dialog box appears.

  6. Select C++ File (.cpp).

  7. Type the name ProgBarDemo in the Name box. Then, click OK.

    A window for ProgBarDemo.cpp opens.

  8. Copy the code from Creating a Sample Application into the ProgBarDemo.cpp window.

  9. Add the following line of code just below the #include directive for Windows.h:

    #include <commctrl.h>
    
  10. Paste the following code into the WinMain function between the block of comments that identify the location for code that loads the accelerator table and the while loop.

    Placing the code in this location causes the progress bar to be displayed and fully advanced from 0 percent to 100 percent before the application enters its main message loop.

    //=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
    
    // Initialize the common controls and then create the progress bar.
    int i;
    int iSpacing;   // Controls the size of the progress bar.
    HWND hwndPB;    // Handle of progress bar.
    INITCOMMONCONTROLSEX iccInit;
    RECT rcClient;  // Client area of the application window.
    
    // Initialize the common controls.
    iccInit.dwSize = sizeof(iccInit);
    iccInit.dwICC = ICC_PROGRESS_CLASS;
    InitCommonControlsEx(&iccInit);
    
    // Create the window for the progress bar.
    GetClientRect(g_hwndMain, &rcClient); 
    iSpacing = (int)(0.05 * (rcClient.right - rcClient.left));
    hwndPB = CreateWindowEx(0,
                            PROGRESS_CLASS,
                            TEXT("Progess Bar"), 
                            WS_CHILD | WS_VISIBLE,
                            rcClient.left + iSpacing, 
                    (int)((rcClient.bottom - rcClient.top)/2 - iSpacing/2),
                            rcClient.right - 2 * iSpacing,
                            iSpacing, 
                            g_hwndMain,
                            NULL,
                            hInstance,
                            NULL); 
    
    if(!hwndPB)
    {
      MessageBox(g_hwndMain, TEXT("Unable to create the progress bar"),
                 TEXT("Progress Bar"), MB_OK);
      return  FALSE;
    }
    
    // Display the progress bar.
    ShowWindow(g_hwndMain, iCmdShow);
    UpdateWindow(g_hwndMain);
    
    // Set the range and increment of the progress bar. 
    SendMessage(hwndPB, PBM_SETRANGE, 0, MAKELPARAM(0,100)); 
    SendMessage(hwndPB, PBM_SETSTEP, MAKEWPARAM(1, 0), 0);
    
    // Send data to the progress bar to make it advance.
    for(i=0 ; i < 100 ; i++)
    {
      SendMessage(hwndPB, PBM_STEPIT, 0, 0); 
      Sleep(50);
    }
    
    //=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
    
  11. On the File menu, select Save, and then Close to close the file.

Because the previous code uses a common control, that is, the progress bar, you must add Commctrl.lib to the list of link libraries for ProgBarDemo.exe.

  1. In the Solution Explorer window, expand the Subprojects node. You should see ProgBarDemo node. Right-click ProgBarDemo and select Properties.

    The project settings dialog box appears.

  2. Select the Link tab.

  3. In the Additional Libraries field, add (_$PROJECTROOT)\cesysgen\sdk\lib\(_$CPUINDPATH)\Commctrl.lib to the end of the list of link libraries. Note that the list of libraries is separated by a space character.

  4. Click OK.

See Also

Reference

Progress Bar Controls Reference
CreateWindowEx
GetClientRect
INITCOMMONCONTROLSEX (structure)
InitCommonControlsEx (function)
MAKELPARAM
MAKEWPARAM
MessageBox
RECT
SendMessage
ShowWindow
UpdateWindow

Concepts

How to Customize the Appearance of Common Controls

Other Resources

TEXT