Click to See Complete Forum and Search --> : Activate menu option with API call


Yaser
March 26th, 2001, 09:36 AM
Hi All

I added a menu to my MDIForm with VB. now I scanning the menu by making API calls and getting each menu item.
I have 2 Q's:

1) how do I simulate mouse click on some item using API call(SendMessage?)
2) If for this item there is code in the click event within the
form, will it be executed?

TIA
Yair

Clearcode
March 26th, 2001, 09:48 AM
You need to get the menu item info:


private Type MenuItemInfo
cbSize as Long
fMask as Long
fType as Long
fState as Long
wID as Long
hSubMenu as Long
hbmpChecked as Long
hbmpUnchecked as Long
dwItemData as Long
dwTypeData as Long
cch as Long
End Type

private Declare Sub CopyMemoryMenuItemInfo Lib "kernel32" Alias "RtlMoveMemory" (Destination as MenuItemInfo, byval Source as Long, byval Length as Long)

private Declare Function GetMenuItemInfoApi Lib "user32" Alias "GetMenuItemInfoA" (byval hMenu as Long, byval un as Long, byval b as Boolean, lpMenuItemInfo as MenuItemInfo) as Long




Use:


public Function GetMenuItemInfo(byval hMenu as Long, byval un as Long, byval b as Boolean) as MenuItemInfo

Dim lRet as Long
Dim miiThis as MenuItemInfo

lRet = GetMenuItemInfoApi(hMenu, un, b, miiThis)

GetMenuItemInfo = miiThis


End Function




And send this to the window as the wParam of a WM_COMMAND message.

And yes, the VB event will be fired.

HTH,
Duncan

-------------------------------------------------
Ex. Datis: Duncan Jones
Merrion Computing Ltd
http://www.merrioncomputing.com

Yaser
March 26th, 2001, 10:21 AM
Hi Duncan

thnx for the light speed reply.

Sorry but I still missing a point,
miiThis is of a structure type yet wParam declared as long
so VB screams "Type mismatch"

Yair

Clearcode
March 26th, 2001, 10:28 AM
Oops - forgot the vital bit.
The menu command identifier you need to pass in the SendMessage() api is

Dim lRet as Long

lRet = SendMessageByNum(me.Hwnd, WM_COMMAND, miiThis.wId, 0&)




HTH,
Duncan

-------------------------------------------------
Ex. Datis: Duncan Jones
Merrion Computing Ltd
http://www.merrioncomputing.com

Yaser
March 26th, 2001, 10:44 AM
Hi Duncan

This is what I tried in the first place but the VB event wasn't
fired niether then nor now.

Thank's again

Regards,
Yair

Yaser
March 27th, 2001, 02:39 AM
I have found the missing link.

if one want the VB event to be fired he should call to
PostMessage instead of SendMessage

Regards,
Yair

Clearcode
March 27th, 2001, 02:44 AM
Of course - Doh!

Sendmessage doesn't work if called from the same thread that the emssage is intended for. I had copied my code out of a project I wrote to manipulate word's windows so it worked there.

Top fix, by the way.

Duncan

-------------------------------------------------
Ex. Datis: Duncan Jones
Merrion Computing Ltd
http://www.merrioncomputing.com