Thursday, June 30, 2005
Trap All Key Presses Independent of Focus
Using Visual C# .NET Compact Framework 1.0, I'm trying to trap all keypresses in a top level System.Windows.Forms.Form whether or not the form has Focus. Basically I want to delegate key events on my own. The problem is that only the currently Focused Control receives events (KeyPress, KeyDown, etc.). I would like a high level key event manager that peeks (does not consume) all key related events for a Form. Can anyone help me here?
I looked at the RegisterHotKey API but that is only for C++ and, as the method name implies, that is only for registered keys -- not the entire set of keys. If this is the only way or best way of trapping keypresses, I guess I will have to write a C# wrapper but I would prefer some other method.
Is there a known way of doing this?
I got one response from Daniel who said, "Look at the ApplicationEx class (and message filters) in the Smart Device Framework (SDF) from OpenNETCF." Unfortunately I can't use OpenNet CF because it is Open Source. He also pointed me to a newsgroup discussion. The consensus seems to be that the .NET CF does not make this easy, so you should just use OpenNET CF :( For example, here.
Tuesday, June 28, 2005
OpenSource .NET CF
Confusion About .NET & .NET CF
To add a .NET CF 1.0 project to your solution with VS2005 b2, select the solution in the solution explorer->Add->New Project->Visual C#->Smart Device->SmartPhone 2003. You have just implicitly started a .NET CF 1.0 project :)
More frustrating things about developing for these phones:
(1) Again, there is no good documentation source that simply displays the .NET CF 1.0 API. You have to wade through all of the .NET documentation and then scroll down to the bottom of the class description to make sure it's supported by your flavor of .NET.
(2) When you open up any class in VS2005 help, the bottom of the class description details three things.
- Development Platforms
- Target Platforms
- Version Information
The Version Information is most critical for .NET CF developers. It is here that Microsoft tells us whether or not this class is supported by the .NET CF framework (and which versions 2.0, 1.0, etc.). Of course, this does not mean that ALL members of this class are supported by the .NET CF framework; in fact, more often than not only a subset of the members are supported. So, you must then browse to the class members and look for the little Pocket PC icon. If it exists to the left of a method/property, you can be assured that it is supported by the .NET CF.
Now, this post is NOT a rant about the lack of functionality in .NET CF (of course the compact framework is going to have a more constrained API offering) but rather in the organization of the MSDN help system. After programming in .NET for the SMT5600 for only two weeks I have run into a couple of confusing instances where a method I expected to be available (e.g. the Control.ControlAdded event in Forms) was not and, critically, it took some proactive documentation perusing to understand why.
Finally, I will say that part of my struggle is most definitely a result of being relatively new to .NET as a whole (my Master's thesis project was in Java, my language of choice) -- there are inevitable growing pains and disconnects whenever learning a new language; it's just been a very frustrating experience.
Sunday, June 26, 2005
Property Browser with Custom Controls
[
CategoryAttribute("Appearance"),
DescriptionAttribute("This is a description of this property")
]
public object MyProperty{
get { ... }
set { ... }
}
For more info on customizing the property browser, go here and search for "Property Browser" within your web browser.
UPDATE (06/26/2005 @ 12:09PM): It appears that the .NET Compact Framework has a relatively restricted ComponentModel space to affect run-time and design-time behaviors. For example, code completion with System.ComponentModel in VS2005 b2 shows only three available methods: (1) DefaultValue (2) DesignerCategory and (3) EditorBrowsable
Tab Order
The .NET Compact Framework supports tabbing between controls with Service Pack 2 and later, but requires that you explicitly use the Focus method on the first control that should receive the focus.
The .NET Compact Framework does not support the TabIndex and TabStop properties or the UpdateZOrder method, but you can design your application to have a predictable tab order and explicitly set controls to receive focus. The up and down navigation follows the tab order.
The default tab order follows the sequence of focusable controls as they are added in code to the Controls collection.
Note that the forms designer creates the Controls collection in reverse order of when the controls were added to the form. For example, if TextBox1, TextBox2, and TextBox3 are added to the form in that order, then first control in the Controls collection is TextBox3. The following Visual Basic example shows designer-generated code in the InitializeComponent method of a form.
(from MSDN -- scroll down to bottom)
Saturday, June 25, 2005
MSDN API for SmartPhones
I am trying to find an easy reference for the C# SmartPhone API. Unfortunately, all I can find is the ordinary MSDN .NET API (can't even find the reduced .NET Compact Framework API). So, I have to scroll down to the bottom of the API reference to make sure that it includes .NET Compact Framework... Even then, the class is not guaranteed to work.
Case in point: the ButtonBase class. Go to the MSDN ButtonBase Class Overview page and you will see that it is a compatible with the compact framework. Then open up the constructor page, found here, and note that platform support for the compact framework is curiously missing. I had a devil of a time trying to build a custom control class that inherits from ButtonBase (VS2005 b2 kept saying "No overload for method 'ButtonBase' takes '0' arguments"). I finally gave up. I had then hoped to derive a class from UserControl but it seems that this class is not supported by the .NET compact framework either. Hmm...
I feel like I am certainly missing something with regards to the MSDN documentation system. Is it too much to ask for to gain access to an easy API reference which just includes SmartPhone 2003 supported classes?
Connect to Device Failed
The error I get is identical to this thread on forums.microsoft.com. Basically, I try debugging a simple test application with the SmartPhone 2003 SE Emulator and I have to suffer through a long pause before I get an error dialog that reads, "There were deployment errors. Continue?" I have the option of selecting Yes or No... neither of which helps. In the Error List in Visual Studio I get "Connect to Device Failed - Conman HelpText System."
According to the help thread mentioned above, this connection error is most likely due to a problem with the ip of the emulator. By default VS2005 beta 2 uses TCP/IP as the transport to the emulator. Unfortunately there is no easy way to determine the ip of the SmartPhone 2003 emulator (though there is a way to do it in the PocketPC 2003 emulator). I then installed the Microsoft Loopback Adapter solution, instructions found here. This did not solve my problem either -- in fact, I get the exact same error.
Beyond this, I've tried just about every setting in Tools->Options->Devices->SmartPhone 2003 SE Emulator->Properties but to no avail. In addition, I foundthat the easiest way to test the connection setting was to employ the "Device Emulator Manager" found in VS2005 (Tools->Device Emulator Manager) rather than to attempt a debug execution on the emulator.
I'm going to give up for now and debug straight off the cell phone itself. This, however, was not a possible solution this past week because I did not have my cord with me.
Friday, June 17, 2005
Storing Application Data on SmartPhones
Application data is typically about two things: settings and application preferences that the user expects the application to keep even after it is terminated, and transactional or reference data brought from a remote server or entered by the user. Microsoft SQL Server™ 2000 for Windows CE Edition (SQL Server CE) is a popular choice for application data storage on Pocket PCs and other Windows CE devices. Other options have to be used in Smartphone applications since SQL Server CE is not available for the platform. Persisting data to the registry is not generally recommended because flushing the registry to permanent store is quite resource intensive. For Smartphone applications, using local XML files is a common alternative.
(from MSDN)
Thursday, June 16, 2005
Signing SmartPhone Apps
The security model for Smartphone applications is based on certificates. A device can be configured by the device manager (usually the network operator) to allow only signed applications to run. Whether an application can run or not depends on:
- If the device has a one- or two-tiered security model
- The current security mode of the device: Open, Locked, or Prompt
- How the application was signed: with a privileged certificate, unprivileged certificate, or not at all
One-tiered devices give access to all APIs for applications that are allowed to run. On two-tiered devices, there are APIs that cannot be access unless the application was signed with a privileged certificate.
If the device has:
- Open security mode, all applications can run, signed and unsigned.
- Locked security mode, only signed applications run on the device.
- Prompt security mode, all signed applications run without a prompt, and the user is prompted to reject or accept all unsigned applications.
(from MSDN).
Application Data Path on SmartPhones
RAM is erased when a Smartphone is switched off. This means that application data has to be put in the \Storage folder. The \Storage folder is persisted to flash memory. For more information, see "Storing Data" in the Smartphone Guide found in the Smartphone 2003 SDK.
(from MSDN)
Thursday, June 09, 2005
Sets in C#
Wednesday, June 08, 2005
Windows Mobile 5.0 on the SMT5600
You can take away my buttons, but you...
Tuesday, June 07, 2005
SmartPhone Registry Editor
On my SmartPhone, the registry link:
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion
does not contain the Run directory. So perhaps you cannot register your application to autostart through the registry on SmartPhones...
Monday, June 06, 2005
Auto-Start App on Device Startup
The nice thing about the latter method is that many programs use command line switch options to load in a special way if executed by autostart rather than by user. You could imagine building a program that uses a command line switch like -autostart that would simply load itself passively into the background when initiated by the device, while the same program might show a load screen or user interface when initiated by the user.
I am not entirely sure how this works on Smartphones. I am quite confident that method one above works. The model here is, let the installer do the work and copy a shortcut of your application into the Smartphone's Startup directory. However, I found a discussion on msdn that seems to indicate shortcuts on mobile devices are limited compared to their desktop counterparts. In WindowsXP, for example, you can set the Shortcut's target application and in the process you can include command line switches. This does not appear possible on Smartphones (link). Of course, this does not limit you in just creating a simple shortcut to your application or, as the above link outlines, creating a special boot application independent of your main executable.
Incidentally, you can see a list of programs slated to auto-start by typing "msconfig" in the Run window of Windows XP, then click the "Startup" tab. (See link for more information)