|
Written by Wojciech Kocjan
|
If you have a Windows Mobile powered device, you'll be thrilled to know that Tcl/Tk is available for it. The'res great port for Windows Mobile platform called Etcl, which is also available for Windows, Linux and Mac OS X. This article begins a series showing some useful information on writing for Windows Mobile. It's also recommended for people that are device geeks, but don't yet have such a device - perhaps it'll give you some ideas on what to expect from them.
First things first. There are two types of Windows Mobile based devices - PocketPC and smartphones. First one has a touch screen and a relatively large screen - usually around 3" and 240x320 pixels or more - largest screens are even up to 480x800 pixels. Smartphones have numeric pads, two soft keys and much smaller screens - usually 176x180 pixels. Most devices nowadays ship with Windows Mobile 5 or 6, but almost all things are the same in devices that use Windows Mobile 2003. In this article we'll focus on PocketPC, Windows Mobile 5 and 6 and describe both displays with 240x320 (so called QVGA) and 480x640 (so called VGA) displays.
Etcl has a smooth installation method on PocketPC. After installing it, you can run either Etcl by itself or simply run any file with *.tcl, *.tk and *.etk. When running an Etcl binary, a console shows up where you can type Tcl interactively:
Since PocketPC does not come with any command line tool by default, Etcl seems like a very good tool for power users. You can do operations like file copying, renaming and deleting automatically. Also, using simple Tcl syntax like foreach and string manipulation it is possible to do complex things like batch renaming easily.
Etcl also comes with two sample applications - a calculator written in Tcl/Tk and a game called ataxx. Here's how they look like on various PocketPC devices:
The best thing is that you can use Tk and Tile on PocketPC in almost the same way as on your computer. Unlike Java there are only subtle differences between desktop and mobile versions and they mainly are related to the fact that PocketPC and Smartphone devices have smaller screens and that they always consume entire screen.
Imagine you'd want a small application to tune several registry settings. Tcl can do that! Below is a screenshot of the tool:
Sample code package require registry
set reg(P3Limit) {HKEY_LOCAL_MACHINE\SOFTWARE\HTC\camera\AppDefSettings\P3}
wm title . "Registry tweak"
# configuration of Windows Mobile animation
set reg(AniType) {HKEY_LOCAL_MACHINE\SYSTEM\GWE\Menu}
proc setAniType {} {
registry set $::reg(AniType) AniType $::AniType
}
set ::AniType [registry get $::reg(AniType) AniType]
checkbutton .anitype -text "Enable animations" -offvalue 0 -onvalue 6 \
-variable ::AniType -command setAniType -anchor w
pack .anitype -fill x -pady 4
# HTC camera 3GP video limit configuration
# (catch will cause it to skip if registry entry is not present)
proc setP3Limit {} {
registry set $::reg(P3Limit) EnableLimit $::P3Limit
}
catch {
set ::P3Limit [registry get $::reg(P3Limit) EnableLimit]
checkbutton .p3limit -text "3GP record limit" -offvalue 0 -onvalue 1 \
-variable ::P3Limit -command setP3Limit -anchor w
pack .p3limit -fill x -pady 4
}
# set up a small menu
menu .menu
menu .menu.file
.menu add cascade -menu .menu.file -label "File"
.menu.file add command -command exit -label "Exit"
. configure -menu .menu
# automatic fitting of the window
after 100 {focus -force . ; etcl::autofit .}
The last line causes Tcl to run etcl::autofit command after 0.1 second so that the window gets fitted into the screen. Other than that, the code should also work on your desktop, assuming you have registry package and these registry entries present.
As you've seen in this article, writing applications for PocketPC is quite simple. In next part of this series we'll talk about more complex issues and try to focus on a generic plugin based application that could be running on your device all the time. Stay tuned! |