dseifert

I am trying to handle the Smartphone's back button in my application, but it does not work at all. I'm using

Code Snippet

LPARAM lparam = MAKELPARAM(SHMBOF_NODEFAULT | SHMBOF_NOTIFY, SHMBOF_NODEFAULT | SHMBOF_NOTIFY)
LRESULT res = ::SendMessage(menuBar, SHCMBM_OVERRIDEKEY, VK_TBACK, lparam);


But I am not receiving the hotkey event that I should receive. In fact, PreTranslateMessage does receive a WM_KEYUP for VK_TBACK, but letting this pass along it never arrives in WindowProc (neither as WM_KEYUP nor as WM_HOTKEY).

menuBar is set to the handle of my menubar, i.e.
Code Snippet

[...]

SHCreateMenuBar(&mbi);
menuBar = mbi.hwndMB;

and SendMessage returns S_OK.

One difference I notice between the application I am working on and all the back-button sample code out there is that the sample code seems to be always based on a dialog. In my app however we do not use dialogs, but rather our own CWnd derived class.

May it be that CDialog does something special that gets the hotkey and back button working How could I do the same Or should it work with a plain CWnd object as well - and if yes, any idea what the problem may be

Thanks in advance,

Daniel



Re: Smart Devices Native C++ Development SHCMBM_OVERRIDEKEY without dialog

Zero Dai - MSFT

Hi Daniel,

I don't think it is the issue due to if the application is based on dialog.

e.g. If you create a clear Win32 smart device project, which creates a plain window (not dialog), you can still override the back button and get WM_HOTKEY message.

I may guess this is due to the menu bar is not created correctly. Make sure the hwndParent is set to the right handle of the window. You can grab a default code when you create a clear win32 smart device application as following:

Code Snippet

SHMENUBARINFO mbi;

memset(&mbi, 0, sizeof(SHMENUBARINFO));
mbi.cbSize = sizeof(SHMENUBARINFO);
mbi.hwndParent = hWnd;
mbi.nToolBarId = IDR_MENU;
mbi.hInstRes = g_hInst;

if (!SHCreateMenuBar(&mbi))
{
g_hWndMenuBar = NULL;
}
else
{
g_hWndMenuBar = mbi.hwndMB;
}

The window referenced by hWnd will receive the WM_HOTKEY, so if you don't set this value, your WinProc will not get this message.

Regards,

Zero Dai - MSFT






Re: Smart Devices Native C++ Development SHCMBM_OVERRIDEKEY without dialog

dseifert

Hmm, alright. But I use exactly the code as you quoted. I.e. in my CWnd derived class I use

Code Snippet

SHMENUBARINFO mbi;
memset(&mbi, 0, sizeof(SHMENUBARINFO));
mbi.cbSize = sizeof(SHMENUBARINFO);
mbi.hwndParent = m_hWnd;
mbi.nToolBarId = nMenuTemplateID;
mbi.hInstRes = ::AfxGetInstanceHandle();

if (!SHCreateMenuBar(&mbi)) {
menuBar = 0;
return false;
} else
menuBar = mbi.hwndMB;

// override back key
LPARAM lparam = MAKELPARAM(SHMBOF_NODEFAULT | SHMBOF_NOTIFY, SHMBOF_NODEFAULT | SHMBOF_NOTIFY);
::SendMessage(menuBar, SHCMBM_OVERRIDEKEY, VK_TBACK, lparam);

return true;



(this is called after the Create function has been called, i.e. the window is created, and m_hWnd contains a value)




Re: Smart Devices Native C++ Development SHCMBM_OVERRIDEKEY without dialog

Zero Dai - MSFT

Hi dseifert,

Hmm~~ I'm not sure. The code is just right. Maybe the issue is on the window creation. Could you please try to call CWnd::CreateEx (top level window) or ::CreateWindowW directly And set the Style of the window as WS_VISIBLE only. Then add the code into OnCreate handler.

Thanks,

Zero Dai - MSFT






Re: Smart Devices Native C++ Development SHCMBM_OVERRIDEKEY without dialog

dseifert

Haven't done what you said yet, but I found out where the WM_HOTKEY message was being sent to. Instead of the window where the menubar is located, the message arrived at the CFrameWnd. I'm a bit confused about that, is this the expected behaviour

P.S.: Well, for now I'm just redirecting the message to my windows. It is a bit strange that I get the WM_HOTKEY message twice, though. Is this the way it is supposed to be





Re: Smart Devices Native C++ Development SHCMBM_OVERRIDEKEY without dialog

dseifert

Ah, okay, eliminated the duplicate message by checking for MOD_KEYUP (didn't see this being mentioned at MSDN ...). So it is now all working just fine, though if anybody wants to shed some light on why the WM_HOTKEY message is ending up in the CFrameWnd and not in the actual window that the menubar is attached to, this would be great.

By the way, here's the OnHotKey handler for my window's base class (one to rule them all):

Code Snippet

LRESULT MyWindowBaseClass::OnHotKey(WPARAM wp, LPARAM lp) {
CWnd* focusWnd = GetFocus();

if (focusWnd && focusWnd->IsKindOf(RUNTIME_CLASS(CEdit))) {
SHSendBackToFocusWindow (WM_HOTKEY, wp, lp);
} else if (0 != (MOD_KEYUP & LOWORD(lp))) {
PostMessage(WM_COMMAND, ID_BACK);
}

return S_OK;
}


Daniel





Re: Smart Devices Native C++ Development SHCMBM_OVERRIDEKEY without dialog

spymaster2

Have you read the docs It so states that it's sent to the parent. I'd like to see it made WITHOUT an menu deal in an .rc (i.e., make it all in code like any other menu/dialog/etc.) - I can't figure out how to do it that way. Also, you have to make sure the control is visible. If you hide the window it won't work (as I recall). You can move it off-screen, however, possibly give it a 0x0 size, too (less resources that way).

Somewhat related to this:

Saw this on pocketinformat.com and slashdot

cracker iFalleni
aka Fallen
aka F/\LLEN
aka Syrkine, Vladimir
aka Vladimir Syrkine
russian living in australia, undergrad at university of sydney (honor roll according to univ.)

mailto:vsyr4253@it.usyd.edu.au [mailto]

pirate sertoli
aka Anderson Barbosa de Oliveira
aka Anderson Barbosa
aka Anderson B Oliveira
aka Andros
aka androabo
aka mike terr
aka Barbol
aka tttsmith
living in brazil

mailto:andersonbarbosa@cardiol.br [mailto]

Know them They have pirated your stuff. Google them to see what it is these two hoods do.




Re: Smart Devices Native C++ Development SHCMBM_OVERRIDEKEY without dialog

dseifert

spymaster2 wrote:

Have you read the docs It so states that it's sent to the parent.


To the parent of the menu bar (http://msdn2.microsoft.com/En-US/library/aa454997.aspx), i.e. it should not arrive in my CFrameWnd as far as I can tell (as I've not set mbi.hwndParent to the CFrameWnd).



I'd like to see it made WITHOUT an menu deal in an .rc (i.e., make it all in code like any other menu/dialog/etc.) - I can't figure out how to do it that way. Also, you have to make sure the control is visible. If you hide the window it won't work (as I recall). You can move it off-screen, however, possibly give it a 0x0 size, too (less resources that way).


What is "it" Not sure what you are talking about. If my window is hidden I don't care about the talk button anyway ;-)



Somewhat related to this:



While I agree with the letter (I've developed/sold software, incl. shareware, myself in the last 7 years), it does not really relate to this thread at all.

Daniel





Re: Smart Devices Native C++ Development SHCMBM_OVERRIDEKEY without dialog

spymaster2

"It" is the shmenubar thing. That can only be made via an .rc entry.

mbi.nToolBarId = nMenuTemplateID;

is the only way to make those. I know of no other control that has to be made using an .rc/resource editor. I've been doing windows a few years and never use a resource editor. I make my controls in code. Except "it". I don't use MFC so this CFrameWnd stuff means nothing to me. One advantage to programming low; you know what to do when it hits the fan. "It" is...yadonwanaknow.

Related is relative





Re: Smart Devices Native C++ Development SHCMBM_OVERRIDEKEY without dialog

dseifert

I agree with you on that, I do not like the .rc requirement either. As it doesn't seem to be possible to circumvent, however, I tried to limit it as much as possible. Therefore I created three menu templates:
  • left softkey: action, right softkey: nothing
  • left softkey: action, right softkey: action
  • left softkey: action, right softkey: menu
I simply load the template I need and then modify it. So except for the templates the .rc file is not involved and everything is in code.

That said, this is getting off-topic.





Re: Smart Devices Native C++ Development SHCMBM_OVERRIDEKEY without dialog

spymaster2

I don't know why you need to do that. It needs an rc template to create the menu. Unless it's because I use a pop menu for my softkey menus, not the menu's, uh, menus. That's probably it. I can create those on the fly. Saying off topic does not make it off topic, but the act of saying it implies your own guilt. Or, it's like running your husband over in the car, getting out and saying, I'm sorry, then getting in and doing it again.