Browse DevX
Sign up for e-mail newsletters from DevX


Put Your Apps on the Landscape with Windows Mobile 2003 Second Edition : Page 3

New mobile devices on store shelves all over the world are built to accommodate both landscape and portrait screen orientation and the good news is that the second edition of Windows Mobile 2003 supports this flexibility. The bad news is that it's not just yet a straightforward process, but we'll show you how to get the job done.




Building the Right Environment to Support AI, Machine Learning and Deep Learning

Hidden Controls and Images
Prior to the Windows Mobile 2003 Second Edition, all applications were displayed in Portrait mode. And so developers often adopted the practice of leaving unused controls outside the boundary of the displayable form (see Figure 7).
Figure 7. Dust Bunnies: "Hidden" controls left off to the sides in the Portrait mode show up in funny places when the app is switched to Landscape.

If this is a practice that effects your apps, it's time to do some housekeeping! While controls left to the side in Portrait mode are always safely "hidden" in devices that only support Portrait mode, if the same application is executed on a Windows Mobile 2003 Second Edition device, all the unused controls will be seen if the user changes the screen orientation.

Programmatically Rotate the Screen
While Microsoft does not recommend that you unnecessarily rotate the screen of your application, you may need to do so at times. Unfortunately, the .NET Compact Framework does not have managed classes to do the screen rotation programmatically. And so, as you might have guessed it, Platform Invoke (P/Invoke) is the way to go. Because of the data types marshalling problem, invoking the ChangeDisplaySettingsEx() function to rotate the screen is quite a lengthy affair.

Figure 8. Rotating the Screen: Here I've added the C# class that programmatically rotates the screen into the project.

Fortunately, a fellow MVP—Alex Feinman (a member of the OpenNETCF.org Advisory Board has been very helpful to write a sample in C# (and has given me his permission to modify it for use in this article). I modified his sample and encapsulated the main code into a class so that you can just reference it directly in your project. Listing 1 shows the class in C# that allows you to programmatically rotate the screen.

To compile the class in Listing 1, simply create a new Smart Device application and select the Class Library project type. Copy and paste the code into the class1.cs file and then build the project.

To demonstrate screen rotation, I built a new VB.NET Pocket PC application and added a reference to the C# class shown above. (I named this application ScnOrientation, see Figure 8).

And I populated my Pocket PC Windows form with four Button controls (see Figure 9).

Figure 9. Adding Buttons: These four new buttons are added to allow the user to dynamically reorient the screen.

To change the screen mode, use the function in Listing 2, which services the click events of the four Button controls.

You can now rotate the screen using the four buttons (see Figure 10).

Figure 10. 360: You can rotate the screen all you like.

Windows Mobile Second Edition gives mobile developers a big advantage: You can deliver the latest capabilities of the latest devices—devices that will appear in the market for the next few months. While most current application will run without problem in the newer OS, you should really put the time in to modify your application to capitalize on the larger and more flexible Landscape screen configuration. Unfortunately, the .NET Compact Framework has been a little slow to catch up on the changes and requires some nifty coding to get some of the features to work. But you should now have the information you need to get past any initial roadblocks.

Wei-Meng Lee is a Microsoft .NET MVP and co-founder of Active Developer, a training company specializing in .NET and wireless technologies. He is a frequent speaker and author of numerous books on .NET, XML, and wireless technologies.
Comment and Contribute






(Maximum characters: 1200). You have 1200 characters left.



Thanks for your registration, follow us on our social networks to keep up-to-date