Hallo!
I'm working on an application called hTorch and although it is my first vb.net app I was quite successfull so far (at least I hope so ). But one think I'm just not able to achieve: Preventing the device from going into standby/suspend while the app is running.
In C++/C# there semes to be a system call "SystemIdleTimerReset()" but either there is no equivalent for vb.net or I was not able to find it.
Another thought was to modify the according registry key (HKLM\System\CurrentControlSet\Control\Power\Timeouts\BattSuspendTimeout) and to restore the original settings on program exit. This works fine except that WM does not apply the settings change immediately when it's done via registry. Again I did some research and again I only found a solution for C++/C# only. A system call named "NWUS_MAX_IDLE_TIME_CHANGED" tells the OS that the settings have changed and should be reread. I wasn't able to find something similar for vb.net though.
Does anybody know a solution for my needs?
Maybe someone could provide me with some sample code how he achieved this within vb.net?
Maybe some C++/C# programmer has build a library to access the power functions?
I would be really thankful for any help/hint you can give me!
Thanks in advance,
DeepThought
The standby mode is in the registry. Make a timer in VB.net and set it with an interval of about 5000 ms. Then make sure that ever time the timer ticks the standby mode will be disabled in the registry
Thank you for the quick response!
But the change via registry doesn't work. When I change the BattSuspendTimeout to 0 that does change the setting correctly. But they become not active. Only after a soft reset. It seems, that you somehow have to notify windows, that the settings have changed. Otherwise the will not be reread.
Any Idea how to achieve that?
I would also like to know if there is a way to prevent suspend.
I think only the pocket pc winmo versions do a real suspend where wifi and applications stop processing, and the smartphone winmo devices only kind of black the screen.
The only software I know is S2U2 which successfully can prevent "real suspend" and let e.g. my led notification work correctly.
Cause i cannot really use it on ks20 due to compatibilty issues i would be very interested in a reg hack, or (if there really is no reghack, i tried alot) some code snipets with which i could build a little app.
There's a pretty good article on CodeProject covering power.
*digs out link*
Here you go - http://www.codeproject.com/KB/mobile/WiMoPower1.aspx
It covers:
* Displaying the voltage, current, and temperature of your device's battery
* Changing the power state of hardware within the device
* Enumerating the hardware in a Windows Mobile Professional device
* Enumerating the power modes that a Windows Professional device supports
* Preventing a device from sleeping
* Toggling the state of the screen's backlight
* Waking up the machine to perform work without alerting the user or turning on the screen
[solution]
Thanks to AndyZap I can now answer the question myself
It is so simple, that I'm really ashamed now.
The magic word for me was PInvoke. Since I new the function I was searching for was an available win32 systemcall the missing link was how I can make this system call within vb.net.
So the actual solution are just two lines:
Code:
Declare Sub IdleTimerReset Lib "coredll.dll" Alias "SystemIdleTimerReset" ()
where "IdleTimerReset" is the name I've given the Sub. Which than just needs to be called like:
Code:
IdleTimerReset()
NOTE: This just resets the Idle timer once. So if you want to prevent the device from going into standby you have to reset this timer every time before it reaches the threshold. (The windows default setting is 60 seconds AFAIK).
THANK YOU AndyZap for your Help via PMail!
DeepThought
Thank you for your answer Northernmost!
I really love this community!
Related
Hi guys,
Hope this hasn't been asked before too many times. I did do a search but couldn't find anything.
I've just written a small app for ppc (works on 2002, 2003 and WM5) to act as a countdown timer. However, unless I set my Wizard to never shutdown, it turns off whilst the timer is still going.
I've had a look through the latest SDK's (I'm using Visual Studio 2005 and the latest version of the Compact .NET Framework) but can't figure out how to stop this.
The only way I can think of is to find the reg key that controls this (I assume there is one), copy it, set it to a rediculous or null value and then copy it back again on shutdown. But it seems like a god awful solution and prone to any number of errors where it doesn't get copied back.
Is there a simple ".NET" way to do this?
BTW Although I've been a developer for [cough] years, I've never written anything for PPC before.
Cheers,
Bassey
Hi
take a closer look at HKLM\System\CurrentControlSet\Control\Power. There you will find system and user idle timeouts. To prevent a PocketPC WindowsMobile system from going to sleep, you must reset the System idle timer periodically. This is done by a call to
void WINAPI SystemIdleTimerReset (void);
I think this will be the same for WinCe 3.0 up to WinCe5
If you think about a good programming starter book, I recommend Douglas Boling 'Programming Microsoft Windows CE .NET' (3rd edition). It talks about nearly everything. It is my favourite book.
regards
Josef
Thank you very much indeed. Have just ordered the book as well.
Cheers,
Bassey
Hello eveyone,
I do not know if this is the right place to post my question, if not please advice of where I should do so.
My question is the following:
Is it possible to configure WM5 registry keys so as to enable an application run in suspended mode. In other words when the PPC goes to stand-by-mode I would like my application to keep on running.
I have developed a Java application (runs with IBM J9) but when the PPC enters the suspend mode, threads pause and the application does not behave as it should do. My intention is not to completely disable suspend mode for the PPC, but just for an application (as it is possible to prevent e.g. the 'sound device' ('wav1:') from going to suspend mode, when the PPC goes to stand-by).
Thank you in advaced.
No
Read here:
http://blogs.msdn.com/windowsmobile/archive/2006/08/16/702833.aspx
and here:
http://blogs.msdn.com/windowsmobile/archive/2005/08/01/446240.aspx
Apparently, if you want your app to run, the device can't be suspended.
I'm not sure how useful this is, depending on your program, you might want to consider using notification queues to wake the PC up to run your software.
Anyway, I'm not sure how true what Setok said above, I do find many other programs that runs with my PPC is in 'suspend' mode. E.g. I've tried various timer (count down) program which seems to be able to run in background when after I press the power-button to suspend it. I wake my phone when it reaches 0. And it is done without using notification queue.
The links above certainly seem to authoritatively state that applications can't run in sleep mode, so I posted it. But hanmin's post made me wonder what was up, so I went looking. There are a few more states.
An application can use:
PowerPolicyNotify(PPN_UNATTENDEDMODE, TRUE);
to put the device in unattended mode so that it doesn't suspend. In unattended mode the backlight, LCD, and audio still turn off.
There are a couple more power states explained here:
http://blogs.msdn.com/windowsmobile/archive/2005/08/10/450186.aspx
If you do put the device in unattendedmode be sure to call
PowerPolicyNotify(PPN_UNATTENDEDMODE, FALSE)
before you exit.
I just re-read your post, you want audio on, then use ScreenOff mode. See the above link.
Good luck
Registry way....
Hello guys,
thank you very much for your concerns and details.
To tell you the truth I have read all of these in the past. And I believe that since you can program this on-the-fly probably you can do it also by altering registry keys. In other words, not do it programmatically, cause this involves writting a C program (mu application is Java). After all if you notice ....the values that you can change through you C application to alter suspend mode for you application are 'registry values'.
My application is an event calendar, that checks the time and if there is an event it notices the user. When the mobile goes to suspend mode the thread pauses and the application does not work as appropriate...Tha't why I would like to set it in the registry-stage...
If you find anything of interest I would be more that thankfull
Thank you in advanced. ;-)
Christos
Hey,
have a look at the CeSetUserNotificationEx() function and the CE_NOTIFICATION_TRIGGER structure.
This is the way MS calendar app does it on the device.
Register your exe for a special time and if in suspend mode and
the time is reached you app will bestarted. Nice or?
Infos here: http://msdn2.microsoft.com/en-us/library/ms913969.aspx
Houser
Hi all,
I recently installed Pedometer on my HTC HD (with MaryOne X0.04☻Build 23502 COM5☻Leo 1.43), but I would like to "suspend" the device, and yet let the Pedometer run in the background, so it could measure my walk distance/steps.
I am not a programmer, but I could change a few registry settings if anyone could point me in right direction...
Thanks in advance,
cheers,
Nenad
p.s. - it should be possible, how all the other "background" programs are running (the clock, the notification, the G alarm...) ?
Ok, most of you may find this totally useless as a plugin, but it was a combination of a request by user Treo_newb and a desire to create a sample plugin project that could be used as a base / example for plugin writers (I plan on doing an article on codeproject.com and this will be the source for it).
What does it do?
This plugin displays a string stored in registry.
The path is:
HKEY_CURRENT_USER\Software\RegDispPlugin
Value name: DisplayString
It checks if this string has changed several times per second when today screen is shown (as the system sends refresh message to all plugins) and displays the updated message if a change occurred.
What is it good for?
First, if you write apps using mortscript or similar like the user who requested this it will let your script display stuff on today screen.
Alternatively it could be used to mark your device today with a string that isn't as easily changed as user info.
The source is basically a skeleton plugin you can use to build your own plugin on (no license / copyright to limit you) and it already has several tricks needed for the plugin to display correctly:
VGA compatibility
Text size matching system settings
Proper header in settings dialog (like on system plugins)
Proper text color when selected (according to theme)
No blinking all today screen on change
Proper resize when switching between landscape and portrait
When I was writing my first plugin I could not find all these little fixes concentrated in a single article so I had to fish for each one as the bug reports came in.
Hope you will find this little project useful.
The plugin:View attachment RegDisplay.CAB
The source (eVC 4 project): View attachment RegDisplay.zip
Thanks for this!
Thank You Lev.
Thanks, Thanks, Thanks,
You are a legend.
I was almost through with my today plugin and was trying to figure out reading registry values and all of a sudden I get a PM from u about the plugin !!!
Very Cool !!!
OK a few questions,
1. I know that WM_TODAYCUSTOM_QUERYREFRESHCACHE is called for refreshing the today plugin, any ideas about when is it called.
I read somewhere that it was 2 seconds. Is it true?
2. I saw ur code and u have exposed CustomItemOptionsDlgProc in RegDisplay.def, but when I installed the cab file the 'options' is not enabled.
I manually changed the resistry and changed options to dword = 1 and saw ur name and email address.
u might want to enable that by default so that people can notice ur work.
I am planing a commercial release of a new project on basis of this.
Thanks again,
Shailesh
First, you're welcome.
shaileshashar:
1) I ran a debug print on this message once on an iPaq 1710 and it seems to be sent several times per second. This could differ from OS to OS or even from device to device, I am not sure.
If you need specifically timed refresh, or you have an event triggered on new data, I suggest using a timer or maybe a thread that will wait on an event. You can refresh your plugin from anywhere in code by calling InvalidateRect with your window handle.
2) I messed up the cab at first, forgetting to add the Options reg value. Then when I went to upload the fix, I couldn't access the site for about an hour (no idea why, I even rebooted the PC to Ubuntu). Should be fixed now, but I will check it later again (I have to go back to XP for that).
Good luck with your program.
Suggestion
levenum said:
First, you're welcome.
shaileshashar:
1) I ran a debug print on this message once on an iPaq 1710 and it seems to be sent several times per second. This could differ from OS to OS or even from device to device, I am not sure.
If you need specifically timed refresh, or you have an event triggered on new data, I suggest using a timer or maybe a thread that will wait on an event. You can refresh your plugin from anywhere in code by calling InvalidateRect with your window handle.
2) I messed up the cab at first, forgetting to add the Options reg value. Then when I went to upload the fix, I couldn't access the site for about an hour (no idea why, I even rebooted the PC to Ubuntu). Should be fixed now, but I will check it later again (I have to go back to XP for that).
Good luck with your program.
Click to expand...
Click to collapse
Thanks for the help, will check the fixed cab.
Also a suggestion:
A custom icon could also be incorporated. You can give a option to load a custom icon next to the text in the today plugin.
I know anybody can modify ur code and do it but still.
Actually, I probably should have mentioned this in the original post but I have no intention of adding options to this thing.
This would only complicate the code and turn it in to an actual app instead of a sample project.
But by all means feel free to make suggestions. If this thing does become popular, when I am done with my other projects (like LVMTopBat) which won't be any time soon (unfortunately) I will release a separate version of this plugin with all kinds of options that can be controlled both by user (form the options dialog) and by other apps through registry.
Maybe things like text alignment, size, bold / Italic / underlined.
P.S.
The reason I put the string this plugin loads under HKEY_CURRENT_USER instead of the HKLM where the rest of the plugin registry resides is because by default the HKEY_LOCAL_MACHINE on WM 5 and higher has a security restriction. For example you can not write to it using RAPI, only by authorized (or signed) app on the device. The HKEY_CURRENT_USER on the other hand is open for all.
levenum said:
P.S.
The reason I put the string this plugin loads under HKEY_CURRENT_USER instead of the HKLM where the rest of the plugin registry resides is because by default the HKEY_LOCAL_MACHINE on WM 5 and higher has a security restriction. For example you can not write to it using RAPI, only by authorized (or signed) app on the device. The HKEY_CURRENT_USER on the other hand is open for all.
Click to expand...
Click to collapse
Thanks for the info, I never knew that.
Thank you so much! This was exactly what I was looking for!
levenum said:
...But by all means feel free to make suggestions.
Click to expand...
Click to collapse
As a frequent mortscript user I think, this great app might be even more usefull, if the string was shown in an "allways on top" message box instead of the today screen. The Today screen might be obscured by other active windows during the scripts runtime and the plugin eats precious today screen estate also while being unused, doesn't it?
In that case (of a standalone application) I would furthermore introduce some kind of termination string (or reg. value) to end the display application.
Code:
- start mortscript
- writes first string to registry
- starts display application (run)
- updates string in registry whenever appropriate
- ...
- writes termination string to registry
-> display applications self-terminates
- ...
- end of mortscript
Honestly, I already do use something comparable with mortscript (employing a conditioned sleepmessage loop and reading from the registry too), but this could be much nicer and more elegant.
Just my 2 cents... What do you think?
I think something like that would be better implemented by the mortsrit program it self.
It could be a function like MessageBox API in windows which you could then command on and off. Having it built in would save precious resources on the device that would be wasted by having an extra app run constantly in background.
This is just my thought though.
I'd suggest contacting the developer of mortscript and discussing it with him.
levenum said:
I think something like that would be better implemented by the mortsrit program it self.
...
I'd suggest contacting the developer of mortscript and discussing it with him.
Click to expand...
Click to collapse
Mort knew about that request and by chance just announced to so.
Thanks anyway.
Hello levenum,
I just joined the community. Reason being, I found your RegDisplay plug-in
You call it a sample project, but the impact is that of an awesome solution.
Great for MortScript, but equally useful in BASIC applications that write
messages to the registry which is show upon screen minimization.
I regret not being a C programmer (mainly BASIC), else I'd love to further
develop this jewel.
Your plug-in runs flawlessly in an iPAQ 210 under WM6 Classic.
Cheers and Respectful Greetings
Robert
CLSID for registry display plugin
What is the CLSID for the Registry Display Plugin? I am going to have to edit the XML file that defines my home screen in order to get the plugin to show up. I am using Facade to control my home screen, and the only plugins that it will show in its list are those currently in use in one of the XML files in the Application Data\Home folder. All other new plugins require editing the XML. Thanks for your help.
levenum said:
Ok, most of you may find this totally useless as a plugin, but it was a combination of a request by user Treo_newb and a desire to create a sample plugin project that could be used as a base / example for plugin writers (I plan on doing an article on codeproject.com and this will be the source for it).
What does it do?
This plugin displays a string stored in registry.
The path is:
HKEY_CURRENT_USER\Software\RegDispPlugin
Value name: DisplayString
It checks if this string has changed several times per second when today screen is shown (as the system sends refresh message to all plugins) and displays the updated message if a change occurred.
What is it good for?
First, if you write apps using mortscript or similar like the user who requested this it will let your script display stuff on today screen.
Alternatively it could be used to mark your device today with a string that isn't as easily changed as user info.
The source is basically a skeleton plugin you can use to build your own plugin on (no license / copyright to limit you) and it already has several tricks needed for the plugin to display correctly:
VGA compatibility
Text size matching system settings
Proper header in settings dialog (like on system plugins)
Proper text color when selected (according to theme)
No blinking all today screen on change
Proper resize when switching between landscape and portrait
When I was writing my first plugin I could not find all these little fixes concentrated in a single article so I had to fish for each one as the bug reports came in.
Hope you will find this little project useful.
The plugin:View attachment 41592
The source (eVC 4 project): View attachment 41583
Click to expand...
Click to collapse
This is great! I was asked if I could write a today screen plug-in for my weather application (http://forum.xda-developers.com/showthread.php?t=445576) - I couldn't since I don't have the skills and I'm writing .NET code - but this is exactly what I needed.
I'm adding support for this plug-in and will of course give credits to you.
Hi there,
cause most of you know the problem with TF3D Qvga and StandBy.
Could anyone here with knowledge of coding write a small app that acts like the standby timer in Windows Mobile?
I thought about something like that:
If no user action is recognize for time x, then deactivate TF3D (HKLM","\Software\Microsoft\Today\Items\TouchFLO 3D","Enabled","0")
and device goes to standby.
If device wakes up (or pressing power button) TF3D will be enabled again.
I think for someone with knowledge in development it shouldn't be mouch action, but it would be great to have a fully working TF3D and i think driver development still will need some time.
So, if someone is able to do that, please, please, please
I will test everything.
that should only be a few lines of mortscript, no ?
No itried this by myself (it's anywhere here in this forum) and i talked to Mort, too.
But there is no possibility in the actual version to recognize user actions.
The rest you can easyli write in MortScript, but not the user recognation.
Like a few others with the HTC P6500 (Sedna) handset. I was annoyed by the 1 minute time out on the fingerprint security, which could not be adjusted easily. After looking at the registry etc further, I believe I have extended my timeout to 5 mins with the following registry adjustments.
Edit these values here:
HKLM\Comm\Security\Policy\LASSD\AE\{50C13377-C66D-400C-889E-C316FC4AB374}
AEFrequencyType - set to 2
(This calls AEFrequencyValue (below) which represents the number of minutes since any AE returned from VerifyUser successfully.)
AEFrequencyValue – set to 5
(Number of mins to delay timeout)
Then - Soft reboot the device[/B]
Initial tests appear that this works ok on my handset.
Reference: msdn.microsoft.com/en-us/library/aa919751.aspx
Reference: channel9.msdn.com/wiki/MobileDeveloper/CreatingALap/
This post is for information only. I am not responsible for damage caused to your own handset. I am also not a developer, just someone who knows a little about computers etc. I hope that people find this information useful.
Thanks for the info but where is the "HKLM" folder to start with ?
Registry folder
Hi Chayen22,
You will need to install a registry editor onto the handset to access these settings. Have a look around on the forums to see what people use. I use one called Total Commander which also has many other useful features and tools.
If you are unsure of what you are doing it may be best speaking to someone you know who is good with Windows based computers. I'll also take this opportunity to say that I'll accept no responsibility for any damage caused when using registry editing tools on your phone. You make changes at your own risk.
I hope you find this info useful.
Stretch_y2k