An Original Idea

because all great software begins with an original idea

Archive for the 'Pocket PC Development' Category


Twittering using the Compact Framework

Posted by anoriginalidea on May 19, 2008

 image

My twitter updates are done using a variety of code.  At the moment I use the Curl command line  in conjunction with SlickRun.  In the past I did this with Outlook (see the article Twittering from Outlook Using VBA).  In the past I’ve found this pretty easy to do using the Twitter Api.

 

I also like to do updates from my Pocket PC, but am not keen on SMS charges.  The solution of course is to create my own client, which I’ll be posting about shortly.

For my client program I intend to use TwitterLib library.  Sadly this does not work for the compact framework unaltered.  I am currently working on porting it to the compact framework.

 

In the interim I want to share with you a simple code sample for submitting tweets to Twitter. 

The example is simple enough to be used by people who want to do HTTP posts to similar services.

 

    Dim lsParams As String = “status=” & Uri.EscapeDataString(tweetText)

    Dim loRequest As HttpWebRequest = CType(HttpWebRequest.Create(”http://twitter.com/statuses/update.xml”), HttpWebRequest)
           With loRequest
               .Proxy = System.Net.GlobalProxySelection.GetEmptyWebProxy()

               .Timeout = 10000
               .AllowAutoRedirect = True
               .AllowWriteStreamBuffering = True

               .Method = “POST”

               .ContentType = “application/x-www-form-urlencoded”
               .ContentLength = Len(lsParams)

               Dim loCred As New System.Net.NetworkCredential(”someusername”, “somepassword”)
               .Credentials = loCred

               ‘ Write the request paramater
               Dim stOut As New StreamWriter(.GetRequestStream(), System.Text.Encoding.ASCII)
               stOut.Write(lsParams)
               stOut.Flush()
               stOut.Close()

               Dim loResp = .GetResponse
               With loResp

                   .Close()
               End With

           End With

 

The most important difference with the full .net framework is the “GetEmptyWebProxy” and “AllowWriteStreamBuffering” lines.  It won’t work without it.


Share this post :

Posted in .net Framework, Pocket PC Development, VB.Net | Tagged: , , , , | No Comments »

PPCFinder 1.0.0.5 released

Posted by anoriginalidea on April 24, 2008

Isn't the PPCFinder dog just the cutest?

 

About a year ago we released the freeware Pocket PC search program PPCFinder.  This program has had literally thousands of downloads subsequently with only a single release.

I’m proud to announce the first public update of the program since it’s original release.  The maintenance release 1.0.0.5.

The “backstory” of PPCFinder is a plane flight home from Sydney to Brisbane.  In the past I found the inbuilt Windows Mobile search completely inadequate.  The available freeware alternatives seemed unpleasant to use and the commercial ones seemed to be as an ajunct to filemanager functionality.    It was time to write my own….In only a few days, PPCFinder was born. 

PPCFinder is a simple program that still addresses an important need on the Windows Mobile Platform.  That is the need to find files, particularly large ones (the definition of “large” has changed since the default search application in Windows Mobile was created), in order to get extra memory.

PPCFinder gives you all the “advanced” search options available to the original Windows XP search, including the cute doggy mascot that I’m sure you find excellent.

If you need all this, give PPCFinder a go.

The full release notes for the new version are available at the forum.

If you are a fan, please leave a comment and let everyone know about it.


Share this post :

Posted in General, Pocket PC Development | Tagged: , | 3 Comments »

Getting a Screenshot with VB.NET on the Compact Framework 2.0

Posted by anoriginalidea on January 3, 2008

 

image

I believe that “thumbnail” images of data in applications is a powerful way of giving an overview to a user.

One sort of application that uses this technique is the “Flip 3D” functionality of Vista.

The code sample below provides a routine that “grabs” a rectangle of the currently displayed screen.  Just like it’s desktop equivalent, it can only take screenshots of the visible screen, not graphics that are off-screen. (Anyone know how to do that? Please let me know!)

Here’s the code:

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    picScreenshot.Image = GetControlBitmap(Me.CreateGraphics, Me.SomeControl.Bounds)
End Sub
Const SRCCOPY As Integer = &HCC0020
Public Declare Function BitBlt Lib “coredll.dll” (ByVal hdc As IntPtr, ByVal nXDest As Integer, ByVal nYDest As Integer, ByVal nWidth As Integer, ByVal nHeight As Integer, ByVal hdcSrc As IntPtr, ByVal nXSrc As Integer, ByVal nYSrc As Integer, ByVal dwRop As Integer) As Boolean

Private Function GetControlBitmap(ByVal gx As Graphics, ByVal rect As Rectangle) As Bitmap

    ‘ Create the bitmap to output
    Dim loBitmap As Bitmap = New Bitmap(rect.Width, rect.Height)

    ‘ Create compatible graphics
    Dim loCompGraphics As Graphics = Graphics.FromImage(loBitmap)

    ‘ Blit the image data
    BitBlt(loCompGraphics.GetHdc(), 0, 0, rect.Width, rect.Height, gx.GetHdc(), rect.Left, rect.Top, SRCCOPY)

    ‘ Cleanup
    loCompGraphics.Dispose()
    Return loBitmap
End Function

The function “GetControlBitmap” will get a bitmap of a control or any rectangle passed into it.

Links


Share this post :

Posted in .net Framework, Pocket PC Development, VB.Net | Tagged: , , , , | 2 Comments »

Disabling the context menu in the .Net CF WebBrowser Control

Posted by anoriginalidea on December 31, 2007

image

Although initially impressive, the WebBrowser control in the .NET Compact Framework 2.0 lacks the ability to be customised in a few important areas. An obvious one that people are asking about seems to be the ability to remove the default context menu.

None of the obvious solutions , such as setting the ContextMenu property to null seem to work.

The Problem
The internal PIE control that the WebBrowser control wraps has a COM property to disable it, but this is not exposed.

So how can we set the property?

The .NET CF 2.0 provides the answer. It introduced some new features that allows straight forward interaction with COM objects and controls.

Doing this with the WebBrowser control involves sending a special windows message (DTM_BROWSERDISPATCH) to the windows handle of the control to retrieve a pointer to the IDispatch interface, converted into an object (using the GetObjectForIUnknown call) , which is then cast to a marked up interface with the appropriate identifiers. These are found webvw.h which is part of the Compact Framework SDK.

This technique will only work for Windows Mobile (not Smartphone) based devices. For my own projects I use a compiler directive to screen avoid the COM calls on the Smartphone platform.

The Solution

I have cut down the solution to it’s bare essentials and encapsulated it in the class WebBrowserContactMenu. You should be able to reuse this class, unaltered in your own project.

Warning: Currently this solution WILL ONLY WORK FOR Windows Mobile 2003!   It is supposed to work for WM5 and above also (it all seems correct) but for some reason the SendMessage to DTM_BROWSERDISPATCH is not working at all.   I have researched the problem but as yet cannot find a workaround.  I will update this article if I do.  Any suggestions are welcome.

Imports System.Runtime.InteropServices
Imports System.Runtime.CompilerServices
Public Class WebBrowserContextMenu
Private moWebBrowser As WebBrowser
Public Sub New(ByVal control As WebBrowser)
moWebBrowser = control
End Sub
Const WM_USER As Integer = &H400
Const DTM_BROWSERDISPATCH As Integer = (WM_USER + 124)
Declare Function SendMessageLongRef Lib “Coredll” Alias “SendMessageW” (ByVal HWND As Integer, ByVal wMsg As Integer, ByVal wParam As Integer, ByRef lParam As Integer) As Integer
Public Property Enabled() As Boolean
Get
Return mGetBrowserInterface.ContextMenuEnabled
End Get
Set(ByVal value As Boolean)
mGetBrowserInterface.ContextMenuEnabled = value
End Set
End Property

Private Function mGetBrowserInterface() As IBrowserBareEssentials

Dim liPtr As Integer = 0
SendMessageLongRef(moWebBrowser.Handle.ToInt32, DTM_BROWSERDISPATCH, 0, liPtr)

Return CType(System.Runtime.InteropServices.Marshal.GetObjectForIUnknown(CType(liPtr, IntPtr)), IBrowserBareEssentials)

End Function

<ComImport(), InterfaceType(ComInterfaceType.InterfaceIsIDispatch), Guid(”698E3FC9-70C3-11D0-81E8-00A0C90AD20A”)> _
Public Interface IBrowserBareEssentials

<DispId(185)> Property ContextMenuEnabled() As Boolean
End Interface
End Class

In the example project, a simple WebBrowser application hosts this class, instantiating it and using radio buttons to toggle the button. Here’s what the form code looks like:

Public Class Form1
Private moContextMenu As WebBrowserContextMenu
Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Load
WebBrowser1.Navigate(New Uri(txtUrl.Text))
moContextMenu = New WebBrowserContextMenu(WebBrowser1)
End Sub
Private Sub cmdGo_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdGo.Click
WebBrowser1.Navigate(New Uri(txtUrl.Text))
End Sub
Private Sub optEnabled_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles optEnabled.Click
moContextMenu.Enabled = optEnabled.Checked
End Sub
Private Sub optDisabled_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles optDisabled.Click
moContextMenu.Enabled = optEnabled.Checked
End Sub

End Class

Download the sample project. (14K)

Conclusion

The purpose of this article was to provide a direct solution to the context menu problem. I have by no means an exhaustive description of using COM with WebBrowser, but this may help as an introduction. At a future date I will share other uses for this technique.

Share this post :

kick it on DotNetKicks.com

Posted in .net Framework, Pocket PC Development, VB.Net | Tagged: , , , | 4 Comments »

New OpenNETCF Community Site

Posted by anoriginalidea on September 10, 2007

image

 A while ago I noticed that the tremendously useful OpenNetCF wiki had been taken down, with spammers being sited as the reason why.

The fine folks at OpenNetCF.org have opened a new site to replace it, called  “OpenNETCF Community” to replace  it, so get on over there and take a look.

Links

OpenNETCF Community

Posted in Pocket PC Development | No Comments »

Write Code Once For Both Mobile And Desktop Apps

Posted by anoriginalidea on August 28, 2007

 

In a previous article I wrote about the technique used by Mobile Client Software Factory to do Microsoft Test automated testing in device projects.

MSDN magazine have now published a magazine article that explores the technique for developing other kinds of assemblies.  They also make the point that Compact Framework assemblies are “retargetable” (able to run on either platform ) whereas full framework assemblies are not.

This is not always ideal, as sometimes you may want to take advantage of desktop platform features.

The recommended technique involves sharing source, yet having two project files, targeting each different platform in the same project directory. 

Links

 Share Code: Write Code Once For Both Mobile And Desktop Apps — MSDN Magazine, July 2007

Unit Testing Smart Device Projects

Posted in Pocket PC Development, Software Development | No Comments »

A reference "to that project" could not be added

Posted by anoriginalidea on August 7, 2007

As part of my research into doing test driven development on the Windows Mobile platform, I tried to create a “smart device” project level reference.

(See the post Unit Testing Smart Device Projects for more information about using Microsoft Test and unit testing on Windows Mobile)

As I haven’t found the information anywhere else, I thought I’d post my problem and the solution:

The Problem

When my test project was in Visual Basic, I got this brutal error message:

A reference to xxxxxxxxx could not be added:

image

A CSharp test project did manage to get to add the reference, but only after getting this message:

image

Does this mean I’ve finally found something CSharp can do better than VB.Net?  Surely not!

The Solution

After a great deal of messing around, I tried using the Microsoft Test Test Wizard to create the Visual Basic test project.  This worked.  The reason this worked was that it took a file reference instead.

So there’s your workaround.  Use a file reference.

Posted in .net Framework, Pocket PC Development, Software Development, Unit Testing, VB.Net | 1 Comment »

Unit Testing Smart Device Projects

Posted by anoriginalidea on August 7, 2007

Screenshot of the Smart Client Software Factory's Gui Test Runner

A way of doing Test Driven Development on the Windows Mobile platform in the early days was not particularly easy.

For the development of Webby I created my own NUnit clone that worked inside the exe in debug mode.  This worked really well, but it was limited and I would have preferred something that was integrated into the IDE.

The developers of the “Mobile Client Software Factory” at Microsoft Patterns and Practices felt the need to create a unit testing environment that would enable full “test first” development.  Recently I had the need to investigate their solution, and have found very good.

The factory provides comprehensive unit tests for the application blocks that come with the factory, but more interestingly it provides a way for you to use the same testing framework.

This article below gives an outline of how tests are structured and how to do it.  

The structure of the tests

The test classes utilise the “Visual Studio Team Suite” attribute test markup ([TestClass], [TestMethod] etc).

These test classes are used by two test projects (assemblies):

  • A desktop test project for Visual Studio 2005 Team Suite
  • A mobile class library for running the unit tests on a mobile device

Both the desktop and mobile projects reside in the same project folder (with different names)

Creating the tests

The following procedures describe how you should create and run unit tests
To create and run unit tests on the desktop

  1. Create a Visual Studio 2005 Team System Edition test project that will run unit tests on the desktop.
  2. Add the <TestClass>, <TestMethod>, <TestInitialize>, and <TestCleanup> attributes described earlier to your classes to indicate which are test classes, test methods, initialization methods, and cleanup methods.  (TIP: Reference the application exe or dll as a “File Reference”)
  3. Run these unit tests using Visual Studio 2005 Team System or the TestDriven.NET test runner until all the tests pass.

Next, you can adapt these tests to run on the mobile device. The following procedure describes how you can use the GuiTestRunner utility to run your unit tests in the device emulator or on a mobile device.

To run unit tests in the emulator or on a device

  1. Add the following projects to your application project:
    • GuiTestRunner.csproj from the Tools\CFUnitTester\GuiTestRunner folder
    • TestRunner.csproj from the Tools\CFUnitTester\TestRunner folder
    • UnitTesting.csproj from the Tools\CFUnitTester\UnitTesting folder
  2. If you want to use the test utilities in your tests, also add the TestUtilities.csproj project from the Tools\TestUtilities folder. This project includes utilities to help you read application resources, access the application runtime folder, and provides stopwatches for measuring performance.
  3. Click Add on the File menu, and then click New Project. In the left-side tree view of the Add New Project dialog box, click Windows Mobile 5.0 Pocket PC. In the right-side window of this dialog box, click Class Library. Click OK to add the new project to your existing solution. Use the naming convention for test projects “[Module to be tested].Tests.CF“.
  4. Close Visual Studio and, in Windows Explorer, move your new Class Library project into same folder as desktop test project. This allows the device test project to share the same files as the desktop test project more easily.
  5. Re-open Visual Studio, and open your application solution. In Solution Explorer, right-click the References entry for your application project, and then click AddReference. On the Projects tab of the AddReference dialog box, select your test project, and click OK.
  6. With the device test project selected in Solution Explorer, click Show AllFiles on the Project menu. This reveals all files and folders in the same folder as the desktop test project.
  7. Select all the test and supporting files in Solution Explorer, right-click, and then click Include in Project.
  8. Add the compiler directive to select the appropriate test class namespace at compile time.

    #if PocketPC
     Imports Microsoft.Practices.Mobile.TestTools.UnitTesting
    #else
     Imports Microsoft.VisualStudio.TestTools.UnitTesting
    #endif

  9. In Solution Explorer, right-click your test project, and then click Properties. On the Properties page, click the Devices tab. Change the value for the Output file folder in the Deployment Options section to %CSIDL_PROGRAM_FILES%\GuiTestRunner to ensure that your tests deploy to the same folder as the as the GuiTestRunner utility.
  10. Deploy and execute the GuiTestRunner utility

Links

Posted in .net Framework, Pocket PC Development, Software Development, Unit Testing, VB.Net | 4 Comments »

So what’s so good about the iPhone? (WebBrowser)

Posted by anoriginalidea on August 7, 2007

Why is web browsing the iPhone so cool then?  Well I can’t answer that question with certainty, as I don’t have access to an iPhone. 

But I’ve seen a few videos on the subject and will list my thoughts.  Feel free to post any things people feel really “make it”.

Powerful features to me are:

  • Thumb scrolling
  • Thumb zoom (seems awkward, but seems  to  work)
  • Strong animation support throughout to give an “organic” feel.  The animations are contextual and enhance the usability of the program.
  • Orientation awareness

I think all these features are intrinsic to the iPhone user experience and are not peculiar to safari.

Other interesting features:

  • Cool thumbable “multiple page” interface. (Tab substitute)
  • “Full Screen” mode  just seems to happen intuitively
  • Search field “appears” when url field is focused
  • I like the bookmarks “slide up”. Much smoother than traditional PPC menus.

I believe the “usability” of applications like this is going to be “expected” in the future.  Software developers will really have to take this seriously in order to  survive.

I still think Webby will still have much to offer, even in an iPhone world.  Stay posted.

Links

Posted in Pocket PC Development, Software Development, Webby | No Comments »

The .net 2.0 Compact Framework WebBrowser Control

Posted by anoriginalidea on May 31, 2007

The .netcf 2.0 provides a web browser control.  This inspired me to try and create my own Web Browser based on .net technology.

The “WebBrowser” control has some serious limitations.  These include:

No “Title” property
Back/Next not supported (on 2003 only?)
Can’t access the “Document” object
Can’t change the context menu
Inability to set options such as formatting, cleartype, textsize etc (ie Anything useful)
Inability to access/invoke the favorites infrastructure
If you think about it, these are fairly major.

I overcame most of these problems in a few ways in Webby.

If you’re interested, feel free to ask questions by leaving comments on this post. 

Posted in Pocket PC Development, Software Development | 4 Comments »