How to invoke menu item with SendMessage?

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I thought it would be a simple matter to SendMessage(hWnd, WM_COMMAND,
commandId, lParam), where hWnd is the form window handle and lParam is 0.
(Surprise... it doesn't work on a WM5 PPC.)

Using CESpy, I can see that for real menu clicks, lParam is set to the
handle of a window with a class name of "MS_SOFTKEY_CE_1.0".

Sure enough, if I manually set lParam to this value in the debugger,
SendMessage works as expected.

So now the question is: How do I _reliably_ get the handle to this
MS_SOFTKEY_CE_1.0 window? There can be any number of them at a given time.
I need to know which one to use for the active form.

Thanks!
-David
 
There is a softkey bar for each application potentially. I can't remember
but possibly the GetMenu API call will work - pass in the handle to your
main form and see what handle is returned.

Regards,

Peter
 
Hi Peter,

Thanks for the response. Your blog has been helpful to me on more than one
occasion.

I'm able to find the softkey bar window (class "menu_worker") using
SHFindMenuBar without any trouble. Its parent is the form hWnd, and it has
no child windows, so that seems to be a dead end as far as finding the
related MS_SOFTKEY_CE_1.0 window goes.

I'm also able to find my form menu handle using the TB_GETBUTTONINFO
message. GetMenu (SHCMBM_GETMENU) only works on the Smartphone platform, not
on the PocketPC.

But I still don't see any way to get the correct lParam value to use to send
a WM_COMMAND message that will invoke a .NET CF menu command.

-David
 
Problem solved. It turns out that the handle returned by SHFindMenuBar works
fine as the lParam for WM_COMMAND, even though CESpy shows a different lParam
value if the menu is invoked normally by tapping on it.

Thanks!
 
Great! Glad that resolved it. The differences between Menu architecture in
Pocket PC and Smartphone can be confusing (since they now are designed to
look and behave more or less the same).

Peter

--
Peter Foot
Microsoft Device Application Development MVP
www.peterfoot.net | www.inthehand.com
In The Hand Ltd - .NET Solutions for Mobility
 
Back
Top