Freigeben über


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

Send Feedback

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 Project or File.

    The New Project or File dialog box appears.

  2. Choose the Projects tab and then choose WCE Application.

  3. Type the name ProgBarDemo in the Project name box, select the Workspace project radio button, and choose OK.

    The New Project Wizard (WCE Application) - Step 1 of 3 dialog box appears.

  4. Type the relevant information in this dialog box and choose Next.

  5. In the New Project Wizard (WCE Application) - Step 2 of 3 dialog box choose An empty project and choose Finish.

    Note that a new node called Projects appears in the OSDesignView of your workspace, and the project you just created appears as a subnode.

  6. From the File menu, choose New Project or File.

    The New Project or File dialog box appears.

  7. Choose the Files tab and then from the list of available file types choose C++ Source File.

  8. Type the name ProgBarDemo in the File name field. Verify that the Add to project check box is selected and that ProgBarDemo is selected in the drop-down list, and then choose OK.

    A window for ProgBarDemo.cpp opens.

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

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

    #include <commctrl.h>
    
  11. 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);
    }
    
    //=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
    
  12. From the File menu, choose 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.

To add Commctrl.lib to the list of link libraries

  1. Select the FileView tab in your workspace. Expand the Projects node. You should see ProgBarDemo under the Projects node. Right-click ProgBarDemo and select Settings.

    The project settings dialog box appears.

  2. Choose 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. Choose OK.

See Also

How to Customize the Appearance of Common Controls | Progress Bar Control Reference | CreateWindowEx | GetClientRect | INITCOMMONCONTROLSEX (structure) | InitCommonControlsEx (function) | MAKELPARAM | MAKEWPARAM | MessageBox | RECT | SendMessage | ShowWindow | TEXT | UpdateWindow

Send Feedback on this topic to the authors

Feedback FAQs

© 2006 Microsoft Corporation. All rights reserved.