Intercept Green Call Button

When programming windows mobile application I use CDialog based most of the time, it’s very simple. However there’s a drawback that when I want to capture Green Call Button and Red End button I cannot receive it on WM_SYSCOMMAND, WM_COMMAND, or WM_KEYDOWN. Looks like this windows message is not being called.

The solution is to implement PretranslateMessage in your Dlg app.

in Header files add

public:

afx_msg BOOL PreTranslateMessage(MSG* pMsg);

in Source files add
#define BN_END 115
#define BN_OK 194
#define BN_WINDOWS 193

#define MSG_KEYUP 0×101
#define WM_HOTKEY 0×312
#define BN_TALK 1 //WM_HOTKEY
#define BN_LEFT_SOFTKEY 112 //WM_HOTKEY
#define BN_RIGHT_SOFTKEY 113 //WM_HOTKEY

BOOL CWinceButtonHookDlg::PreTranslateMessage(MSG* pMsg)
{

if(pMsg->message == MSG_KEYUP)
{

if(pMsg->wParam == BN_END)
{
MessageBox(_T(“END?”));
return TRUE;
}
else if(pMsg->wParam == BN_OK)
{
MessageBox(_T(“OK?”));
return TRUE;
}
}
else if(pMsg->message == WM_HOTKEY)
{
if(pMsg->wParam == BN_TALK)
{
MessageBox(_T(“Call?”));
return TRUE;
}
}

return CDialog::PreTranslateMessage(pMsg);
}

PretranslateMessage should return TRUE if you handle the message so windows will not dispatch the message further.

I’m testing with HTC Windows Mobile 6.

~ by arenosoft on July 25, 2008.

Leave a Reply