|
-
March 26th, 2001, 10:36 AM
#1
Activate menu option with API call
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
-
March 26th, 2001, 10:48 AM
#2
Re: Activate menu option with API call
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
-
March 26th, 2001, 11:21 AM
#3
Re: Activate menu option with API call
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
-
March 26th, 2001, 11:28 AM
#4
Re: Activate menu option with API call
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
-
March 26th, 2001, 11:44 AM
#5
Re: Activate menu option with API call
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
-
March 27th, 2001, 03:39 AM
#6
Re: Activate menu option with API call
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
-
March 27th, 2001, 03:44 AM
#7
Re: Activate menu option with API call
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
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|