Click here to Skip to main content
6,292,426 members and growing! (10,086 online)
Email Password   helpLost your password?
Platforms, Frameworks & Libraries » Mobile Development » Howto     Intermediate

Using .NET CF P/Invoke to Turn off PDA Screen

By hesicong

An article on how to turn off PDA screen on .NET CF platform.
VB, Windows, .NET CF, .NETVS.NET2003, Dev
Posted:21 Mar 2005
Views:26,988
Bookmarked:23 times
Announcements
Loading...
 
Search    
Advanced Search
printPrint   Broken Article?Report       add Share
  Discuss Discuss   Recommend Article Email
5 votes for this article.
Popularity: 3.22 Rating: 4.60 out of 5

1

2

3
1 vote, 20.0%
4
4 votes, 80.0%
5

Sample Image

Introduction

It's sometimes useful to turn off the PDA screen to save power while your application is running in the background, e.g., if you design a music player, the user may want to turn off the screen for longer play time.

Unfortunately, there are few articles on this topic. One C++ program I have found is on MSDN. And thank one's lucky stars, I also found another C# program from OpenNET CF. Then I rewrote it and tested for VB.NET.

Using the code

It's easy to use this code, you simply call Video.PowerOff under the PDA namespace. When your screen is turned off, you can turn it on using Video.PowerOn Sub, or you can press the Power button on your PDA.

The core function here is ExtEscape in "Coredll.dll". This function allows applications to access the capabilities of a particular device that are not available through the graphics display interface (GDI). The device capabilities this function accesses must be implemented by an OEM.

Declare Function ExtEscapeSet Lib "coredll" Alias _
               "ExtEscape" (ByVal hdc As IntPtr, _
                            ByVal nEscape As Int32, _
                            ByVal cbInput As Int32, _
                            ByVal plszInData As Byte(), _
                            ByVal cbOutput As Int32, _
                            ByVal lpszOutData As IntPtr) As Int32

A return value greater than zero indicates success and less than zero indicates an error. You can get detail information from the MSDN Library.

To use this function, first you must have a hdc returned by GetDC function. Then the nEscape parameter is set to SETPOWERMANAGEMENT where the value is 0x1803. The cbInput parameter is the length of plszInData. Here the plszInData is some structure. I define it like this:

Dim vpm() As Byte = {12, 0, 0, 0, 1, 0, 0, 0, _
                     VideoPowerState.VideoPowerOff, 0, 0, 0, 0}

Here the 9th value is from VideoPowerState enumeration:

Public Enum VideoPowerState As Integer
    VideoPowerOn = 1
    VideoPowerStandBy
    VideoPowerSuspend
    VideoPowerOff
End Enum

And the last parameter cbOutput and lpszOutData should be set to zero. In the end, call ExtEscapeSet function to turn off/on your screen.

Although the function works well, I was confused by the structure of plszInData and what extra usage of ExtEscape function. Can anyone tell me about it? Thanks!

Points of Interest

Contact me

Thanks for reading and using my code.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here

About the Author

hesicong


Member
I'm a undergraduate student in UESTC in China.
I have being learing computer for more than ten years. And now studying programming and have some software made by myself.
I learned SMS technology and did some work on OBEX, PDU, AT commands, IrDA and so on.
If you have interested in this field, please contact me.
And see more on my web site: http://www.hesicong.net
Occupation: Web Developer
Location: China China

Other popular Mobile Development articles:

  • Writing Your Own GPS Applications: Part 2
    In part two of the series, the author of "GPS.NET" teaches developers how to write GPS applications suitable for the real world by mastering GPS precision concepts. Source code includes a working NMEA interpreter and sample high-precision application in C# and VB.NET.
  • Writing Your Own GPS Applications: Part I
    What is it that GPS applications need to be good enough to use for in-car navigation? Also, how does the process of interpreting GPS data actually work? In this three-part series, I will cover both topics and give you the skills you need to write a commercial-grade GPS application.
  • Learn How to Find GPS Location on Any SmartPhone, and Then Make it Relevant
    A step by step tutorial for getting GPS from any SmartPhone, even without GPS built in, and then making location useful.
  • Pocket 1945 - A C# .NET CF Shooter
    An article on Pocket PC game development
  • iPhone UI in Windows Mobile
    It's an interface that works with transparency effects. As a sample I used an interface just like the iPhone one. In this tutorial I am explaining how simple is working with transparency on Windows Mobile.
Article Top
You must Sign In to use this message board.
FAQ FAQ 
 
Noise Tolerance  Layout  Per page   
 Msgs 1 to 3 of 3 (Total in Forum: 3) (Refresh)FirstPrevNext
GeneralHi PinmemberSolanki Rajat1:16 14 May '08  
GeneralHow To Check Current Status? PinmemberReza Ghorbani21:01 19 Aug '07  
GeneralHandy for .NET Show Pinmemberfrenchroast14:33 29 Mar '05  

General General    News News    Question Question    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

PermaLink | Privacy | Terms of Use
Last Updated: 21 Mar 2005
Editor: Smitha Vijayan
Copyright 2005 by hesicong
Everything else Copyright © CodeProject, 1999-2009
Web18 | Advertise on the Code Project