bricksmilepig

Here is my original question:

I am developping a smart phone interface by using VC++2005(dialog based). The function is to ask the user to input some information in the edit box. However, when it comes into the interface of data input, the "delete key" on the smart phone does not work, but it works in its own phone functions. I am confused. I think it should work as it is kind of default, or maybe I am wrong, I have to do sth to make it work Anybody can help Thank you!!!!!!!!!!!!!!!!!!!!!!!!!!!!

After this, Thanks Christopher Fairbairn replied me with the answers:

In summary this explains the following process

Within WM_CREATE (or some other initialisation point)

SendMessage (SHFindMenuBar (hWnd), SHCMBM_OVERRIDEKEY, VK_TBACK,
MAKELPARAM (SHMBOF_NODEFAULT | SHMBOF_NOTIFY,
SHMBOF_NODEFAULT | SHMBOF_NOTIFY));

Within a message handler for WM_HOTKEY

if (HIWORD (lParam) == VK_TBACK)
SHSendBackToFocusWindow (wMsg, wParam, lParam);

But i am very new to VC++, even new to programming, so I dont konw where is WM_CREATE and WM_HOTKEY (actually in the "Class View" of the project and choose the property of "Alphabetical" and " Messages" , I found some "WM_......." stuff, but I only found WM_CREATE there, there is no WM_HOTKEY, so i dont konw whether i was in the right way)

Any one can tell me in detail:

1 where is WM_CREATE and message handler for WM_HOTKEY

2 how to get the hWnd

3 Do I need to do some extra thing, like declaration of the variable and include something, or just put the sample inside

Really appreciate your time

Thank you




Re: Smart Devices Native C++ Development the " delete key"

Christopher Fairbairn

Hi,

I think from your description that you are developing a MFC Smart Device Application.

Is this correct If not could you please confirm what project type you selected within the "New Project" wizard when you created your project. Someone will then probably be able to give you specific advice for your situation.

If you are developing a MFC Smart Device Application within Visual Studio 2005 here are some step by step instructions for you:

  1. Open your project within Visual Studio 2005
  2. Open class view (select "Class View" within the "View" menu or press Ctrl+W, C)
  3. Select your dialog class (called CxxxxxDlg where xxxxx is probably the name of your project)
  4. Open the properties window (select "Properties window" within the "View" menu or press Ctrl+W, P)
  5. Click the little diamond shaped toolbar item within the properties window (it's tooltip is "Overrides")
  6. Scroll down until you see "PreTranslateMessage" and click to display a combo box.
  7. Select "add PreTranslateMessage" (the text editor should appear)
  8. Type in the first code snippet shown below (part of it will already be present)
  9. Scroll up within the text editor until you find a method called OnInitDialog
  10. Type in the second code snippet shown below (place it after the call to CDialog::InitDialog)
  11. Scroll up to the top of your source code file and type in the third code snippet

Code Snippet number 1

BOOL CxxxxxDlg::PreTranslateMessage(MSG* pMsg)

{

if (pMsg->message == WM_HOTKEY

&& (HIWORD(pMsg->lParam) == VK_TBACK))

{

SHSendBackToFocusWindow (pMsg->message, pMsg->wParam, pMsg->lParam);

return TRUE;

}

return CDialog::PreTranslateMessage(pMsg);

}

Code Snippet 2

::SendMessage (SHFindMenuBar (m_hWnd), SHCMBM_OVERRIDEKEY, VK_TBACK,

MAKELPARAM (SHMBOF_NODEFAULT | SHMBOF_NOTIFY,

SHMBOF_NODEFAULT | SHMBOF_NOTIFY));

Code Snippet 3
#include
"tpcshell.h"

Hope this helps,

Christopher Fairbairn






Re: Smart Devices Native C++ Development the " delete key"

bricksmilepig

Thank you very much, Christopher Fairbairn

It was really an amazing and detailed answer, I followed step by step, then compile and run, there was no error.

but when I press the "delete" key after I type in some information, by using either "windows mobile 5.0 smart phone Emulator" or " 2003 smart phone Emulator"

Nothing happens.

Actually, I put the codes of "write to file, or read to file" from the edit box, in a dialog called " SecondDlg.cpp", so do I need to paste the codes you gave to me in the "CSecondDlg" under class view, instead of " CxxxxxDlg " I have no idea totally, just guess.

Thanks a lot!






Re: Smart Devices Native C++ Development the " delete key"

Christopher Fairbairn

Hi,

bricksmilepig wrote:

Actually, I put the codes of "write to file, or read to file" from the edit box, in a dialog called " SecondDlg.cpp", so do I need to paste the codes you gave to me in the "CSecondDlg" under class view, instead of " CxxxxxDlg "

Yes the code and step by step instructions I outlined should be applied to what ever dialog your edit box control is located on. If you have three dialogs, all with edit controls you would need to insert the code on all three dialogs.

I had guessed that you were probably using the MFC project wizard, and had placed your edit control on the sole dialog created by the project wizard. If you have created a second dialog, and placed the edit control on this dialog, you would need to adjust my instructions to place the code within that dialog (CSecondDlg within Class view).

If you are still stuck, perhaps you could post the source code to your project somewhere and someone could take a look over it for you.

Sorry for the inconvenience.

Hope this helps,

Christopher Fairbairn.






Re: Smart Devices Native C++ Development the " delete key"

pingpinglele

wow......

very impressive post by Christopher Fairbairn. Actually, I also encountered this problem, so thanx a lot, it is really helpful.

While, I tried the code myself, and it works, but only in solo dialog interface. So maybe bricksmilepig and I are in the same situation, When, we have several dialogs.

alright, here it is: because the splash screen mightbe harder ( I think), so i just put a picture control with a bmp photo on my first dialog, and then put a timer there, so that it can first comes out, and then go to the next interface when the time is up.

then the second dialog is several buttons, and can get access the the last screen by pressing one of those buttons.

For the last dialog, I put some edit control to let the user to type in their data, and save it to a text file.

and for the dialog switching from one dialog to another dialog, I use the following codes:

void CTestDlg:SurprisenSwitch()
{
// First get a pointer to the main pointer - m_pMainWnd of the application
CWnd* TheMainWindow = AfxGetMainWnd();

// Cancel the current dialog box
CDialog:SurprisenCancel;

// Define a new class for the second dialog class
CSecondDlg CSecDlg;

// Set the pointer of the application to the second dialog box
TheMainWnd = &CSecDlg;

// Run the second dialog box in the main application
CSecDlg.DoModal();
}

The problem is, I design a one dialog with edit control, the "backspace" key works as I program following the instruction above taught by Christopher Fairbairn , but like now, I am doing multiple dialog, the key does not work, so I just dont konw what happened to my code, anybody can help me

Thanks a lot!!





Re: Smart Devices Native C++ Development the " delete key"

Christopher Fairbairn

Hi,

pingpinglele wrote:
The problem is, I design a one dialog with edit control, the "backspace" key works as I program following the instruction above taught by Christopher Fairbairn , but like now, I am doing multiple dialog, the key does not work, so I just dont konw what happened to my code, anybody can help me

Have you tried placing the code in my instructions on each dialog within your application The instructions should be fairly easy to modify, just replace references to CxxxDialog with the name of the dialog you need the special backspace handling on.

If you have followed my instructions precisely you will have only handled the backspace key on your initial dialog. The WM_HOTKEY code etc needs to be added to each form which requires this modified behaviour, meaning if your application has 7 dialogs with edit controls, you need to duplicate the code 7 times, one for each dialog.

Hope this helps,

Christopher Fairbairn.