Share via


Create Your First Application (Compact 2013)

9/29/2014

You can create applications for Windows Embedded Compact 2013 in two ways: you can add them as subprojects of the OS in Platform Builder, or you can use an SDK to create them in Visual Studio outside of Platform Builder. In this exercise, you will create your application as a subproject of Platform Builder.

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

Add a subproject to your OS design

  1. In Platform Builder, open your OS design project.
  2. Go to Project>Add New Subproject to start the Subproject Wizard.
  3. On the Select name, location and templates page, under Available templates, select WCE Application.
  4. Enter a Subproject name, and then select a Location for the project files.
  5. On the Auto-generated subproject files page, select A simple application, and then click Finish.

In Solution Explorer, your new subproject appears under the Subprojects node of your OS design.

Modify the code

In this exercise, you will add code to your subproject so that your device displays a Getting Started window with the text Hello, World!

  1. In the Solution Explorer pane, go to Subprojects>{your application name}>Source files, and then open the C++ file for your application ({your application name}.cpp).

    Edit the code for an application in Visual Studio

  2. Add your code to the C++ file to display a window with the text Hello, World!. Or, if you want, you can copy the sample code below, and then paste it into the source file.

    #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 your subproject

Now build your subproject and include the application’s executable file with your OS run-time image. (You can build the entire OS again, but if you build just the subproject, the build process is much, much faster, and you don’t have to detach your test device.)

Note

Before you build your application subproject, you must have an existing build for this OS design.

To build the subproject

  1. In Solution Explorer, expand the Subprojects node, and then select your application subproject.

  2. Go to Build>Build All Subprojects.

Build just the subproject in Visual Studio 2012

Download and run the application

Use the same steps from Connect to your virtual device and download the OS run-time image to update the run-time image on your test device. When your test device boots with the new OS run-time image, use the following procedure to run the application on your device.

To run the application

  1. In Platform Builder, go to Target>Run Programs.

  2. Select the executable file for your application ({your application name}.exe), and then click Run.

    Run your application on the target device.

Your test device should now display a window with the text “Hello, World!”

Hello World progam running on the device.

Learn more about

  • Subprojects in your OS design
    A subproject is a collection of files that calls 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. For more information, see Create Your Application as a Platform Builder Subproject.
  • Control your target device
    The Target Control lets you transfer files to a target device, load and manage debugger DLLs, and test applications. For more information about the Target Control commands, see Target Control Debugging.

See Also

Concepts

Getting Started