Share via


Develop and Run an Application on a Virtual CEPC (Compact 7)

3/12/2014

The tasks below describe how to create a simple Windows Embedded Compact application that displays the target device boot name that your virtual CEPC uses to connect to Platform Builder.

Tasks to Develop and Run an Application in a Virtual CEPC

  • Task 1: Create a Platform Builder Subproject
  • Task 2: Add Your Application Code
  • Task 3: Build and Run Your Application

Task 1: Create a Platform Builder Subproject

The easiest way to get your Windows Embedded Compact application started is to develop it as a Platform Builder subproject. Use the following steps to create an initial Platform Builder subproject for your application.

To create a subproject in your OS design

  1. Open your OS design project in Platform Builder, such as the VCEPC project that you created earlier.

  2. On the Project menu, click Add New Subproject.

  3. When the Subproject Wizard displays a list of available templates, select the WCE Application template.

  4. In the Subproject name box, enter the name of your application. For example, you can use the name "MyBootName" for this example application. In the Location box, you can enter a new location for your subproject or use the path that is provided. Click Next.

  5. On the Auto-generated subproject files page, select A simple application, and then click Finish.

After you create this new subproject in your OS design, you can compile and link the generated application template to run on your virtual CEPC.

To build your subproject

  1. In the Solution Explorer pane, expand Subprojects to view all subprojects.

  2. Locate and right-click the subproject that you created for your application, and then click Build.

  3. Verify that there are no build errors in the output display window. For example, if you named your subproject "MyBootName," the output window should display the following messages:

C:\WINCE700\OSDesigns\VCEPC\VCEPC\MyBootName\sources - 0 error(s), 0 warning(s)
========== Build: 1 succeeded or up-to-date, 0 failed, 0 skipped ==========

After you successfully create and build your initial subproject, you can add functionality to create your application.

Task 2: Add Your Application Code

When you use the Subproject Wizard to create a simple application template, it creates a .cpp source file with an empty WinMain function-you use this file as the starting point for developing your application. If you choose "MyBootName" for your project name, the Subproject Wizard creates the source file MyBootName.cpp with a few lines of template code:

#include "stdafx.h"

int WINAPI WinMain(HINSTANCE hInstance,
                   HINSTANCE hPrevInstance,
                   LPTSTR    lpCmdLine,
                   int       nCmdShow)
{
    // TODO: Place code here.
    return 0;
}

In the following steps, you will replace this code template with sample application code that retrieves the boot name of your virtual CEPC and displays this boot name in a small window on your virtual CEPC desktop.

To create the MyBootName sample application

  1. In the Solution Explorer pane, expand the MyBootName subproject that you created earlier.

  2. Locate the Source files folder and expand it to reveal the source file MyBootName.cpp as shown here:

    Subproject Tree

  3. Double-click MyBootName.cpp to open it, then replace the contents of this file with the following code sample:

    #include "stdafx.h"
    
    // The main window class name.
    
    TCHAR szWindowClass[] = TEXT("SimpleApp");
    
    // The string that appears in the application's title bar.
    
    TCHAR szTitle[] = TEXT("Boot Name");
    
    // Forward declaration of callback function.
    
    LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
    
    int WINAPI WinMain(HINSTANCE hInstance,
                       HINSTANCE hPrevInstance,
                       LPTSTR    lpCmdLine,
                       int       nCmdShow)
    {
       WNDCLASS wc;
       wc.style = CS_HREDRAW | CS_VREDRAW;
       wc.lpfnWndProc = (WNDPROC) WndProc;
       wc.cbClsExtra = 0;
       wc.cbWndExtra = 0;
       wc.hInstance = hInstance;
       wc.hIcon = 0;
       wc.hCursor = 0;
       wc.hbrBackground = (HBRUSH) GetStockObject(WHITE_BRUSH);
       wc.lpszMenuName = 0;
       wc.lpszClassName = szWindowClass;
    
       // Register the application
    
       RegisterClass(&wc);
    
       // Create the window for the application: specify the name 
       // of the application, the title bar text, flags to make
       // the window visible and turn on decorations. The window
       // is 140x60 in size and there is no parent window or menu.
    
    HWND hWnd = CreateWindow (
    szWindowClass, szTitle, WS_VISIBLE | WS_CAPTION, 
    400, 150, 140, 60, NULL, NULL, hInstance, NULL);
    
    // Display the window.
    
    ShowWindow (hWnd, nCmdShow);
    
    // Send a WM_PAINT message to the window.
    
    UpdateWindow (hWnd);
    
    // Message loop that listens for OS messages. When
    // the application receives a message, this loop dispatches
    // the message to the WndProc function.
    
    MSG msg;
    while (GetMessage(&msg, NULL, 0, 0))
    {
    TranslateMessage(&msg);
    DispatchMessage(&msg);
    }
       return msg.wParam;
    }
    
    // Function that processes messages for the main (and only) window:
    
    LRESULT CALLBACK WndProc(HWND hWnd, UINT message, 
                             WPARAM wParam, LPARAM lParam)
    {
       PAINTSTRUCT ps;
       HDC hdc;
       TCHAR szBootName[128] = L"";
    
       switch (message) 
       {
            case WM_PAINT:
    
                // Get the boot name and display it:
    
                SystemParametersInfo (SPI_GETBOOTMENAME, 
                        sizeof(szBootName), szBootName, 0);
                hdc = BeginPaint(hWnd, &ps);
                RECT rt;
                GetClientRect(hWnd, &rt);
                DrawText(hdc, szBootName,
                        _tcslen(szBootName), &rt, DT_CENTER);
                EndPaint(hWnd, &ps);
                break;
    
            case WM_DESTROY:
                PostQuitMessage(0);
                break;
    
            default:
                return DefWindowProc(hWnd, message, wParam, lParam);
       }
       return 0;
    }
    
  4. Click the File menu and click Save All to save your changes.

Task 3: Build and Run Your Application

To build MyBootName

  1. Locate and right-click the MyBootName subproject that you created earlier, then click Build.

  2. Verify that there are no build errors in the output display window. For example, the output window should display the following messages:

    C:\WINCE700\OSDesigns\VCEPC\VCEPC\MyBootName\sources - 0 error(s), 0 warning(s)
    ========== Build: 1 succeeded or up-to-date, 0 failed, 0 skipped ==========

    After you successfully create and build MyBootName.exe, you can start it and see it run on your virtual CEPC desktop.

To run MyBootName.exe on your virtual CEPC

  1. If your virtual CEPC is not already booted and connected to Platform Builder, follow the steps in Download and Run a Virtual CEPC OS Run-Time Image to start your virtual CEPC and prepare it for running your application.

  2. In Platform Builder, on the Target menu, click Run Programs, and then select MyBootName.exe.

  3. Verify that your application starts and runs successfully. When MyBootName runs successfully, it prints the boot name of your virtual CEPC in a small window as shown here:

    Running MyBootName

To stop MyBootName, right-click Boot Name on the virtual CEPC taskbar and select Close.

See Also

Concepts

Develop with Virtual CEPC