13 Aug 2007

Bitmap lock

Pour éviter de verrouiller un fichier Bitmap lors de son utilisation, voici comment charger un Bitmap. Sinon quand you essayerez d'accéder au fichier, vous obtiendrez une exception "can not access file".

To avoid to lock a Bitmap file, here is how to load a Bitmap. Else, when you access to the file, you will have a "can not access file" exception.

using (Stream s = File.OpenRead(@"\My Documents\My Pictures\Waterfall.jpg"))
Bitmap _backImage = (Bitmap)Bitmap.FromStream(s);


Ink WISP Lite

Dans le SDK WM 6.0 pour les applications natives, vous avez le nouveau composant WISP Lite qui permet à l'utilisateur d'utiliser le stylet pour saisir du texte, ensuite ce composant peut reconnaître le texte saisi.
In WM6.0 SDK for native application, you have the new WISP Lite component allows user to input text with stylus, then WISP Lite can recognize the text.

Voici un exemple de code pour utiliser le WISP Lite:
Here is a code example for using WISP Lite:


  1. // Create the signature window
    hWndInk = CreateWindow( TEXT("static"),
    NULL,
    WS_VISIBLE WS_CHILD WS_BORDER,
    left,
    top + 20,
    215,
    150,
    hWnd,
    NULL,
    hInstance, NULL);

  2. // Attach the inkoverlay to the windows and enable it
    hr = ::CoCreateInstance(CLSID_InkOverlay,
    NULL,
    CLSCTX_INPROC_SERVER,
    IID_IInkOverlay,
    (void **)&g_pInkOverlay);
    ASSERT(SUCCEEDED(hr));

    hr = g_pInkOverlay->put_hWnd((long)hWndInk);
    ASSERT(SUCCEEDED(hr));

    hr = g_pInkOverlay->put_Enabled(VARIANT_TRUE);
    ASSERT(SUCCEEDED(hr));

  3. // Get the strokes and convert to a string
    hr = g_pInkOverlay->get_Ink( &pInk );
    // Get all the strokes in the ink object
    hr = pInk->get_Strokes(&pStrokes);
    // Get the recognition result for these strokes
    hr = pStrokes->get_RecognitionResult(&result);
    // Get the top recognized string
    hr = result->get_TopString(&resultString);

Et c'est fini, resultString contient la chaîne de caractères.
And it is finished, resultString contains the string.


Vous pouvez trouver des exemples plus complets dans le WM6 SDK Refresh :
You can find more examples in the WM6 SDK Refresh directory:

\Program Files\Windows Mobile 6 SDK\Samples\PocketPC\CPP\win32\WISPLite


7 Aug 2007

Extract method tool

Cet outil permet de créer une nouvelle méthode à partir d'un morceau de code. Il est alors très aisé de faire appel à plusieurs reprises à cette section de code, par un simple appel de la méthode. Les paramètres en entrée ou en retour sont automatiquement gérés.
This tool makes it possible to create a new method starting from a piece of code. Then, it is very easy to on several occasions call this section of code, by a simple call of the method. The returns and in parameters are automatically managed.


1) Sélectionner le code

1) Select the code


2)Cliquer sur la fonction extract

2) Click on extract method




3)Attribuer un nom à la nouvelle fonction

3) Set the name of the new function








30 Jul 2007

Migration CF1.0 to CF2.0

Voici un lien intéressant sur la migration d’une application du CF1.0 vers du CF2.0. Je rajouterai juste une recommandation si comme moi vous aviez utilisé des Forms imbriquées dans des panels pour palier le manque des UserControls du CF1.0 ce n’est plus possible sous le CF2.0, il vous faudra donc convertir vos Forms en UserControl. Sinon vous obtiendrez une exception à l'exécution.


Here is an interesting link on migration of an application from CF1.0 to CF2.0. I will add just a recommendation as me you had used Forms imbricated in panels for stage the lack of UserControls in CF1.0, it is no more possible under the CF2.0, it will thus be necessary for you to convert your Forms into UserControl. Else, you will obtain an exception at the execution.


http://msdn2.microsoft.com/en-us/library/bb435027.aspx

19 Jul 2007

Hibernate Windows CE message

Qu'est-ce que c'est?
Ce message Windows est envoyé à toutes les applications ouvertes quand les ressources mémoires sont très faibles (en dessous de 224KB sur PPC). Une application doit libérer de la mémoire autant que possible quand elle reçoit ce message en déchargeant des boîtes de dialogue, détruisant des fenêtres ou libérer de l'espace de stockage temporaire.
What is it?
This Windows message is sent to all opened applications when system resources are running low (under 224KB on PPC). An application should attempt to release as many resources as possible when sent this message by unloading dialog boxes, destroying windows, or freeing up as much local storage.

Vous pouvez répondre à cette évènement en code managé en s'accrochant sur l'event Hibernate.
You can respond to this event in managed code with the Hibernate event.

Voici un exemple d'utilisation :
Here is an example :
// Connect an event hander, OnHibernate, to the Hibernate event.
MobileDevice.Hibernate += new EventHandler(OnHibernate);

private void OnHibernate(object sender, EventArgs e)
{
// Add code here to release cached resources
// for relieving memory pressure.

}