Email:   
Home
In This Issue
Email a Friend
EasyPrint
News details Click here for the RSS feed's XML code. This is not a browser URL.
Articles-only Click here for the RSS feed's XML code. This is not a browser URL.
Freeing up DLLs, avoiding suspend mode, and listbox tricks (continued)

"Fortunately, there's a back door you can use to modify the timeout value."

Fortunately, there's a back door you can use to modify the timeout value. When the operating system starts, it initializes the timeout period from the DWORD registry value FreeTimeout under the HKEY_LOCAL_MACHINE\Software\Microsoft\OLE key. The time is specified in milliseconds, so a value of 30,000 would indicate a 30 second time period. If the registry key does not exist, the default time of ten seconds (or 600,000 milliseconds) is used.

What can I do to avoid having my device go into suspended mode?
Power conservation is a big issue for a Windows CE device that's running on batteries, so the operating system is designed to suspend itself into a low-power mode after a period of inactivity. Unfortunately, this is not ideal for all situations. For example, if your program has an open serial port connection or a TCP/IP connection over a PC Card network adapter, these connections will be broken when the device goes into suspend mode.

A hacked up solution to this is to occasionally fake a keystroke with the keybd_event or SendInput APIs. While this will usually work for most devices, it can be problematic if the keystroke is interpreted as input to the active application. Additionally, the keybd_event API doesn't work on most Palm-sized PCs, which makes it an even less desirable approach.

Luckily, there is a right way to do this that works on all devices. Since version 1.0, Windows CE has had the well-hidden SystemIdleTimerReset API, which takes no parameters and has no return value. When this API is called, the system countdown to device suspension starts over from the beginning. Since the countdown time is about 30 seconds, calling SystemIdleTimerReset at least once every 30 seconds will stop the device from suspending itself. The easiest way to do this is to launch a thread like this:

DWORD WINAPI AvoidSuspendThread(LPVOID pv)
{
// Application code should set g_bAvoidSuspend to false when
// it's OK to enter suspend mode again

while ( g_bAvoidSuspend )
{
SystemIdleTimerReset();
Sleep(30 * 1000);
}

return 0;
}

Although this API has been available since version 1.0, it only started showing up in the SDK header files in CD version 2.11. For older devices, you may have to add the prototype yourself. You won't need to manually load the function with GetProcAddress, though -- it's already available in the standard SDK import library COREDLL.LIB.

How can I make the horizontal scrollbar in a listbox work properly?
Let's say you're putting the finishing touches on a dialog box for your application and you notice that some of the entries in a listbox extend past the right margin. "No problem", you say to yourself, "I'll just enable the horizontal scrollbar".

You open up the dialog in the resource editor, enable the "Horizontal Scroll" radio button and rebuild. When you test your changes you're surprised to see that the horizontal scrollbar doesn't show up. Fiddling around with the other styles has no effect -- the little bugger just won't appear. What gives?




[ Prev | Next ]

ZATZ Home  ·  News  ·  Back Issues  ·  Credits/Trademarks ·  Link To Us
Copyright © 1999-2009, ZATZ Publishing. All rights reserved worldwide.
Editor's Login