Gérer sa propre fonction de messages avec le Compact Framework 2.0 (Pour Smartphone)

30. mai 2008

Contrairement aux Windows Forms, il n'est pas directement possible avec le .NET CF 2.0(SmartPhone) de surcharger la WndProc de ses formulaires.

Hors c'est parfois super utile!

Dans mon cas je voulais déclencher du code dès que l'utilisateur touche l'écran ou le clavier sans avoir à pourrir mon code avec des verrues de partout.

Le résultat c'est cadeau pour vous :) :

public partial class RootForm : Form
{
    private const int GWL_WNDPROC = -4;

    delegate IntPtr WndProcHandler(IntPtr hwnd, uint msg, IntPtr wParam, IntPtr lParam);

    [DllImport("coredll.dll", EntryPoint = "GetWindowLong")]
    private static extern IntPtr GetWindowLong(IntPtr hwnd, int index);

    [DllImport("coredll.dll")]
    static extern int SetWindowLong(IntPtr hwnd, int index, IntPtr wndProc);

    [DllImport("coredll.dll")]
    static extern IntPtr CallWindowProc(IntPtr prevWndFunc, IntPtr hwnd, uint msg, IntPtr wParam, IntPtr lParam);

    private IntPtr prevWndProc = IntPtr.Zero;
    private WndProcHandler wndProc;

    public RootForm()
    {
        InitializeComponent();

        wndProc = new WndProcHandler(WndProc);

        prevWndProc = GetWindowLong(this.Handle, GWL_WNDPROC);

        int success = SetWindowLong(this.Handle, GWL_WNDPROC, Marshal.GetFunctionPointerForDelegate(wndProc));
    }

    private IntPtr WndProc(IntPtr hwnd, uint msg, IntPtr wParam, IntPtr lParam)
    {
        // Mon code juste ici!
        return CallWindowProc(prevWndProc, hwnd, msg, wParam, lParam);
    } 
}

 

Hope this help!

.Net, Win32, Windows Mobile

Silverlight 2 3D - Part 6

1. mai 2008

Au programme aujourd'hui : lissage de Gouraud. Les faces des objets ne sont désormais plus uniformément colorées mais subissent correctement l'éclairage (calculé au niveau des vertices).

Il reste un soucis sur le depth buffer qui me fait passer parfois certains pixels par-dessus d'autres. Je travaille à augmenter la précision de tout ça.

Prochaine étape : les textures.

Pour jeter un coup d'oeil, c'est ici.

.Net, Silverlight