Walkthrough: Create and Run a Simple Windows Application In Native Code
In this walkthrough you will create, build and run a simple Hello World application in C++.
To create a Windows Application project
On the File menu, point to New, and then select Project.
In the Project Types pane, expand the Visual C++ branch and select Smart Device.
In the Templates pane, choose Win32 Smart Device Project.
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.
The Win32 Smart Device Project Wizard will appear. Select Next to select the platforms you wish to support.
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.
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.
To compile and link the application
Replace the WM_PAINT event handler with the following lines of code:
case WM_PAINT: hdc = BeginPaint(hWnd, &ps); int bReturn; TCHAR szHelloStr; 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;
From the Solution Configurations dropdown, located in the toolbar, select Debug.
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.
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
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.
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.
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.
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.
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.
To stop debugging, you can exit your application or select Stop Debugging (Shift+F5) from the Debug menu.
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.
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.