[Q]Bash scripting - T-Mobile Samsung Galaxy S II SGH-T989

Hey XDA, question, been usig bash for god nows how long, definately not new to it/linux,
basis for my question is, i built a huge ass config-based script (reads from default of 5 cfgs, to infinite..) t
o work as init.d, with way to many options
So many it actually gets annoying using root explorer to edit em all, & tracking em all down xD (generated..)
So i built a dynamic menu script to define it (everything in it changes dynamicly depending on config + current displayed info)
With the lack of text functions on droid its getting annoying xD lmao, so yesterday when i got off work i sat down & rebuilt it from scratch
Only took about n hour, its not to big, but now im stuck on a big issue with droid trying to add option for color
On linux its easy (just tput that **** xD), Android, almost got it, but unless i am filling the menu, color wont stick
Meaning, if i color parts of the menu (borders, text, etc. ) thenhide the keyboard, color returns to default
My question is simply, is there a bash native way to force color?
Script is here if you want a reference
http://pastebin.com/DXq1ny4P
Main config:
http://pastebin.com/q6CziJNi
Advanced config:
http://pastebin.com/0LruDMWc
(Configs MUST be in SRC/Menus from script)
Configs have functio ns removed to use as example..
excuse the crudeness & "unusual" method for scriptig xD its a WiP..
Only had about an hour or so on it
That color function is NOWHERE near mt final, its just a tmp untill
I can get full color working,
Full (so far) is:
Code:
Sf_Out() # Allows multiple variables to be parsed
# during echo, while keeping a simple layout
# $1 = Color ends after echo? [0|1]
# $2 = Remove newline on echo [0|1]
# $3 = FiP (in progress, bold text) [N/A]
# $4 = Foreground color
# $5 = Background color
# $6 = Actual text
# Command is parsed by following layout
# 'Sf_Out 0 0 0 {$4} {$5} "text"'
{
Ec="-e"
tmp=$1; # Specifify if color should end after echo
tmp=$2; # Should we remove newline on echo
tmp=$3; # FiP
U="$6" # Actual text of echoline
case "$1" in
1)Ad="FixCl;";;
*)Ad=;;
esac;case "$2" in
1|y)Ec="-en";;
esac;case "$3" in
1)FiP=;;
*)FiP=;;
esac;
W="$(case "$4" in
0)echo "30";;
1)echo "31";;
2)echo "32";;
3)echo "33";;
4)echo "34";;
5)echo "35";;
6)echo "36";;
7)echo "37";;
*)echo "37";;
esac)"
V="$(case "$5" in
0)echo "40m";;
1)echo "41m";;
2)echo "42m";;
3)echo "43m";;
4)echo "44m";;
5)echo "45m";;
6)echo "46m";;
7)echo "47m";;
*)echo "47m";;
esac)";
echo $Ec "\e[$M;$V""$6"
if [ "$Ad" == 1 ];then FixCl;Ad=;fi
}
dblChk() {
Ok=;Dc="$1";Fb="$2";Op="$3";V1="$4";V2="$5"
for k in `seq $V1 $V2`;
do
if [ "$Dc" == "$k" ];then export "$Op"="$k";else export "$Op"="$Fb";Ok=1;fi
done
}
I have a few more to update aswell, as i said, its constantly changing atm, & wont stabilize untill i can either get
This working, or give up, lol,
Side note, if anyone knows where i can get a tput binary, can u lemme know? Lol i coulda had this done in 30min xD

ok, on the way home on the bus, got 15 min, 10 min in, got a new echo prompt, & better explanation of my issue.
Heres my new function:
Code:
Sf_UI()####################################################
#
# Usage:
# Sf_UI <A> <B> <C> <D> "{TEXT}"
#
# Where <$> is:
# A - Color is line only [1|0]
# B - Remove newline from end of echo [1|0]
# C - Bold or underline? [0-none|1-bold|2-underline]
# D - Text color [0|1|2|3|4|5|6|7]
# E - background color [0|1|2|3|4|5|6|7]
###########################################################
{ Fx=;A=$1;B=$2;C=$3;D=$4;E=$5
case "$1" in
1)Fx=1;;
0)Fx=0;;
*)Fx=;;
esac;case "$2" in
1)Var="-ne";;
*)Var="-e";;
esac;case "$3" in
1)Bd=1;;
2)Bd=4;;
*)Bd=0;;
esac;
# Grab our colors..
FgC="$(case "$4" in
1)echo "31";;
2)echo "32";;
3)echo "33";;
4)echo "34";;
5)echo "35";;
6)echo "36";;
7)echo "37";;
*)echo "37";;
esac)"
BgC="$(case "$5" in
0)echo "40";;
1)echo "41";;
2)echo "42";;
3)echo "43";;
4)echo "44";;
5)echo "45";;
6)echo "46";;
7)echo "47";;
*)echo "47";;
esac)";case "$Fx" in
1)echo $Var "\e[$B;$(echo $FgC)m""\e[$(echo $BgC)m""$6""\e[0m";;
*)echo $Var "\e[$B;$(echo $FgC)m""\e[$(echo $BgC)m""$6";;
esac
}
Which when used in either 'Sf_UI 0 0 0 color1 color2' fills colorspace
'Sf_UI 1 0 0 color1 color2' outputs a newline with standard text afterwords, you get the idea..
In terminal,
Outputs results of pic1&2, pic3 is same prompt & keyboard down.

Related

Disable Low Batt Notifications

Hey guys,
I thought i would post this here. Its a mortscript i wrote to automaticlly dismiss the Low Battery notification when your battery goes under 20%.
It works best if you do the mod here http://forum.xda-developers.com/showthread.php?t=331288 and then untick popup message/vibrate etc in 'sounds and notifications'.
Code:
#
# NOLBATT.mscr - Monitors notifications and keeps deleting active registry key for low battery
#
# initialize variables
Delete = FALSE
LowBattID = "{A877D663-239C-47A7-9304-0D347F580408}"
# start notification check loop
While ( 1 )
# check the registry for any notifications
If ( RegValueExists( "HKLM", "System\State\Shell\Notifications\Active", "CLSID" ) )
# make sure it's low batt
CLSID = RegRead( "HKLM", "System\State\Shell\Notifications\Active\", "CLSID" )
If ( CLSID eq LowBattID )
Delete = True
EndIf
Else
Delete = False
EndIf
# Delete Active notification for Low battery
# the OS turns it off whenever there is a new notification.
If ( Delete )
RegDeletekey ( "HKLM", "System\State\Shell\Notifications\Active", TRUE, TRUE )
EndIf
# wait 5 seconds
Sleep( 5000 )
EndWhile
Any thoughts on how to make it more efficient etc are appreciated. There is a 'batterypercentage' option in mortscript that could perhaps be utilised to start the script at a certain percentage.

Playing DOS Games in X1 using DOSBOX

Hello guys,
Earlier, I thought of playing old dos games in X1 using DOSBOX.
Some of my favorite DOS games was
Heretic
Descent
Dave
Skyroads
Commander Keen
and specially Lemmings!!
All of them can be found in DOSGAMESARCHIVE.com
Anyway, my problem is .. SPEED.
So I thought maybe we could help each other to make things faster specially on 3D games.
here's my dosbox config
PHP:
# This is the configurationfile for DOSBox 0.73.
# Lines starting with a # are commentlines.
# They are used to (briefly) document the effect of each option.
[sdl]
# fullscreen: Start dosbox directly in fullscreen.
# rotateright: Alternate screen rotation.
# mapperfile: File used to load/save the key/event mappings from.
# kbdtoolbar: First toolbar.
# gametoolbar: Second toolbar.
# settoolbar: Third toolbar. Note: frameskip and cycles values are drawn there.
# usescancodes: Avoid usage of symkeys, might not work on all operating systems.
# sensitivity: Mouse sensitivity.
# touchpadmouse: Emulate mouse with stylus moves on screen. Can fix mouse behavior in games that expect only relative mouse movement.
# clickms: When in touchpad mode, left-click is sent after single-tap. This sets the delay in milliseconds between emulated mouse button down and up events.
# rightclickdelay: Touchpad mode. If you tap and hold stylus for this milliseconds, right-click will be send instead of left. 0 to disable.
# dpadmouse: Emulate mouse with D-Pad. Make sure to set corresponding mapper values for this to work. Up, down, left and right keys are autorotated.
# forcetoolbar: Sometimes where's no space on screen to fit even a part of toolbar. This forces it to display. Also a key and a zone can be set for toggling.
# forcetransparent: Forced toolbar area, overlapping active screen part will be semitransparent.
# forcezone: X, Y, width and height of 'force toolbar display' tapzone. No spaces please. See also hand_force_tlbr setting in mapper.txt
# forceheight: Forced toolbar will have this height.
fullscreen=true
rotateright=true
mapperfile=mapper.txt
kbdtoolbar=toolbar.dbk
gametoolbar=game.dbk
settoolbar=set.dbk
usescancodes=false
sensitivity=200
touchpadmouse=false
clickms=50
rightclickdelay=700
dpadmouse=true
forcetoolbar=true
forcetransparent=true
forcezone=0,0,10,5
forceheight=52
[dosbox]
# language: Select another language file.
# machine: The type of machine tries to emulate.
# Possible values: hercules, cga, tandy, pcjr, ega, vgaonly, svga_s3, svga_et3000, svga_et4000, svga_paradise, vesa_nolfb, vesa_oldvbe.
# captures: Directory where things like wave, midi, screenshot get captured.
# memsize: Amount of memory DOSBox has in megabytes.
# This value is best left at its default to avoid problems with some games,
# though few games might require a higher value.
# There is generally no speed advantage when raising this value.
language=
machine=svga_s3
captures=capture
memsize=72
[render]
# frameskip: How many frames DOSBox skips before drawing one.
# aspect: Do aspect correction, if your output method doesn't support scaling this can slow things down!.
# scaler: Scaler used to enlarge/enhance low resolution modes. If 'forced' is appended,the scaler will be used even if the result might not be desired.
# Possible values: qvga, vga.
frameskip=4
aspect=false
scaler=vga
[cpu]
# core: CPU Core used in emulation. auto will switch to dynamic if available and appropriate.
# Possible values: full, dynamic, simple.
# cputype: CPU Type used in emulation. auto is the fastest choice.
# Possible values: auto, 386, 386_slow, 486_slow, pentium_slow.
# cycles: Amount of instructions DOSBox tries to emulate each millisecond. Setting this value too high results in sound dropouts and lags. Cycles can be set in 2 ways:
# 'fixed #number' will set a fixed amount of cycles. This is what you usually need if 'auto' fails.
# (Example: fixed 4000)
# 'max' will allocate as much cycles as your computer is able to handle
#
# Possible values: fixed, max.
# cycleup: Amount of cycles to increase/decrease with keycombo.
# cycledown: Setting it lower than 100 will be a percentage.
core=full
cputype=auto
cycles=max
cycleup=500
cycledown=500
[mixer]
# nosound: Enable silent mode, sound is still emulated though.
# rate: Mixer sample rate, setting any device's rate higher than this will probably lower their sound quality.
# Possible values: 22050, 44100, 48000, 32000, 16000, 11025, 8000, 49716.
# blocksize: Mixer block size, larger blocks might help sound stuttering but sound will also be more lagged.
# Possible values: 2048, 4096, 8192, 1024, 512, 256.
# prebuffer: How many milliseconds of data to keep on top of the blocksize.
nosound=false
rate=8000
blocksize=2048
prebuffer=10
[sblaster]
# sbtype: Type of sblaster to emulate.
# Possible values: sb1, sb2, sbpro1, sbpro2, sb16, none.
# sbbase: The IO address of the soundblaster.
# Possible values: 220, 240, 260, 280, 2a0, 2c0, 2e0, 300.
# irq: The IRQ number of the soundblaster.
# Possible values: 7, 5, 3, 9, 10, 11, 12.
# dma: The DMA number of the soundblaster.
# Possible values: 1, 5, 0, 3, 6, 7.
# hdma: The High DMA number of the soundblaster.
# Possible values: 1, 5, 0, 3, 6, 7.
# sbmixer: Allow the soundblaster mixer to modify the DOSBox mixer.
# oplmode: Type of OPL emulation. On 'auto' the mode is determined by sblaster type. All OPL modes are Adlib-compatible, except for 'cms'.
# Possible values: auto, cms, opl2, dualopl2, opl3, none.
# oplemu: Provider for the OPL emulation. compat or old might provide better quality (see oplrate as well).
# Possible values: default, compat, fast, old.
# oplrate: Sample rate of OPL music emulation. Use 49716 for highest quality (set the mixer rate accordingly).
# Possible values: 22050, 49716, 44100, 48000, 32000, 16000, 11025, 8000.
sbtype=sbpro1
sbbase=220
irq=7
dma=1
hdma=5
sbmixer=true
oplmode=auto
oplemu=fast
oplrate=8000
[speaker]
# pcspeaker: Enable PC-Speaker emulation.
# pcrate: Sample rate of the PC-Speaker sound generation.
# Possible values: 22050, 44100, 48000, 32000, 16000, 11025, 8000, 49716.
# tandy: Enable Tandy Sound System emulation. For 'auto', emulation is present only if machine is set to 'tandy'.
# Possible values: auto, on, off.
# tandyrate: Sample rate of the Tandy 3-Voice generation.
# Possible values: 22050, 44100, 48000, 32000, 16000, 11025, 8000, 49716.
# disney: Enable Disney Sound Source emulation. (Covox Voice Master and Speech Thing compatible).
pcspeaker=true
pcrate=8000
tandy=auto
tandyrate=8000
disney=true
[joystick]
# joysticktype: Type of joystick to emulate: auto (default), none,
# 2axis (supports two joysticks),
# 4axis (supports one joystick, first joystick used),
# 4axis_2 (supports one joystick, second joystick used),
# fcs (Thrustmaster), ch (CH Flightstick).
# none disables joystick emulation.
# auto chooses emulation depending on real joystick(s).
# Possible values: auto, 2axis, 4axis, 4axis_2, fcs, ch, none.
# timed: enable timed intervals for axis. (false is old style behaviour).
# autofire: continuously fires as long as you keep the button pressed.
# swap34: swap the 3rd and the 4th axis. can be useful for certain joysticks.
# buttonwrap: enable button wrapping at the number of emulated buttons.
joysticktype=auto
timed=true
autofire=false
swap34=false
buttonwrap=true
[dos]
# xms: Enable XMS support.
# ems: Enable EMS support.
# umb: Enable UMB support.
# keyboardlayout: Language code of the keyboard layout (or none).
xms=true
ems=true
umb=true
keyboardlayout=auto
[autoexec]
# Lines in this section will be run at startup.
mount c "\Storage Card\DOSDrive\emu"
#imgmount c "\Storage Card\DOSDrive\EMU\Win98\W98.IMG" -t hdd -fs fat -size 512,63,16,518
C:
please wait .. uploading sample videos ..
Dos Game Dave
{
"lightbox_close": "Close",
"lightbox_next": "Next",
"lightbox_previous": "Previous",
"lightbox_error": "The requested content cannot be loaded. Please try again later.",
"lightbox_start_slideshow": "Start slideshow",
"lightbox_stop_slideshow": "Stop slideshow",
"lightbox_full_screen": "Full screen",
"lightbox_thumbnails": "Thumbnails",
"lightbox_download": "Download",
"lightbox_share": "Share",
"lightbox_zoom": "Zoom",
"lightbox_new_window": "New window",
"lightbox_toggle_sidebar": "Toggle sidebar"
}
http://www.youtube.com/watch?v=2L3x2_JY1O0
Dos Game Heretic + Turbo Basic 1.0 and Turbo C++
Part 1 - http://www.youtube.com/watch?v=xWi5YcwHkU4 - HERETIC
Part 2 - http://www.youtube.com/watch?v=QFiP2KmUm3I - Turbo Basic
Part 3 - http://www.youtube.com/watch?v=MQmmq-P9BXI - Turbo C++
reserved section for download links
my problem is messed up keys ie. left right up down
but so far i only tried faceoff (hockey) maybe i need to try some newer game
yeap. I hope every one can share their thoughts.
tried nhl94 runs slow as hell keys are messed up and lacking "ALT", "ALT_gr" keys
tried to edit mapper.txt but no success with keys
tried to fine tune dosbox.conf no major progress made
heretic and hexen have been released native for pocketpc
lemmings too
that's counter progressive but I accept that.
anyway, I still want to have a possibility to make DOSBOX fast when playing games.
that's counter progressive but I accept that.
anyway, I still want to have a possibility to make DOSBOX fast when playing games.
this is the best what i have made so far
dosbox runs great gameplay on faceoff is quite smooth (some video lag)
Code:
# This is the configurationfile for DOSBox 0.73.
# Lines starting with a # are commentlines.
# They are used to (briefly) document the effect of each option.
[sdl]
# fullscreen: Start dosbox directly in fullscreen.
# rotateright: Alternate screen rotation.
# mapperfile: File used to load/save the key/event mappings from.
# kbdtoolbar: First toolbar.
# gametoolbar: Second toolbar.
# settoolbar: Third toolbar. Note: frameskip and cycles values are drawn there.
# usescancodes: Avoid usage of symkeys, might not work on all operating systems.
# sensitivity: Mouse sensitivity.
# touchpadmouse: Emulate mouse with stylus moves on screen. Can fix mouse behavior in games that expect only relative mouse movement.
# clickms: When in touchpad mode, left-click is sent after single-tap. This sets the delay in milliseconds between emulated mouse button down and up events.
# rightclickdelay: Touchpad mode. If you tap and hold stylus for this milliseconds, right-click will be send instead of left. 0 to disable.
# dpadmouse: Emulate mouse with D-Pad. Make sure to set corresponding mapper values for this to work. Up, down, left and right keys are autorotated.
# forcetoolbar: Sometimes where's no space on screen to fit even a part of toolbar. This forces it to display. Also a key and a zone can be set for toggling.
# forcetransparent: Forced toolbar area, overlapping active screen part will be semitransparent.
# forcezone: X, Y, width and height of 'force toolbar display' tapzone. No spaces please. See also hand_force_tlbr setting in mapper.txt
# forceheight: Forced toolbar will have this height.
fullscreen=true
rotateright=true
mapperfile=mapper.txt
kbdtoolbar=toolbar.dbk
gametoolbar=game.dbk
settoolbar=set.dbk
usescancodes=false
sensitivity=200
touchpadmouse=true
clickms=50
rightclickdelay=700
dpadmouse=true
forcetoolbar=true
forcetransparent=false
forcezone=0,0,10,5
forceheight=12
[dosbox]
# language: Select another language file.
# machine: The type of machine tries to emulate.
# Possible values: hercules, cga, tandy, pcjr, ega, vgaonly, svga_s3, svga_et3000, svga_et4000, svga_paradise, vesa_nolfb, vesa_oldvbe.
# captures: Directory where things like wave, midi, screenshot get captured.
# memsize: Amount of memory DOSBox has in megabytes.
# This value is best left at its default to avoid problems with some games,
# though few games might require a higher value.
# There is generally no speed advantage when raising this value.
language=
machine=svga_s3
captures=capture
memsize=32
[render]
# frameskip: How many frames DOSBox skips before drawing one.
# aspect: Do aspect correction, if your output method doesn't support scaling this can slow things down!.
# scaler: Scaler used to enlarge/enhance low resolution modes. If 'forced' is appended,the scaler will be used even if the result might not be desired.
# Possible values: qvga, vga.
frameskip=3
aspect=false
scaler=vga
[cpu]
# core: CPU Core used in emulation. auto will switch to dynamic if available and appropriate.
# Possible values: full, dynamic, simple.
# cputype: CPU Type used in emulation. auto is the fastest choice.
# Possible values: auto, 386, 386_slow, 486_slow, pentium_slow.
# cycles: Amount of instructions DOSBox tries to emulate each millisecond. Setting this value too high results in sound dropouts and lags. Cycles can be set in 2 ways:
# 'fixed #number' will set a fixed amount of cycles. This is what you usually need if 'auto' fails.
# (Example: fixed 4000)
# 'max' will allocate as much cycles as your computer is able to handle
# Possible values: fixed, max.
# cycleup: Amount of cycles to increase/decrease with keycombo.
# cycledown: Setting it lower than 100 will be a percentage.
core=full
cputype=auto
cycles=max
cycleup=500
cycledown=500
[mixer]
# nosound: Enable silent mode, sound is still emulated though.
# rate: Mixer sample rate, setting any device's rate higher than this will probably lower their sound quality.
# Possible values: 22050, 44100, 48000, 32000, 16000, 11025, 8000, 49716.
# blocksize: Mixer block size, larger blocks might help sound stuttering but sound will also be more lagged.
# Possible values: 2048, 4096, 8192, 1024, 512, 256.
# prebuffer: How many milliseconds of data to keep on top of the blocksize.
nosound=false
rate=8000
blocksize=2048
prebuffer=10
[sblaster]
# sbtype: Type of sblaster to emulate.
# Possible values: sb1, sb2, sbpro1, sbpro2, sb16, none.
# sbbase: The IO address of the soundblaster.
# Possible values: 220, 240, 260, 280, 2a0, 2c0, 2e0, 300.
# irq: The IRQ number of the soundblaster.
# Possible values: 7, 5, 3, 9, 10, 11, 12.
# dma: The DMA number of the soundblaster.
# Possible values: 1, 5, 0, 3, 6, 7.
# hdma: The High DMA number of the soundblaster.
# Possible values: 1, 5, 0, 3, 6, 7.
# sbmixer: Allow the soundblaster mixer to modify the DOSBox mixer.
# oplmode: Type of OPL emulation. On 'auto' the mode is determined by sblaster type. All OPL modes are Adlib-compatible, except for 'cms'.
# Possible values: auto, cms, opl2, dualopl2, opl3, none.
# oplemu: Provider for the OPL emulation. compat or old might provide better quality (see oplrate as well).
# Possible values: default, compat, fast, old.
# oplrate: Sample rate of OPL music emulation. Use 49716 for highest quality (set the mixer rate accordingly).
# Possible values: 22050, 49716, 44100, 48000, 32000, 16000, 11025, 8000.
sbtype=sbpro1
sbbase=220
irq=7
dma=1
hdma=5
sbmixer=true
oplmode=auto
oplemu=fast
oplrate=8000
[speaker]
# pcspeaker: Enable PC-Speaker emulation.
# pcrate: Sample rate of the PC-Speaker sound generation.
# Possible values: 22050, 44100, 48000, 32000, 16000, 11025, 8000, 49716.
# tandy: Enable Tandy Sound System emulation. For 'auto', emulation is present only if machine is set to 'tandy'.
# Possible values: auto, on, off.
# tandyrate: Sample rate of the Tandy 3-Voice generation.
# Possible values: 22050, 44100, 48000, 32000, 16000, 11025, 8000, 49716.
# disney: Enable Disney Sound Source emulation. (Covox Voice Master and Speech Thing compatible).
pcspeaker=true
pcrate=8000
tandy=auto
tandyrate=8000
disney=true
[joystick]
# joysticktype: Type of joystick to emulate: auto (default), none,
# 2axis (supports two joysticks),
# 4axis (supports one joystick, first joystick used),
# 4axis_2 (supports one joystick, second joystick used),
# fcs (Thrustmaster), ch (CH Flightstick).
# none disables joystick emulation.
# auto chooses emulation depending on real joystick(s).
# Possible values: auto, 2axis, 4axis, 4axis_2, fcs, ch, none.
# timed: enable timed intervals for axis. (false is old style behaviour).
# autofire: continuously fires as long as you keep the button pressed.
# swap34: swap the 3rd and the 4th axis. can be useful for certain joysticks.
# buttonwrap: enable button wrapping at the number of emulated buttons.
joysticktype=none
timed=true
autofire=false
swap34=false
buttonwrap=true
[dos]
# xms: Enable XMS support.
# ems: Enable EMS support.
# umb: Enable UMB support.
# keyboardlayout: Language code of the keyboard layout (or none).
xms=true
ems=true
umb=true
keyboardlayout=auto
[autoexec]
# Lines in this section will be run at startup.
mount c "\Storage Card\"
c:
hi
Nullstring said:
Dos Game Dave
http://www.youtube.com/watch?v=2L3x2_JY1O0
Dos Game Heretic + Turbo Basic 1.0 and Turbo C++
Part 1 - http://www.youtube.com/watch?v=xWi5YcwHkU4 - HERETIC
Part 2 - http://www.youtube.com/watch?v=QFiP2KmUm3I - Turbo Basic
Part 3 - http://www.youtube.com/watch?v=MQmmq-P9BXI - Turbo C++
Click to expand...
Click to collapse
whether it will work for htc hd2
indycar said:
my problem is messed up keys ie. left right up down
but so far i only tried faceoff (hockey) maybe i need to try some newer game
Click to expand...
Click to collapse
I'm not sure about the X1, but on the LG Fathom, you just need to edit MAPPER.TXT in the DOSBOX folder and swap key_up, key_down etc
- so I think I'm right in saying that you need to swap
key_up <> key_right
key_down <> key_left
key_left <> key_up
key_right <> key_down
I know this post is from a while back, but I just want to post that for anyone looking. I am going to use Windows Mobile as long as I can and I hope others will continue to use it too!

MortScripts to toggle settings

This thread is dedicated to MortScripts that we use to change settings. Most of these can be stand alone scripts, but I got started creating this thread based on CHTS needing WMLongLife to change from Automatic to GSM radio profile. I found that WMLL seemed to eat up battery life in my old Fuze. I tried a script or two from the MortScript examples thread, but they did not work for me. I'll be posting various scripts that I use during my profile changes in CHTS, but I will in such a way that if you do not use CHTS you can still use the scripts.
Another purpose of this thread is to make these scripts available to those who for one reason or another the default programs in CHTS do not work and perhaps the script will. An example is sound profile changing to Automatic was not available so I added a script to do it for me. The feature had been turned off since it did not work in all phones. In a coming version I believe it will be back. The beta test works in my Fuze.
The hope of this thread is to help those that use CHTS to get some of the features that may not work on their phone through MortScripts instead. Also, as a place to share these "TOGGLE" switch scripts for others to be able to use outside CHTS.
I am trying to write scripts that do not use programs outside windows mobile. The hope is that they can be used in as many phones and ROMs as possible. An example is the first form of my Band_Changer used a program in CHTS and I reworked it to not require that program.
Radio toggle between Automatic (2G & 3G) and GSM (2G only): Post #2
Switch Sound Profile: Post #3
Auto time zone toggle: Post #5 and Post #8
Toggle Backlight: Post #14
Toggle Screen Rotation: Post #15
Toggle between Active Sync and Mass Storage: Post #16
Toggle Voice Command: Post #17
Radio toggle between Automatic (2G & 3G) and GSM (2G only)
This script calls the main script with the argument required based on your current profile to switch the profile to the other.
Code:
# Band_Toggle.mscr
opmode = RegRead( "HKLM","Software\OEM\UMTS","OpMode")
opmode = RegRead( "HKLM","Software\OEM\PhoneSetting\NetworkType","ItemName" & OpMode + 1)
If(opmode eq "Auto")
key = "g"
Else
key = "a"
EndIf
CallScript("\storage card\scripts\Band_Changer.mscr", key)
# CallScript("\windows\Band_Changer.mscr", key)
I test the script in my storage card, but when I use it for CHTS I would have it in \windows folder.
This is the main script:
Code:
# Band_Changer.mscr
If(NOT FileExists("\Windows\CMBandSwitching.exe"))
Message("You must have CMBandSwitching.exe installed in windows folder.^NL^^NL^Script will exit now.", "ERROR")
Exit
EndIf
key = argv[1]
key = (key eq "a")?"Auto":"GSM"
opmode = RegRead( "HKLM","Software\OEM\UMTS","OpMode")
opmode = RegRead( "HKLM","Software\OEM\PhoneSetting\NetworkType","ItemName" & OpMode + 1)
network1 = RegRead( "HKLM","Software\OEM\PhoneSetting\NetworkType","ItemName1" )
network2 = RegRead( "HKLM","Software\OEM\PhoneSetting\NetworkType","ItemName2" )
network3 = RegRead( "HKLM","Software\OEM\PhoneSetting\NetworkType","ItemName3" )
If(key ne OpMode)
If(key eq network1)
key = 1
ElseIf(key eq network2)
key = 2
ElseIf(key eq network3)
key = 3
Else
EndIf
Call("switcher")
EndIf
Sub switcher
Global(key)
SendSpecial(126) # Data disconnect
i=0
ForEach xvariable in regSubkeys("HKLM", "Comm\ConnMgr\Providers\{7C4B7A38-5FF7-4bc1-80F6-5DA7870BB1AA}\Connections")
i+=1
enable[i] = RegRead("HKLM", "Comm\ConnMgr\Providers\{7C4B7A38-5FF7-4bc1-80F6-5DA7870BB1AA}\Connections" \ xvariable, "Enabled")
EndForEach
Sleep(500)
ForEach xvariable in regSubkeys("HKLM", "Comm\ConnMgr\Providers\{7C4B7A38-5FF7-4bc1-80F6-5DA7870BB1AA}\Connections")
RegWriteDWord("HKLM", "Comm\ConnMgr\Providers\{7C4B7A38-5FF7-4bc1-80F6-5DA7870BB1AA}\Connections" \ xvariable, "Enabled", 0)
EndForEach
Sleep(500)
Run("\Windows\CMBandSwitching.exe")
If(ScreenHeight() eq 640)
Y1 = 160 # 1st button which is Auto on my Fuze 163
Y2 = 245 # 2nd button which is GSM on my Fuze 244
Y3 = 315 # 3rd button which is WCDMA on my Fuze 314
Y4 = 610 # Done button on my Fuze 608
X4 = 135 # Done button on my Fuze 134
Y5 = 460 # Done button on my Fuze 460
X5 = 125 # Done button on my Fuze 125
ElseIf(ScreenHeight() eq 800)
Y1 = 150 # 1st button which is Auto on HD2 150
Y2 = 200 # 2nd button which is GSM on HD2 200
Y3 = 305 # 3rd button which is WCDMA on HD2 305
Y4 = 750 # Done button on HD2 750
X4 = 110 # Done button on HD2 110
Y5 = 480 # Done button on HD2 480
X5 = 110 # Done button on HD2 110
EndIf
While(NOT WndActive("Band"))
Sleep(50)
EndWhile
If(key eq 1)
MouseClick("Band", ScreenWidth()*0.25, Y1) # 1st button
ElseIf(key eq 2)
MouseClick("Band", ScreenWidth()*0.25, Y2) # 2nd button
Else
MouseClick("Band", ScreenWidth()*0.25, Y3) # 3rd button
EndIf
Sleep(150)
SendSpecial(112) # Done
Sleep(500)
i=0
ForEach xvariable in regSubkeys("HKLM", "Comm\ConnMgr\Providers\{7C4B7A38-5FF7-4bc1-80F6-5DA7870BB1AA}\Connections")
i+=1
RegWriteDWord("HKLM", "Comm\ConnMgr\Providers\{7C4B7A38-5FF7-4bc1-80F6-5DA7870BB1AA}\Connections" \ xvariable, "Enabled", enable[i])
EndForEach
Sleep(20000)
If(NOT Connected())
Connect("The Internet")
EndIf
EndSub
If you do not have a 480 x 640 or 480 x 800 phone or if this does not work for you please try this script to get me the points I need to improve this script.
Code:
# PickPoints.mscr
Run("\Windows\CMBandSwitching.exe")
WaitForActive("Band", 10)
Sleep(300)
SleepMessage( 2, "Select center of first (top) Network Type choice after this screen closes." )
Sleep(300)
aMouse = ScreenshotClick()
sMSGOutput1 = "^NL^First:^NL^X1 = " & aMouse[1] &"^NL^Y1 = " & aMouse[2]
SleepMessage( 2, "Select center of second (middle) Network Type choice after this screen closes." )
Sleep(300)
aMouse = ScreenshotClick()
sMSGOutput2 = "^NL^Second:^NL^X2 = " & aMouse[1] &"^NL^Y2 = " & aMouse[2]
SleepMessage( 2, "Select center of third (bottom) Network Type choice after this screen closes." )
Sleep(300)
aMouse = ScreenshotClick()
sMSGOutput3 = "^NL^Third:^NL^X3 = " & aMouse[1] &"^NL^Y3 = " & aMouse[2]
Sleep(300)
MouseClick("Band", aMouse[1], aMouse[2])
Sleep(300)
SleepMessage( 2, "Select center of Done button after this screen closes." )
Sleep(300)
aMouse = ScreenshotClick()
sMSGOutput4 = "^NL^Done:^NL^X4 = " & aMouse[1] &"^NL^Y4 = " & aMouse[2]
Sleep(300)
MouseClick("Band", aMouse[1], aMouse[2])
Sleep(1500)
SleepMessage( 2, "Select center of OK button after this screen closes." )
Sleep(300)
aMouse = ScreenshotClick()
sMSGOutput5 = "^NL^OK:^NL^X5 = " & aMouse[1] &"^NL^Y5 = " & aMouse[2]
SleepMessage( 2, "Select center of Cancel button after this screen closes." )
Sleep(3000)
WriteFile("\band_click.txt", "Screen width: " & ScreenWidth() & "^NL^Screen height: " & ScreenHeight() & sMSGOutput1 & sMSGOutput2 & sMSGOutput3 & sMSGOutput4 & sMSGOutput5)
Message("Please send me these data. They are saved in root directory \band_click.txt^NL^")
Remove the .txt from the end of the script files.
Switch Sound Profile
These scripts call the main script with the argument for the profile you want.
Code:
# Sound_Automatic.mscr
CallScript("\Windows\Sound_Profile.mscr", "Automatic")
Code:
# Sound_Normal.mscr
CallScript("\Windows\Sound_Profile.mscr", "Normal")
Code:
# Sound_Silent.mscr
CallScript("\Windows\Sound_Profile.mscr", "Silent")
Code:
# Sound_Vibrate.mscr
CallScript("\Windows\Sound_Profile.mscr", "Vibrate")
This is the main script:
Code:
# Sound_Profile.mscr
# Change Sound Profile based on argument used to call this script from
# a short script in the form:
# CallScript("\Windows\Sound_Profile.mscr", "Automatic")
mode=argv[1]
If(mode EQ "Automatic")
RegWriteString("HKCU", "ControlPanel\Profiles", "ActiveProfile", "Automatic")
SendMessage("", 1156, 0, 0)
ElseIf(mode EQ "Normal")
RegWriteString("HKCU", "ControlPanel\Profiles", "ActiveProfile", "Normal")
SendMessage("", 1156, 0, 0)
ElseIf(mode EQ "Silent")
SendMessage("", 1156, 3, 0)
ElseIf(mode EQ "Vibrate")
SendMessage("", 1156, 2, 0)
Else
EndIf
In CHTS profile switching I use the Execute/Kill App(s) section with the executable as \windows\mortscript.exe and the argument one of these four:
\Windows\Sound_Profile.mscr Automatic
\Windows\Sound_Profile.mscr Normal
\Windows\Sound_Profile.mscr Silent
\Windows\Sound_Profile.mscr Vibrate
Remove the .txt from the end of the script files.
This isn't written as a toggle, but these scripts will turn off or on the auto-time zone sync option in phone settings. Turning it off helps to keep active sync from running all the time.
Code:
#Auto time zone off
RegWriteDWord("HKLM","\Drivers\BuiltIn\RIL","NITZEnable",0)
Code:
#Auto time zone on
RegWriteDWord("HKLM","\Drivers\BuiltIn\RIL","NITZEnable",1)
Auto time zone toggle
Thanks Farmer Ted
It is easy enough to create a toggle.
Code:
If(RegRead("HKLM","\Drivers\BuiltIn\RIL","NITZEnable"))
RegWriteDWord("HKLM","\Drivers\BuiltIn\RIL","NITZEnable",0) #Auto time zone off
Else
RegWriteDWord("HKLM","\Drivers\BuiltIn\RIL","NITZEnable",1) #Auto time zone on
EndIf
Thx RoryB... toggle features are good... if you can store all here.. it must be a good base to share with communauty !
great job my friend! especially after the long test time in beta group to fulfill different device's needs.
this is the perfect extension for the post-run-scripts while profile switching.
I'm looking forward to much more of this scripts, which can be used.
Thanx also in name of all CHTS-users
Micha
RoryB said:
Thanks Farmer Ted
It is easy enough to create a toggle.
Click to expand...
Click to collapse
Cool, that was a lot simpler than if I'd done it, lol. Here's the same script, with message boxes to let you know what the setting is.
Code:
If(RegRead("HKLM","\Drivers\BuiltIn\RIL","NITZEnable"))
RegWriteDWord("HKLM","\Drivers\BuiltIn\RIL","NITZEnable",0) #Auto time zone off
Message("Active Sync under control")
Else
RegWriteDWord("HKLM","\Drivers\BuiltIn\RIL","NITZEnable",1) #Auto time zone on
Message("Active Sync running wild")
EndIf
LOL I love a sense of humor.
I updated post #2 for the Band Changer because I have been getting failed to connect or dialed modem not answering error messages.
RoryB said:
I updated post #2 for the Band Changer because I have been getting failed to connect or dialed modem not answering error messages.
Click to expand...
Click to collapse
Made another tweak to stop data connection first.
Updated Post #2 for Band_Changer.mscr. It seems to run a little faster.
On Band_Changer I realized that
Code:
Y1 = 150 # 1st button which is Auto on HD2 150
Y2 = 215 # 2nd button which is GSM on HD2 200
Y3 = 300 # 3rd button which is WCDMA on HD2 305
works in my phone too. So I would not need to check the screen size, but I am running Energy ROM that is a WVGA with tweaks to work on my VGA. I need to get some pick point data from anyone who uses a true VGA ROM in their phone to confirm the points for it. Also, a screen shot of CMBandSwitcher.exe would help a lot.
If CMBandSwitcher.exe has the same screen size for WVGA and VGA phones I will be able to reduce the code some more.
Toggle Backlight
From http://forum.xda-developers.com/showpost.php?p=2018165&postcount=239
Code:
#toggle backlight between max and one-from-minimum (on trinity at least)
CurrentBright = RegRead( "HKCU", "ControlPanel\Backlight", "Brightness" )
If (CurrentBright = 1)
SetBacklight (100, 5)
Else
SetBacklight (1, 1)
EndIf
Toggle Screen Rotation
From http://forum.xda-developers.com/showpost.php?p=2832605&postcount=929
Code:
If (regread("HKLM", "System\GDI\ROTATION", "ANGLE") eq 0)
Rotate (90)
Else
Rotate (0)
Endif
Toggle between Active Sync and Mass Storage
From http://forum.xda-developers.com/showpost.php?p=5078802&postcount=2552
Code:
usb = RegRead ( "HKLM", "Drivers\USB\FunctionDrivers", "DefaultClientDriver" )
If ( usb eq "RNDIS" )
Run ( "\Windows\USBSetting.exe" )
Sleep ( 200 )
SendSpecial ( "Down" )
Sleep ( 50 )
SendSpecial ( "CR" )
Sleep ( 50 )
SendOK
ElseIf ( usb eq "Mass_Storage_Class" )
Run ( "\Windows\USBSetting.exe" )
Sleep ( 200 )
SendSpecial ( "Up" )
Sleep ( 50 )
SendSpecial ( "CR" )
Sleep ( 50 )
SendOK
EndIf
Toggle Voice Command
I only use Voice Command when I am driving so I toggle it off when I am not driving to save battery drain.
Code:
ShowWaitCursor
If( ProcExists( "VoiceCmd.exe" ) )
Kill( "VoiceCmd.exe" )
PlaySound( "Stopping" )
HideWaitCursor
SleepMessage( 2, "Voice Command^NL^^NL^Stopped", "Voice Command Toggle" )
Delete( "\Windows\Startup\Voice Command.lnk" ) # so it will not restart after a soft reset
else
Run( "\Program Files\Voice Command\VoiceCmd.exe" )
PlaySound( "Starting" )
HideWaitCursor
SleepMessage( 2, "Voice Command^NL^^NL^Started", "Voice Command Toggle" )
Endif
Sad to go
My Fuze no longer works. I currently have a loner Infuse 4G, but do not know what I will end up with.
I will not be able to continue development of Mortscripts, etc.
Sorry to go, but it has been fun.
I'll keep watching to see if anything comes up I need to respond to.

How make HELLO WORLD on the WM6.1 ???

Who can write Step by Step instruction by C++/VisualStudio 2008 ? for writing Hello World apps And simple actions of work with forms???
You can start here...http://www.hitmill.com/programming/cpp/helloWorld.htm
Remember a search engine is your friend.
Hope that I have help you.
In C++ you have the choice of WIN 32, ATL and MFC programming models. They are all different.
If you are using standard windows forms items ie buttons, editboxes, dropdowns etc. C# is a LOT easier.
stephj said:
If you are using standard windows forms items ie buttons, editboxes, dropdowns etc. C# is a LOT easier.
Click to expand...
Click to collapse
It is indeed much easier for "Hello World" type applications. For more complicated things, poor performance and lack of direct access to the native API begins to add up.
The original poster probably has some specific problem, the solution to which he hopes to find in a step-by-step tutorial. If he still has not been able to solve it, it might help to describe it to us.
O.K........
Over the next few posts, (Rome wasn't built in a day!), this will build into a step by step tutorial in how to create a basic WIN32 application. As a start we will use the C# .Net solution I wrote in reply to this post:
http://forum.xda-developers.com/showthread.php?t=1435629
The original request was for an application that calculates the check digit for an intermodal container number. For the uninitiated, intermodal containers are the ubiquitous 20ft and 40ft metal boxes that dominate the shipping industry.
All containers have an eleven digit serial number of the form:
ABCD 123456 7
Where ABC is the code for the container's owner, and D is the Category Identifier, almost always a 'U'. 123456 is the serial number of the box and the final number '7' is the checksum digit which is calculated from the previous 10 characters. When keying in container numbers into computer systems etc, it can be used to quickly check whether the container number is valid before further processing is done. The same thing applies to the last digit of your credit card number, it is calculated from the previous 15 numbers.
Container numbers conform to ISO6346 and more can be read here http://en.wikipedia.org/wiki/ISO_6346
We will build a WIN32 C++ Mobile 6 application to calculate the check digit from those given in a text box on the screen.
Validation will be minimal, if the user enters anything but characters of the form AAAA999999 in the textbox, nothing appears in the check digit box. When valid, the checkdigit magically appears.
You will need:- Visual Studio Professional 2008, not the express version, and an installed Windows Mobile 6.0 SDK
The Express version of VS cannot target mobile devices. VS 2003/5 can also be used, as well as earlier or later versions of the SDK, but you will encounter slight differences in VS or the SDK, that you will have to fight your way through yourself.
The finished application will look something like the attached image.
Under Win32, there is no drag and drop toolbox, all controls have to be created from scratch. All good fun, so roll up your sleeves, break out the birch twigs and let the self-flagellation begin.......
Right!.....Let's go............
From VS2008 select
File -> New -> Project
Select C++, Smart Device and Win32 Smart Device Project. Select the destination for the project and name it IS06346. See image 01.
Click OK
On the Platforms submenu of the next screen add the Windows Mobile 6.0 SDK to the project and remove the others. See image 02
........and, on the 'Application Settings' submenu, make sure the Windows Application radio button is on, and all others are off. See image 03
Click Finish. The VS wizard will create all the basic files we need under the directory given above.
In fact, pressing F5 should build this project and run it in the emulator. The application does very little at this stage, nothing to be precise, but it should work........... See 04
The main program is ISO3486.cpp This shell program is some 250 lines of code, most of it is needed for a "do nothing" program, but it boils down into five main functions.
WinMain() The entry point of the program, where the operating system will call it on initial load. Leave it alone.
InitInstance() Called immediately by WinMain and where the program creates its initial window etc. We will add a few bits of extra initialization here.
MyRegisterClass() Called by InitInstance to register the window class, just before the initial window is created. Leave it alone unless you really know what you are doing.
WndProc() The message processing loop for the main/parent window. Any windows event will be fired at this function as a Windows Message, it is up to us to process the ones we need. A few variables will go in here. All the original WM2003 "Hello World" program did, in the EVC based SDK, was to intercept the WM_PAINT message, find the client area of the screen, and draw the text "Hello World" in the middle of it.
About() The message processing loop for the About dialog box. We will be quite happy with the default action so we'll leave it alone.
To Do:
1.) Add reference to <string.h>
2.) Create two text boxes and display them. Limit the entry to 10 characters on the main edit box and disable input on the second check digit box.
3) Draw an "Enter container number:" text label above the edit boxes in response to the WM_PAINT message. The edit boxes will draw themselves when required.
4.) Intercept the EN_CHANGE message from the main edit box. If the length of the text in the box is 10 characters long, uppercase it, and if it is valid, generate the checksum and display it in the checksum box, otherwise clear the checksum box. Replace the textbox text with its uppercase value, but do not respond the the EN_CHANGE message generated by this change, as this will trigger an infinite shower of EN_CHANGE messages.
When this is done, we will have a working application.
To be continued.....................
Next...........
Let’s work our way down the TODO: list above.
1.) Add reference to “string.h”:
Later on we are going to use a call to towupper() to convert the input into uppercase. It is defined in string.h, so we have to add this to the source file.
At the top of the ISO6346.CPP after the line
Code:
#include "ISO6346.h"
Add the line:
Code:
#include "string.h"
2.) Create two text boxes and display them......
We will create two windows as text boxes, but we will save their handles as global variables as they are referenced from more than one function. While we are at it we also need a global Boolean variable to prevent the uppercased replacement from causing the runaway reaction mentioned above.
After:
Code:
HINSTANCE g_hInst; // current instance
HWND g_hWndMenuBar; // menu bar handle
Add:
Code:
HWND g_hWndText,g_hWndCheck;
bool g_Updating;
Now let’s create the text edit boxes. You may already know this, or this may be an eye opener, but all edit controls are actually windows in their own right, albeit that they are child windows of the main form.
In InitInstance() after:
Code:
if (!hWnd)
{
return FALSE;
}
add:
Code:
g_hWndText= CreateWindow(TEXT("EDIT"),NULL,WS_CHILD | WS_BORDER,40,50,110,20,hWnd,NULL,hInstance,NULL);
g_hWndCheck=CreateWindow(TEXT("EDIT"),NULL,WS_CHILD | WS_BORDER, 160,50,20,20,hWnd,NULL,hInstance,NULL);
This creates the text edit boxes. As yet they won’t be displayed, but we have to tweak them first. We want to disable the checkdigit box, so that the user cannot type anything into it as we will set it with the correct value when a valid container number is entered in the text box. We will disable it by calling the EnableWindow() function.
We also need to set the size of the text edit window to 10 characters. Under MFC and .NET this is a hoot, as it already a property of the edit control object, which has been conveniently wrappered for us, and we can just set that property. Here in the world of Win32, it is not quite so simple. We have to fire an EM_SETLIMITTEXT message at the window, to tell it that that is what we want. While we are at it, let's set the global g_Updating variable to be false, ready for use later, and here is as good a place as any to do it.
After the CreateWindow() lines we have just added, add the next three lines to do the above.
Code:
SendMessage(g_hWndText,EM_SETLIMITTEXT,10,0);
EnableWindow(g_hWndCheck,false);
g_Updating=false;
Now the windows exist as we want them, all we have to do is display them. At the bottom of the InitInstance() function after
Code:
ShowWindow(hWnd, nCmdShow);
add
Code:
ShowWindow(g_hWndText, nCmdShow);
ShowWindow(g_hWndCheck, nCmdShow);
The main window will now look after them and control them as required. Marvellous!
3) Draw an "Enter container number:" text label............
Now we need a label above the two boxes to tell the user to type a valid container number number into the text box. From the resource view of the project, open the String Table folder in ISO6346ppc.rc then open the String Table object. Click in the blank entry at the bottom and change the ID to IDS_ENTER and the Caption to "Enter container number:" Don't worry about the what the value is, if it is not '3', as the IDE will take care of it.
To get it drawn on the form, we will have to add it to the WM_PAINT event of the main window. We'll need a RECT structure to describe where we want the text to go, a buffer to store the string and while we are here let's add the function variables we are going to need later. At the top of the WndProc() function:
After:
Code:
int wmId, wmEvent;
PAINTSTRUCT ps;
HDC hdc;
add
Code:
TCHAR c,szBuffer[MAX_LOADSTRING];
RECT rt;
int i,j,k;
bool valid;
i,j and k are general variables for calculating the check digit. szBuffer is used to hold the "Enter container number:" string in WM_PAINT, and also for the contents of the edit box when it changes. As these two events will not occur at the same time, we can get away with it having a dual personality. Variable 'c' is used to read the string one character at a time and 'valid' is set to false if the the container number is not in the correct format.
Replace the TODO: line in the WM_PAINT handler
Code:
// TODO: Add any drawing code here...
with:
Code:
rt.top=20;
rt.bottom=40;
rt.left=40;
rt.right=180;
LoadString(g_hInst,IDS_ENTER,szBuffer,MAX_LOADSTRING);
DrawText(hdc,szBuffer,wcslen(szBuffer),&rt,0);
Now when the form is drawn, the label will appear in the right place.
4.) Intercept the EN_CHANGE message from the main edit box..........
There is no easy way to do the next bit step-by-step, so we will just do it, I'll explain later.........
Replace the standard code for the response to the WM_COMMAND message:
Code:
case WM_COMMAND:
wmId = LOWORD(wParam);
wmEvent = HIWORD(wParam);
// Parse the menu selections:
switch (wmId)
{
case IDM_HELP_ABOUT:
DialogBox(g_hInst, (LPCTSTR)IDD_ABOUTBOX, hWnd, About);
break;
case IDM_OK:
SendMessage (hWnd, WM_CLOSE, 0, 0);
break;
default:
return DefWindowProc(hWnd, message, wParam, lParam);
}
break;
with this:
Code:
case WM_COMMAND:
wmId = LOWORD(wParam);
wmEvent = HIWORD(wParam);
// Parse the menu selections:
switch (wmId)
{
case IDM_HELP_ABOUT:
DialogBox(g_hInst, (LPCTSTR)IDD_ABOUTBOX, hWnd, (DLGPROC)About);
break;
case IDOK:
SendMessage (hWnd, WM_CLOSE, 0, 0);
break;
}
switch (wmEvent)
{
case EN_CHANGE:
if(g_hWndText == (HWND) lParam && !g_Updating)
{
GetWindowText(g_hWndText, szBuffer,MAX_LOADSTRING);
if(wcslen(szBuffer)==10)
{
k=0;
valid=true;
for(i=0; i<10; i++)
{
c=szBuffer[i]=towupper(szBuffer[i]);
if((i<4 && (c<'A' || c>'Z')) || (i>3 && (c<'0' || c>'9')))
valid = false;
j=int(c);
if (j > 64 && j < 91)
k += ((j - 55) + (j - 56) / 10) << i;
else
k += (j - 48) << i;
}
if(valid)
{
// Calculate final check digit
k = ((k % 11) % 10);
// Do not process the following update
g_Updating = true;
SetWindowText(g_hWndText,szBuffer);
g_Updating = false;
// Set check window to correct value
szBuffer[0]='0'+k;
szBuffer[1]='\0';
SetWindowText(g_hWndCheck,szBuffer);
// Position cursor at end of edit field.
SendMessage(g_hWndText,EM_SETSEL,10,10);
}
else
SetWindowText(g_hWndCheck,TEXT(""));
}
else
SetWindowText(g_hWndCheck,TEXT(""));
}
break;
default:
return DefWindowProc(hWnd, message, wParam, lParam);
}
break;
When the text edit box contents are changed, a EN_CHANGE message arrives at the parent window. It appears as a WM_COMMAND message with the wmEvent parameter containing the EN_CHANGE identifier, together with the handle of the window that generated the message. That is why the second 'switch' code exists to trap the EN_CHANGE event message.
If the EN_CHANGE message came from the Text edit window, not the Checksum window, then get the text within it. If the length is 10 characters long, then process the string. The variable k is used as a running total for the checksum. If after processing all 10 characters, the string is still valid, it is converted modulo 11 and then modulo 10 into the final checksum number. The checksum edit box is then updated with this value. The contents of the Edit box are replaced with its uppercase value. In doing so, we will cause another EN_CHANGE message to be sent to the parent window, which would cause this function to be executed again, and so on and so forth, causing an infinite shower of messages. To prevent this, we set the global variable g_Updating to true before making the change, and then setting it to false immediately afterwards. The test in the first line of the EN_CHANGE processing code, does not execute at all if g_Updating is true, thereby preventing this problem.
Build the final program, and test it in the emulator. Switch the build to 'Release' and the target to Windows Mobile Device, and run the executable on your device.
The complete ISO6346.cpp file is included in the attached zip file.
Here endeth the lesson...........
As a continuation, we will build the whole thing again from scratch, but next time using the Microsoft Foundation Class, MFC.
Watch this space..................
Don Reba said:
It is indeed much easier for "Hello World" type applications. For more complicated things, poor performance and lack of direct access to the native API begins to add up.
Click to expand...
Click to collapse
I totally agree with this! And worst thing is you can neither use a resource hacker tool nor a dependency walker tool, if you want to inspect a .NET CF application.
Using MFC......
From VS2008 as before select File->New->Project then select Visual C++, Smart Device, and MFC Smart Device Application.
Name it ISO6346 as before, and click OK. See image 01
On the platforms submenu select the Windows Mobile 6.0 SDK as before. See image 02
On the Application Type submenu, select the "Dialog Based" and "Use MFC in a static Library" radio buttons. See Image 03
By default the application comes with two dialog boxes for portrait and landscape but in our case this is complete overkill. We will get rid of the Landscape (Wide) dialog box.
In the Dialog folder of the resource view of ISO6346ppc.rc, delete the IDD_ISO6346_DIALOG_WIDE entry. See image 04.
To get this past the compiler, we will have to tidy it up a bit. In ISO6346Dlg.cpp delete the following sections of code.
Code:
#if defined(_DEVICE_RESOLUTION_AWARE) && !defined(WIN32_PLATFORM_WFSP)
void CISO6346Dlg::OnSize(UINT /*nType*/, int /*cx*/, int /*cy*/)
{
if (AfxIsDRAEnabled())
{
DRA::RelayoutDialog(
AfxGetResourceHandle(),
this->m_hWnd,
DRA::GetDisplayMode() != DRA::Portrait ?
MAKEINTRESOURCE(IDD_ISO6346_DIALOG_WIDE) :
MAKEINTRESOURCE(IDD_ISO6346_DIALOG));
}
}
#endif
and also:
Code:
#if defined(_DEVICE_RESOLUTION_AWARE) && !defined(WIN32_PLATFORM_WFSP)
ON_WM_SIZE()
#endif
Double Click in the IDD_ISO6346_DIALOG entry to open it up in the main window. Click on the "TODO: Place dialog controls here" label and change its caption to "Enter container number:", and position it near the top of the dialog box. From the Toolbox view, drop two edit controls on to the dialog box, under the above label. See image 05. Right click on the first box and select Add Variable. Name the first box edtText and click Finish. See image 06. Do the same for the second box and name it edtCheck. Notice that the wizard has added entries for the DoDataExchange(CDataExchange* pDX) function.
In OnInitDialog() after the line
Code:
// TODO: Add extra initialization here
Add:
Code:
Updating=false;
edtText.LimitText(10);
edtCheck.SetReadOnly();
Note that an Edit Control has more useful methods to call than the Win32 method above, where setting the text limit of the control has to be done by sending windows messages to it.
Right click on the Text Edit Box control and select "Add event handler..." select the EN_CHANGE message, take the default event handler function name, and click the "Add and Edit" button. See image 07 In ISO6346Dlg.h notice that the wizard has added the two edit boxes at the bottom of the file, and also added the message map thus:
Code:
public:
CEdit edtText;
CEdit edtCheck;
afx_msg void OnEnChangeEdit1();
In the //Implementation section of the same file after
Code:
HICON m_hIcon;
add:
Code:
bool Updating;
This will be used as before to prevent an infinite cascade of messages.
In the OnChangeEdit1() function add the following code:
Code:
int i,j,k;
wchar_t c;
bool valid;
CString strText,strCheck;
if(!Updating)
{
if(edtText.LineLength(0)==10)
{
edtText.GetLine(0,strText.GetBuffer(10),10);
strText.ReleaseBuffer(-1);
strText.MakeUpper();
k=0;
valid = true;
// Check the contents are of the form ABCD123456
for(i=0; i<10; i++)
{
c=strText.GetAt(i);
j=int(c);
if((i<4 && (c<'A' || c>'Z')) || (i>3 && (c<'0' || c>'9')))
valid = false;
if (j > 64 && j < 91)
k += ((j - 55) + (j - 56) / 10) << i;
else
k += (j - 48) << i;
}
if(valid)
{
// Calculate final check digit
k = ((k % 11) % 10);
strCheck.GetBufferSetLength(1);
strCheck.SetAt(0,'0'+k);
strCheck.ReleaseBuffer(-1);
edtCheck.SetWindowTextW(strCheck);
Updating = true;
// Do not process the following update
edtText.SetWindowTextW(strText);
Updating = false;
// Position cursor at end of edit field.
edtText.SetSel(10,10,0);
}
else //Invalid Not ABCD123456 - clear the check digit field
edtCheck.SetWindowTextW(TEXT(""));
}
else // Invalid - Not 10 char long - clear the check digit field
edtCheck.SetWindowTextW(TEXT(""));
}
This time we use CString objects to get/set the contents of the edit controls.
Right! That's it. Compile it and run it, either in the emulator or on the device.
See image 08. Notice that as this a dialog application, there are no menu buttons. When the [X] button is pressed the program terminates.
As another interesting point, compare the sizes of the two release executables. The Win32 version is around 8.5kb, that of the MFC version is around 167kb, both launch pretty damned quickly. Compare that with the . NET C# executable from the original post. That is around 9kb in size, but it takes your device around three seconds to shove it through the JiT compiler in order to able to run it, and that is for only a tiny .NET program.

[Q]Refreshing Zooper from SL4A

I've got a Zooper module that I'm using to control the lights in my apartment. I'm calling SL4A scripts from Zooper that call an API running on a webserver to toggle the lights. I'm using wget with #SEX# in zooper to query the status of the lights off my server.
The problem I'm having is that I can't update the widget after the lights toggle. I did just start playing with it today, but I'm not seeing any means to do this from SL4A.
I'm using Python in SL4A.
Edit: I tried sending an intent to Zooper to set an unused variable from SL4A, though I don't think it's sending right.
Code:
activity = 'org.zooper.zw.action.TASKERVAR'
extras = {}
extras['org.zooper.zw.tasker.var.extra.STRING_VAR'] = '#Ta#'
extras['org.zooper.zw.tasker.var.extra.STRING_TEXT'] = 'a'
extras['org.zooper.zw.tasker.var.extra.INT_VERSION_CODE'] = '1'
packagename = 'org.zooper.zw'
classname = 'org.zooper.zw.tasker.var.extra.BUNDLE'
intent = droid.makeIntent(activity, None, None, extras, None, packagename, classname).result
droid.sendBroadcastIntent(intent)

Categories

Resources