PC Review Forums Newsgroups Microsoft DotNet Microsoft Dot NET Compact Framework How to invoke menu item with SendMessage?

Reply

How to invoke menu item with SendMessage?

 
Thread Tools Rate Thread
Old 05-11-2007, 01:54 AM   #1
=?Utf-8?B?X2R0YXlsb3J1cw==?=
Guest
 
Posts: n/a
Default How to invoke menu item with SendMessage?


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
  Reply With Quote
Old 05-11-2007, 07:40 AM   #2
Peter Foot [MVP]
Guest
 
Posts: n/a
Default Re: How to invoke menu item with SendMessage?

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

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

"_dtaylorus" <dtaylorus@discussions.microsoft.com> wrote in message
news:F308EF11-E3B7-4189-9B17-50D5DC4B3CF3@microsoft.com...
>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


  Reply With Quote
Old 05-11-2007, 08:06 AM   #3
=?Utf-8?B?X2R0YXlsb3J1cw==?=
Guest
 
Posts: n/a
Default Re: How to invoke menu item with SendMessage?

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









"Peter Foot [MVP]" wrote:

> 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
>
> --
> Peter Foot
> Microsoft Device Application Development MVP
> www.peterfoot.net | www.inthehand.com
> In The Hand Ltd - .NET Solutions for Mobility
>
> "_dtaylorus" <dtaylorus@discussions.microsoft.com> wrote in message
> news:F308EF11-E3B7-4189-9B17-50D5DC4B3CF3@microsoft.com...
> >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

>

  Reply With Quote
Old 05-11-2007, 08:59 AM   #4
=?Utf-8?B?X2R0YXlsb3J1cw==?=
Guest
 
Posts: n/a
Default Re: How to invoke menu item with SendMessage?

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!

"_dtaylorus" wrote:

> 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
>
>
>
>
>
>
>
>
>
> "Peter Foot [MVP]" wrote:
>
> > 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
> >
> > --
> > Peter Foot
> > Microsoft Device Application Development MVP
> > www.peterfoot.net | www.inthehand.com
> > In The Hand Ltd - .NET Solutions for Mobility
> >
> > "_dtaylorus" <dtaylorus@discussions.microsoft.com> wrote in message
> > news:F308EF11-E3B7-4189-9B17-50D5DC4B3CF3@microsoft.com...
> > >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

> >

  Reply With Quote
Old 05-11-2007, 12:09 PM   #5
Peter Foot [MVP]
Guest
 
Posts: n/a
Default Re: How to invoke menu item with SendMessage?

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

"_dtaylorus" <dtaylorus@discussions.microsoft.com> wrote in message
news:228CC2CA-F1A8-4602-9B5B-D14ACF7CDC61@microsoft.com...
> 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!
>
> "_dtaylorus" wrote:
>
>> 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
>>
>>
>>
>>
>>
>>
>>
>>
>>
>> "Peter Foot [MVP]" wrote:
>>
>> > 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
>> >
>> > --
>> > Peter Foot
>> > Microsoft Device Application Development MVP
>> > www.peterfoot.net | www.inthehand.com
>> > In The Hand Ltd - .NET Solutions for Mobility
>> >
>> > "_dtaylorus" <dtaylorus@discussions.microsoft.com> wrote in message
>> > news:F308EF11-E3B7-4189-9B17-50D5DC4B3CF3@microsoft.com...
>> > >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
>> >


  Reply With Quote
Reply



Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off