Documentation
[SDK Documentation] [Creating a new project]

 

Creating a new project

This document has been updated for use with GapiDraw 3.50 or later.
Last updated on Wednesday, October 13, 2004.

 

Introduction

This tutorial shows you how to create the project files that are shipped with the GapiDraw sample applications. If you use a development environment such as Visual Studio .NET you may have to re-create the project files shipped with the GapiDraw samples since the Visual Studio 6.0 project files in most cases cannot be correctly opened and converted by Visual Studio .NET. Also, Embedded Visual Tools 4.0 that is required for Windows Mobile 2003 development can also not correctly open Embedded Visual Tools 3.0 project files.

The tutorial describes how to create project files for stationary PCs and Windows Mobile devices. If you simply want to get started with GapiDraw the easiest way to do so is to open the "Minimal" sample application and build your application upon that.

Getting Started

I will assume that GapiDraw is installed into the folder "C:\Source\GapiDraw". We will create our new project in the folder "C:\Source\MyProject". Please replace the word MyProject in this document with the actual name of your application.

Begin by creating the following folders using the Windows Explorer:

C:\Source\MyProject
C:\Source\MyProject\Common
C:\Source\MyProject\Common\Res
C:\Source\MyProject\WinCE
C:\Source\MyProject\WinXP
Adding content

Create a new text file called "myproject.cpp" in the folder "C:\Source\MyProject\Common". Add the following text to the file:


#ifndef STRICT
#define STRICT
#endif

#include "GapiDraw.h"
#include "GapiApplication.h"
#include "resource.h"

// ----------------------------------------

class CMyApplication : public CGapiApplication
{
public:
    CMyApplication(const GDAPPCONFIG& config) : CGapiApplication(config) {};

	virtual HRESULT CreateSysMemSurfaces(CGapiDisplay* pDisplay, HINSTANCE hInstance)
	{
		// Add code to create surfaces here
		return GD_OK;
	}

	virtual HRESULT CreateVidMemSurfaces(CGapiDisplay* pDisplay, HINSTANCE hInstance)
	{
		// Add code to create surfaces stored in video memory here
		return GD_OK;
	}

    virtual HRESULT ProcessNextFrame(CGapiSurface* pBackbuffer, DWORD dwFlags)
    {
        // Clear the back buffer
        pBackbuffer->FillRect(NULL, RGB(128, 128, 128), 0, NULL);
    
        // Draw some text
        DWORD dwXCenter = (pBackbuffer->GetWidth()>>1);
        DWORD dwYCenter = (pBackbuffer->GetHeight()>>1);
        TCHAR str1[] = TEXT("Welcome to GapiDraw!");
        pBackbuffer->DrawText(dwXCenter, (dwYCenter-4), str1,
            m_pDisplay->GetSystemFontBorder(),
            GDDRAWTEXT_CENTER, NULL, 0, NULL);
    
        return S_OK;
    };

    virtual HRESULT KeyDown(DWORD dwKey, GDKEYLIST& keylist)
    {
        // Exit main loop on any key press
        Shutdown();
        return S_OK;
    };

    virtual ~CMyApplication() {};
};

// ----------------------------------------

int APIENTRY WinMain(HINSTANCE hInst, HINSTANCE hPrevInst,
                     LPTSTR pCmdLine, int nCmdShow)
{
    GDAPPCONFIG config;
    ::ZeroMemory(&config, sizeof(GDAPPCONFIG));

    config.hInstance       = hInst;
    config.pAppTitle       = TEXT("Welcome to GapiDraw!");
    config.dwTargetFPS     = 30;
    config.dwWindowIcon    = IDI_APP;

    // Create the application
    CMyApplication simple(config);

    // Start main loop
    return simple.Run();
}

Let's add a windows icon as well (so the program looks nicer on Stationary computers). Right click on the icon below and choose Save Target As.... Pick the folder "C:\Source\MyProject\Common\Res".


GapiDraw.ico

 

Stationary PCs

Let's begin by creating the necessary files for Visual C++ 6.0. Start Visual C++ and choose File->New.... Choose Win32 Application and enter "MyProject" as name. Enter the folder "C:\Source\MyProject\WinXP" as target location. Do not use the file selector since Visual Studio will then append "MyProject" to the file path.


Creating a new Win32 Application

When you click on OK you get to choose the kind of Windows application you want to create. Leave the default An empty project selected and click Finish. Click on OK.

Adding the code

Source files. In Visual Studio, click on to the File View tab which should be available in the workspace explorer. Expand MyProject files by using the + next to the text label, and right click on the folder called Source Files. Choose Add Files to Folder.... Navigate to "C:\Source\MyProject\Common" and double click on the file "myproject.cpp".

Header files. Right click on the folder called Header Files and choose Add Files to Folder.... Navigate to "C:\Source\GapiDraw\include\win32" and select the files "GapiDraw.h", "GapiApplication.h", and "GapiApplication.cpp". Click on OK.

Adding the resources

Begin by adding a resource script to your project. Choose the menu File->New... and pick Resource Script. Enter "MyProject" as a name for the script. Leave the other settings at the default. Click on OK.


Adding a resource script to the project

Close the window that opens using Window->Close. Right click on the folder Resource Files and choose Add Files to Folder.... Navigate to "C:\Source\MyProject\WinXP" and select the file "resource.h". Click on OK.

The procedure for adding an icon to the project is the same as adding images or other resources to your project. The main difference is that the file selector in Visual Studio does not recognize PNG, GIF and JPG images, so you have to enter "*.*" as file mask in the selector when adding that type of images.

Choose the menu Insert->Resource, or click CTRL+R. Click on Import and navigate to "C:\Source\MyProject\Common\Res". Double click on the file "gapidraw.ico". The icon should now be visible on screen. Close this window using the menu Window->Close. Right click on "IDI_ICON1" and choose properties. You should now see something similar to the following (the language of the resource may differ).


The imported resource

Visual Studio assumes that all resources always are to be placed in the same folder as the project. We do not want that, so change File name into "..\Common\Res\GapiDraw.ico". At the same time, change the ID of the icon into "IDI_APP". Do not bother to change the language of the resource. You should now have a dialog that looks like the following:


The resource after we have changed the file path

Close the property dialog and click CTRL+S to save the resource script.

Linking to GapiDraw

Now we have to change some of the project settings to make the compiler know that we want to include the GapiDraw library with the build. Start by switching to the File View panel in the workspace explorer. Select the text label MyProject files, and choose the menu Project->Settings....

Common settings

Click the combo box in the top left corner and choose Settings For - All Configurations. Choose the tab C/C++ and pick the category Preprocessor. In the text area called Additional include directories enter ".,..\Common,..\..\GapiDraw\include\win32". Choose the tab Link. Pick the category General, and add "GapiDraw.lib" to the text field Object/library modules. Pick the category Input, and in the text field called Additional library path enter "..\..\GapiDraw\lib\xp".

Testing the application

Start the application using the menu Build->Execute MyProject.exe. You should now see a screen that looks like the following:


Our project is up and running on stationary PCs.

 

Pocket PCs

Let's now create the project files for Embedded Visual C++. Start Embedded Visual C++ and choose File->New.... Choose WCE Pocket PC Application and enter "MyProject" as name (if you use Embedded Visual C++ 4.0 you choose WCE Pocket PC 2003 Application). Enter the folder "C:\Source\MyProject\WinCE" as target location. Do not use the file selector since Embedded Visual C++ will then append "MyProject" to the file path. Scroll through the CPUs list and make sure that every selectable check box is marked.


Creating a new Pocket PC Application

When you click on OK you get to choose the kind of Windows application you want to create. Choose An empty project and click Finish. Click on OK.

Adding the code

Source files. In Embedded Visual C++, switch to the File View tab which should be available in the workspace navigator. Expand MyProject files by using the + next to the text label, and right click on the folder called Source Files. Choose Add Files to Folder.... Navigate to "C:\Source\MyProject\Common" and double click on the file "myproject.cpp".

Header files. Right click on the folder called Header Files and choose Add Files to Folder.... Navigate to "C:\Source\GapiDraw\include\win32" and select the files "GapiDraw.h", "GapiApplication.h", and "GapiApplication.cpp". Click on OK.

Adding the resources

Begin by adding a resource script to your project. Choose the menu File->New... and pick Resource Script. Enter "MyProject" as a name for the script. Leave the other settings at the default. Click on OK.


Adding a resource script to the project

Close the window that opens using Window->Close. Right click on the folder Resource Files and choose Add Files to Folder.... Navigate to "C:\Source\MyProject\WinCE" and select the file "resource.h". Click on OK.

The procedure for adding an icon to the project is the same as adding images or other resources to your project. The main difference is that the file selector in Visual Studio does not recognize PNG, GIF and JPG images, so you have to enter "*.*" as file mask in the selector when adding that type of images.

Choose the menu Insert->Resource, or click CTRL+R. Click on Import and navigate to "C:\Source\MyProject\Common\Res". Double click on the file "gapidraw.ico". The icon should now be visible on screen. Close this window using the menu Window->Close. Right click on "IDI_ICON1" and choose properties. You should now see something similar to the following (the language of the resource may differ).


The imported resource

Visual Studio assumes that all resources always are to be placed in the same folder as the project. We do not want that, so change the "File name" into "..\Common\Res\GapiDraw.ico". At the same time, change the ID of the icon into "IDI_APP". Do not bother to change the language of the resource. You should now have a dialog that looks like the following:


The resource after we have changed the file path

Close the property dialog and click CTRL+S to save the resource script.

Linking to GapiDraw

Linking to GapiDraw is a bit more work on Windows CE since we have so many devices to target. Start by switching to the File View panel in the workspace. Select the text label "MyProject files", and choose the menu Project->Settings....

Common settings

Click the combo box in the top left corner and choose Settings For - All Configurations. Choose the tab C/C++ and pick the category Preprocessor. In the text area called Additional include directories enter ".,..\Common,..\..\GapiDraw\include\win32".

Individual assignments

The procedure for linking to each CPU platform to GapiDraw is identical, so I will only discuss how to link GapiDraw to the ARM platform and leave the the rest up to the reader. Click the combo box in the top left corner and choose Settings For - Win32 (WCE ARM) Release. Choose the tab Link. Pick the category General, and add "GapiDraw.lib" to the text field Object/library modules. Pick the category Input and in the text field called Additional library path enter "..\..\GapiDraw\lib\PocketPC-arm". Repeat for MIPS and SH3 builds.

Testing the application

Enable the Windows CE target toolbar by right clicking on any toolbar and choosing WCE Configuration. Choose your target platform from this toolbar and be sure to change Pocket PC Emulation into Pocket PC (Default Device) unless you intend to use the emulator. Use Release build unless you intend to debug your application. Enable automatic downloading using the menu Tools->Options->Download and select all three check boxes. Compile the project using the menu Build->Build MyProject.exe and it should automatically be copied to your device. You will most probably receive a warning that the target device does not match the currently selected target platform. This is due to a bug in Embedded Visual C++ and is nothing to worry about.

Start the application from the Start menu of your device. You should now see something like this:


Our project is up and running on Pocket PCs

 

Smartphones

For your Smartphone project you can simply copy the Pocket PC project into a new folder called "TPC". Copy the project, open the workspace, and change the active platform to Smartphone 2002 using Build->Set Active Platform... If you base your Smartphone project on a copy of the Pocket PC project, you must manually create a file called "afxres.h" and place that in the project folder. Add the following lines to the file "afxres.h":

// ----- Copied from the default Smartphone 2002 SDK template - "resource.h"
#include <windows.h>
#include <aygshell.h>
#include <tpcuser.h>

#define TPC

The file "afxres.h" is included with the Plasma and TileDemo sample applications.

 

Where to go next?

Now when the project is finished, it is time to add some content. This will be covered in future tutorials.