Share via


Create an Application (Compact 7)

3/12/2014

You can create an application for Windows Embedded Compact 7 in two ways: you can add it as a subproject of the OS in Platform Builder, or you can create it in Visual Studio outside of Platform Builder by using an SDK, as an application developer typically would. In this guide, for simplicity, you create an application as a subproject of Platform Builder. (To create an application for a vCEPC outside of Platform Builder by using an SDK, see Create an SDK for Virtual CEPC.)

You can write Windows Embedded Compact 7 applications in either native (C++) code or managed code. In this guide, you use native code.

Note

Although you do not use Microsoft Silverlight for Windows Embedded in this guide, be aware that applications that use Silverlight for Windows Embedded must be written in native code.

Here, you add a subproject to your OS design, modify the code, and then build the application. After you build the application, you run it on the vCEPC that you created earlier in this guide.

Add a Subproject to Your OS Design

After you create an OS design, you can add subprojects to it. A subproject is a collection of files that call the APIs of the features that are included in your OS design. A subproject can be an application, a dynamic-link library (DLL), or a static library. In this guide, the subproject that you create is an application.

Note

You can add an application as a subproject to your OS design at any time, but for your application build to succeed, you must build (or have previously built) your OS before you build the application.

To add an application subproject to your OS design

  1. In Platform Builder, in Solution Explorer, select your OS design project.

  2. On the Project menu, click Add New Subproject to start the Subproject Wizard.

  3. In the Subproject Wizard, under Available templates, click WCE Application.

  4. Under Subproject name, type HelloWorld, and then click Next.

  5. In answer to What kind of application would you like to create? click A simple application.

  6. Click Finish.

In Solution Explorer, your Hello World project will appear under the Subprojects node of your OS design.

Modify the Code

Next, modify the code in your subproject application so that the application displays Hello World! in a Getting Started window in the center of your device’s display. To do so, replace all of the code in HelloWorld.cpp with the following code. This code is based on the "Simple Application" created by Visual Studio in the previous step, with small modifications to add the Getting Started window.

#include "stdafx.h"
                   
TCHAR szTitle[] = TEXT("Getting Started");        
TCHAR szWindowClass[] = TEXT("Getting Started");  

ATOM MyRegisterClass(HINSTANCE hInstance);
BOOL InitInstance(HINSTANCE, int);
LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);

int WINAPI WinMain( HINSTANCE hInstance,
                    HINSTANCE hPrevInstance,
                    LPTSTR    lpCmdLine,
                    int       nCmdShow )
{
    MyRegisterClass(hInstance);
    if (!InitInstance (hInstance, nCmdShow)) 
    {
        return FALSE;
    }

    MSG msg;
    while (GetMessage(&msg, NULL, 0, 0)) 
    {
        TranslateMessage(&msg);
        DispatchMessage(&msg);
    }
    return msg.wParam;
}


ATOM MyRegisterClass( HINSTANCE hInstance )
{
    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;

    return RegisterClass(&wc);
}


BOOL InitInstance(HINSTANCE hInstance, int nCmdShow)
{
   HWND hWnd = CreateWindow ( szWindowClass, szTitle, 
                              WS_VISIBLE | WS_SYSMENU | WS_CAPTION, 
                              250, 190, 150, 75, NULL, NULL, hInstance, NULL );
   if (!hWnd)
   {
      return FALSE;
   }
   ShowWindow(hWnd, nCmdShow);
   UpdateWindow(hWnd);

   return TRUE;
}


LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
    PAINTSTRUCT ps;
    HDC hdc;

    switch (message) 
    {
        case WM_PAINT:
            hdc = BeginPaint(hWnd, &ps);
            RECT rt;
            GetClientRect(hWnd, &rt);
            DrawText(hdc, TEXT("\nHello World!"), -1, &rt, DT_CENTER);
            EndPaint(hWnd, &ps);
            break;
        case WM_DESTROY:
            PostQuitMessage(0);
            break;
        default:
            return DefWindowProc(hWnd, message, wParam, lParam);
   }
   return 0;
}

Build the Application

Now, you build your application. After you build the application, your application’s executable is saved to your OS release directory.

Note

By default, subprojects are included in the run-time image. Your application has not been added to the run-time image yet, but it will be included the next time you build the run-time image. However, you may want to prevent the application from being included in the run-time image. One reason to exclude the application from the run-time image is so you can modify the application’s code, rebuild just the application, and run it on the device over a KITL connection without having to rebuild the run-time image and re-download the run-time image to the device. To exclude an application from the run-time image, use the OS Design Property Pages: Subproject Image Settings dialog box. When you exclude the subproject from the run-time image, the application runs directly from the release directory.

To build your application, follow the steps below.

Warning

These steps build the subproject only. Be careful not to build the entire solution unless you want to build the OS again, which can be time-consuming.

To build your application

  1. In Platform Builder, in Solution Explorer, under the Subprojects node, right-click your Hello World project, and then click Properties.

  2. In the Editing dialog box that appears, examine the build options. For a description of the different build options, see Subproject Settings Dialog Box. You do not need to change any build options for this guide.

    Note

    In this guide, you built the OS design project in the debug configuration, so the subproject is automatically built in the debug configuration if you don’t change the subproject’s build options. However, if you want to build the subproject in the debug configuration even when the OS design is in a release configuration, you can specify this choice in the OS design build options. For more information, see OS Design Property Pages: Subproject Image Settings.

  3. In Solution Explorer, under the Subprojects node, right-click your Hello World project.

  4. Click Build.

Note

You can also build all subprojects for your OS design at the same time. To do so, in the menu bar at the top of the Platform Builder window, click Build, and then click Build All Subprojects.

In this guide, your next task is to download the run-time image to your vCEPC.

See Also

Concepts

Getting Started