views:

105

answers:

1

I'm developing an C# / .NET CF 2.0 application: it's supposed to be used with the touchscreen deactivated, then, I'm looking for a way to programmatically open the application menu (not the Windows menu).

Looking here I tried to adapt the code to the .NET CF 2 but it doesn't work (no error messages neither)

public const int WM_SYSCOMMAND = 0x0112;
public const int SC_KEYMENU = 0xF100;

private void cmdMenu_Click(object sender, EventArgs e)
{
        Message msg = Message.Create(this.Handle, WM_SYSCOMMAND, 
            new IntPtr(SC_KEYMENU), IntPtr.Zero);

        MessageWindow.SendMessage(ref msg);
}

Any ideas?

TIA, Pablo


After Hans answer, I edited the code to

Message msg = Message.Create(this.Handle, WM_SYSCOMMAND, 
    new IntPtr(SC_KEYMENU), new IntPtr(115));  // 's' key

and added a submenu option as &Search, but it doesn't make any difference

A: 

Well, it's working now, but using a different approach: emulating the ALT key. It did the trick on my device (a Psion NEO), but not in the emulator, but it's fine for now.

This is the code (mostly based on this post)

private void cmdMenu_Click(object sender, EventArgs e)
{
    const int VK_MENU = 0x12;
    SendKey(VK_MENU);
}


public static void SendKey(byte key)
{
    const int KEYEVENTF_KEYUP = 0x02;
    const int KEYEVENTF_KEYDOWN = 0x00;

    keybd_event(key, 0, KEYEVENTF_KEYDOWN, 0);
    keybd_event(key, 0, KEYEVENTF_KEYUP, 0);
}

[System.Runtime.InteropServices.DllImport("coredll", SetLastError = true)]
private static extern void keybd_event(byte bVk, byte bScan, int dwFlags, int dwExtraInfo);
PabloG