Walkthrough: Create and Run a Simple Windows Application In Native Code

4/19/2010

In this walkthrough you will create, build and run a simple Hello World application in C++.

To create a Windows Application project

  1. On the File menu, point to New, and then select Project.

  2. In the Project Types pane, expand the Visual C++ branch and select Smart Device.

  3. In the Templates pane, choose Win32 Smart Device Project.

  4. In the Name box, name the project something unique to indicate the application's purpose. In the Location box, enter the directory in which you want to save your project, or click the Browse button to navigate to it. Select OK.

  5. The Win32 Smart Device Project Wizard will appear. Select Next to select the platforms you wish to support.

  6. Select the platforms you wish to support with your application. For this walkthrough, select a Windows Mobile 6 or higher SDK and add it to the Selected SDKs. Remove any other platforms from the Selected SDKs list. Select Next.

  7. This step of the wizard allows you to select additional Application Settings. Make sure Windows Application is selected and then click Finish.

The Win32 Smart Device Project will be created and the .cpp file will be displayed in the IDE.

  1. Replace the WM_PAINT event handler with the following lines of code:

      case WM_PAINT:
        hdc = BeginPaint(hWnd, &ps);
    
        int bReturn;
        TCHAR szHelloStr[50];
    
        StringCchCopy(szHelloStr, 50, L"Hello World!");
    
        // Set text color.
        SetTextColor (hdc, RGB(0,0,0));
    
        bReturn = ExtTextOut (hdc, 10, 10, 0, NULL,             
                              szHelloStr, lstrlen(szHelloStr), NULL);
    
    
        EndPaint(hWnd, &ps);
      break;
    
  2. From the Solution Configurations dropdown, located in the toolbar, select Debug.

  3. From the Target Device dropdown, located in the toolbar, select your device to test the application on. For this walkthrough, select Windows Mobile 6 Classic Emulator.

  4. Build your project by selecting Build Solution from the Build menu. Check the results of the build in the Output window. Fix errors as needed until the project builds successfully.

To run and debug the application

  1. Set your desired breakpoints. You can set a breakpoint by clicking in the left margin of the line of code you want to set the breakpoint on or by placing the cursor on a line of code and selecting Toggle Breakpoint from the Debug menu. F9 will also toggle breakpoints.

  2. Select Connect to Device from the Tools menu to set up communication with the debugging device, in this case the Windows Mobile 6 Classic Emulator. Click the Connect button.

  3. The emulator window will open and start up. It may take a minute or so to set up the connection with the emulator. Click Close on the Connecting dialog when the connection has been successfully made.

  4. Select Start Debugging from the Debug menu or press F5 to start the application. The executable and any other needed files will be transferred to the emulator. It may take a minute or so to transfer the files.

  5. You can now run your program on the target device and debug it in the Visual Studio environment. You can use the Continue (F5), Step Over (F10), Step Into (F11), and Step Out (Shift+F11) commands to walk through the code.

  6. To stop debugging, you can exit your application or select Stop Debugging (Shift+F5) from the Debug menu.

  7. When you are ready to build the release version of your project, you can change the Solution Configuration dropdown to Release and rebuild the project to build the release version.

  8. When you close the emulator, you are given the option to save the emulator state. By saving the state, you can decrease the emulator start up time the next time you launch the emulator.

See Also

Tasks

Walkthrough: Create and Run a Simple Windows Application In Managed Code

Other Resources

Welcome to Windows Mobile 6.5 Documentation