Welcome to Dream.In.Code
Getting C# Help is Easy!

Join 132,605 C# Programmers for FREE! Get instant access to thousands of C# experts, tutorials, code snippets, and more! There are 922 people online right now. Registration is fast and FREE... Join Now!




Disabling the Windows Mobile Smartphone Back key with C#

 
Reply to this topicStart new topic

Disabling the Windows Mobile Smartphone Back key with C#

jdargan
post 12 Jul, 2008 - 04:22 PM
Post #1


New D.I.C Head

*
Joined: 10 Jul, 2008
Posts: 4

Please help me with understanding how to disable the Back key on an application involving a crossword puzzle game on Windows Mobile with C#. I have attempted to translate the C++ instructions for disabling the Back key. Below is the C++ version of the command for disabling the Back key:

cpp
long lngResult = SendMessage(hWind, SHCMBM_OVERRIDEKEY, VK_TBACK,
MAKELPARAM(SHMBOF_NODEFAULT | SHMBOF_NOTIFY, SHMBOF_NODEFAULT | SHMBOF_NOTIFY));



Below is my C# program code which compiles and runs but does not work and I don't know why not:
csharp

using System.Runtime.InteropServices;

namespace Crossword
{
public partial class frmMain : Form
{

[DllImport("coredll.dll", CharSet = CharSet.Auto)]
private static extern int SendMessage(IntPtr hWnd, int wMsg, IntPtr wParam, IntPtr lParam);


public frmMain()
{
InitializeComponent();

int SHCMBM_OVERRIDEKEY = 0x0593;
IntPtr VK_TBACK = new IntPtr(0x1B);
long lngResult = SendMessage(this.Handle,
SHCMBM_OVERRIDEKEY,
VK_TBACK,
LParamTool.getNoDefaultNotify());

// etc.
}

// Below is a separate class for translating "MakeLParam" from C++
//---------------------------------------------------------------------------------------------
using System;
using System.Collections.Generic;
using System.Text;

namespace Crossword
{
class LParamTool
{


public static IntPtr getNoDefaultNotify()
{
//MAKELPARAM(SHMBOF_NODEFAULT | SHMBOF_NOTIFY, SHMBOF_NODEFAULT | SHMBOF_NOTIFY));
const int SHMBOF_NODEFAULT = 0x00000001;
const int SHMBOF_NOTIFY = 0x00000002;
return MakeLParam(LoWord(SHMBOF_NODEFAULT | SHMBOF_NOTIFY),
HiWord(SHMBOF_NODEFAULT | SHMBOF_NOTIFY));
}

public static IntPtr MakeLParam(int LoWord, int HiWord)
{
return (IntPtr)((HiWord << 16) | (LoWord & 0xffff));
}

public static int HiWord(int Number)
{
return (Number >> 16) & 0xffff;
}

public static int LoWord(int Number)
{
return Number & 0xffff;
}

}
}


This post has been edited by born2c0de: 13 Jul, 2008 - 04:55 AM
User is offlineProfile CardPM

Go to the top of the page

born2c0de
post 13 Jul, 2008 - 04:54 AM
Post #2


printf("I'm a %XR",195936478);

Group Icon
Joined: 26 Nov, 2004
Posts: 3,905



Thanked 34 times

Dream Kudos: 2800

Expert In: 80x86 Assembly, C/C++, VB6, VB.NET, C#, J2SE, Win32 API, Reversing

My Contributions


Do you get any errors after running the code?
Ensure that the PInvoke Signature of SendMessage() is the same as that in coredll.dll (Refer MSDN for prototype)
User is offlineProfile CardPM

Go to the top of the page

jdargan
post 13 Jul, 2008 - 10:24 AM
Post #3


New D.I.C Head

*
Joined: 10 Jul, 2008
Posts: 4

The program compiles and runs but the part about disabling the back key does not work. After I got your reply I searched MSDN and found that MSDN shows the last three parameters as being uint parameters.:

<code>
[DllImport("coredll.dll")]
private static extern int SendMessage(int hWnd, uint wMsg, uint wParam, uint lParam);
</code>

I changed my program to use uints for those parameters, and I am still having the same problem. Any more suggestions?



QUOTE(born2c0de @ 13 Jul, 2008 - 05:54 AM) *

Do you get any errors after running the code?
Ensure that the PInvoke Signature of SendMessage() is the same as that in coredll.dll (Refer MSDN for prototype)

User is offlineProfile CardPM

Go to the top of the page

jdargan
post 22 Aug, 2008 - 02:13 PM
Post #4


New D.I.C Head

*
Joined: 10 Jul, 2008
Posts: 4

By the way, I'm willing to send $100 as a reward to the first person who provides a solution to this problem. The solution MUST involve the C# programming language and have clear, precise instructions on what to do. The answer must involve C# with the Windows Mobile operating system (not just the Windows CE operating system).

The goal is to be able to disable the normal function of the Back button in Windows Mobile, so that when my application is running I will be able to trap the key and discern that it has been pressed but prevent it from causing the previously-viewed screen to be presented to the user.

The solution must not involve the use of a text field. My application does not use text fields, and I don't want any kind of hidden text field receiving keystrokes. I tried that approach and it was a performance problem.

The solution must be one that I find satisfactory and effective.

Thanks in advance for your help.
User is offlineProfile CardPM

Go to the top of the page

Fast ReplyReply to this topicStart new topic
Time is now: 11/23/08 02:23AM

Live C# Help!

C# Tutorials

Reference Sheets

C# Snippets

Bye Bye Ads

Free DIC T-Shirt

T-Shirt Example

Related Sites

Monthly Drawing

Thumb Drive

Partners

Top Contributors

Top 10 Kudos This Month