Overview
To minimize application maintenance and support, you should try to make the platform you plan to support use the unified source code. Follow these tips to make a binary file run on both platforms. If you target all versions of Pocket PC and smartphone, it is relatively easy to keep most business logic code synchronized, because all Pocket PCs and smartphone versions are based on Microsoft Windows CE. The new versions of Pocket PC 2003 and Smartphone 2003 use Windows CE 4.2 and require Embedded Visual tools 4.0 (EVT 4.0 ). The old device still uses embedded Visual tools 3.0 (EVT 3.0 ).
Key code skills
Run the check for the Platform
Many developers check the screen resolution and use this information to determine the platform that hosts the application. There are several tools on the market that can change the screen resolution of the Pocket PC (for example, nydidot's virtual display or jimmysoft's Js landscape ). The correct method for the detection platform is:
# Define pocketpcv1 1
# Define smartphonev1 2
# Define pocketpcv2 3
# Define smartphonev2 4
Int mydevicetype ()
{
Tchar szplatform [max_string_buffer];
Int idevicetype = 0;
Osversioninfo osver;
Getversionex (& osver );
If (osver. dwmajorversion = 3)
{
If (systemparametersinfo (spi_getplatformtype,
Sizeof (szplatform), szplatform, 0 )! = 0)
{
If (lstrcmp (szplatform, text ("pocketpc") = 0)
Idevicetype = pocketpcv1; // runs on Pocket PC 2000 and 2002
Else if (lstrcmp (szplatform, text ("Smartphone") = 0)
Idevicetype = smartphonev1; // runs on Smartphone 2002
}
Else
{
If (getlasterror () = error_access_denied) // (5)
Idevicetype = smartphonev1; // is a smartphone:
// Smartphone creates an Access Denied error on
// Systemparametersinfo ()
}
}
Else
{
If (osver. dwmajorversion = 4)
{
If (systemparametersinfo (spi_getplatformtype,
Sizeof (szplatform), szplatform, 0 )! = 0)
{
If (lstrcmp (szplatform, text ("pocketpc") = 0)
Idevicetype = pocketpcv2; // runs on Pocket PC 2003
Else if (lstrcmp (szplatform, text ("Smartphone") = 0)
Idevicetype = smartphonev2; // runs on Smartphone 2003
}
Else
{
If (getlasterror () = error_access_denied) // (5)
Idevicetype = smartphonev2; // is a smartphone:
// Smartphone creates an Access Denied error on
// Systemparametersinfo ()
}
}
}
Return idevicetype;
} On smartphone, calling "systemparametersinfo ()" may fail due to "Access Denied", depending on whether the smartphone is locked and the certificate signed by the application. This is because only such a platform fails to be called because of access denied, so you can also use it as a flag for smartphone.
Check screen resolution
Although I described how to check the platform instead of checking the screen resolution to detect the platform type, once you know the platform, you also need to know the screen resolution of the device. Again, do not assume that the Pocket PC or smartphone has any fixed resolution. Windows Mobile will support different screen resolutions and directions in future versions.
Once you know the screen resolution, you can adjust the window to suit it. If your application is based on the dialog box, you must create an independent dialog box resource for each resolution you want to support, or manually place the control in the dialog box. In either case, you should place the control in the wm_size handler.
Minimize menu items
Try to limit the menu to two main menus, with a maximum of seven sub menus.
Smartphone has two hotkeys, corresponding to two screen menus. For the Pocket PC, I do not recommend that you do not exceed this limit to improve the user interface design. In addition, do not use cascading menus. Smartphone does not support this function, which will make most Pocket PC users feel overwhelmed.
Restrict the use of general dialogs to a minimum
Smartphone does not support General dialogs. If you want to save the file, either request name or automatically generate some description names, and then save it to "my documents ". When you want to retrieve a file, fill in all the files that can be loaded by the application to a fine-tuning control, allowing you to select a file.
Pocket PC does not support General dialogs for saving and loading, but you should consider the same method for the Pocket PC, which is not only easier to use, but also can keep the code synchronized. If your application requires the "save file" or "Load file" dialog box, you should use the general dialog box in the Pocket PC.
Only save to "my documents" and load it from it
Pocket PC and smartphone are built for users who do not want to manage their buckets on the go. If you must save something to the storage media or load it from it, use the "My Documents" folder to store data. When a memory card is inserted into the device, another problem may occur. Ask the user: "Is it stored in the memory card ?".
The following code shows you how to discover a memory card:
Void showflashcard ()
{
Bool bcontinue = true;
Handle hflashcard;
Win32_find_data lpwfdflashcard;
Hflashcard = findfirstflashcard (& lpwfdflashcard );
If (hflashcard = invalid_handle_value)
Return;
While (bcontinue)
{
MessageBox (null, lpwfdflashcard. cfilename,
Text ("findflash"), mb_ OK );
Bcontinue = findnextflashcard (hflashcard,
& Lpwfdflashcard );
}
Findclose (hflashcard); // close the search handle.
} In smartphone, the My Documents folder is not in the root directory. If you hard code "/my documents", the application will not store it in the persistent location of the smartphone. The directory name of the German version of Pocket PC is "/meine dokumente", and such a call will also fail. Instead, use the following call to obtain the correct path pointing to "my documents.
Shgetspecialfolderpath (null, sztxt, csidl_personal, 0); csidl_personal requests the "My Documents" folder to be returned in the form of sztxt (tchar.
Create resources for each platform or use the "condition" attribute
If you want the same binary file to be used for both the Pocket PC and smartphone, you must create two resource definitions: One platform and the other. If you only want to keep the source code synchronized, you can use the "condition" attribute of the resource to include the correct resource.
If you want to make binary files compatible, You need to load the Pocket PC or smartphone Resources in the Code:
Switch (idevicetype) // determined with tip-1-above
{
Case smartphonev1:
Case smartphonev2:
IDD = idd_smartphone;
Break;
Case pocketpcv1:
Case pocketpcv2:
IDD = idd_pocketpc;
Break;
Default:
IDD = idd_hpc;
Break;
}
Return dialogbox (hinst, makeintresource (IDD ),
Hwndmain, (dlgproc) startdlgmain); if you use the condition attribute of the resource, put "win32_platform_wfsp" (for smartphone) and "win32_platform_pspc" in the condition field ). Remember that the palm-Size PC (the predecessor of the Pocket PC) and the recently appeared Pocket PC 2003 have the same definition as smartphone, so if you want to differentiate them, you need to create your own definition. If you try to maintain the platform independence of the binary/executable files, you must use different resources for different platforms, but include both of them in the resource files.
Dynamic Loading of specific Pocket PC and smartphone Libraries
As you can see, this is the most important skill to help development. When loading one of the following DLL files at any time, make sure to use "loadlibrary" and "getprocaddress" instead of Statically linking the DLL to the application:
Aygshell. dll (aygshell. lib/aygshell. h ). Contains all the SIP, sh, and so on... And other Pocket PC-specific functions. This dll can also be used for smartphone, but has different feature sets.
Cellcore. dll (cellcore. lib/TSP. h and others ). This dll only exists in Pocket PC 2002 phone edition and smartphone, and does not exist in Pocket PC 2000. It contains all the functions used for Connection Manager and telephone call.
Loading these DLL at run time allows you to develop some intelligent error handling. It still allows applications to run without the functions provided by these libraries. If these libraries are statically linked during compilation, the application will not even start on Pocket PC 2002 because it tries to load these DLL files and gives the error "one or more components are missing ".
If you only want to keep the source code synchronized, you do not need to do so. Instead, you can link these libraries to the compilation process. Note that cellcore. Lib must be retrieved manually each time you switch between the compiling process of Pocket PC 2000 and Pocket PC 2002.
Do not assume there is a touch screen
Smartphone does not have a touch screen, and Pocket PC does not have a number key to click, but both devices support d-pad navigation similar to a keyboard. Therefore, if you want to maintain source code synchronization, all user input that require navigation should be implemented through the D-pad navigation. The menus in the Pocket PC are activated through the touch screen, while those in the smartphone are activated through hotkeys. However, because the platform will process the input for you, you do not need to worry about it.
Summary
Although less Code Synchronization is required, maintaining only one source code brings great benefits. Most problems are caused by differences in screen size and input methods. If you follow the above skills, you can compile a cool cross-platform application.