Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

MENU

Posted on 1998-07-23
7
Medium Priority
?
1,476 Views
Last Modified: 2012-06-21
I need help with menu messages, like WM_MENUSELECT, WM_INITMENU, WM_ENTERMENULOOP etc. I want to use these messages (or any other) with SendMessage(...) to select items from the main menu. For example I want to simulate the selection of File\Save from the menu.
Big thanks!
0
Comment
Question by:Matvey
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
7 Comments
 
LVL 1

Expert Comment

by:andrey070798
ID: 1358588
Hi, Matvey!

I'm glad to answer.
May be it will be helpfull.

First you have to get handle of the menu.
Second get handle of SubMenu.
Then get handle of  PARTICULAR ITEM you want to click.
After that you sending message
SendMessage (WindowHandle, WM_COMMAND, LOWORD(MenuItemHandle), 0)

For me it works.
If you need info on how to get handles  I'm here.

Andrey.

0
 
LVL 1

Expert Comment

by:andrey070798
ID: 1358589
Sorry,
I think I misunderstood question.
I my case it will click on the MenuItem and you will see the result of the click.
In your example it will click SAVE item.
If you need to see how is it doing that .... mmmm.... I can check.

Andrey.

0
 
LVL 3

Author Comment

by:Matvey
ID: 1358590
I just need to trigger a menu item click. I think your answere will work.
I know how to get the handle of the menu - GetMenu(Form1.Handle), but after tht all blured.

Let's say I want to make a procedure like this:

ClickMenu('File\Save') //or any other way for defining parameters
begin
  ....................//getting all handles
  SendMessage(...);
end;

Thanks for your help!
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
LVL 1

Expert Comment

by:andrey070798
ID: 1358591
Hi, Matvey!

Here is steps to do that:
1) Get Menu Handle (MHWND)
2) MenuItemCount(MenuHWND) will return CountOfItems from Menu ( For Example if there File, Edit, Exit ---> value 3
3) Loop with GetMenuString will give you string values, like "File", "Edit", "Exit" until "File" detected
4) SubMenuHWND := GetSubMenu (MenuHWND, i) will return Handle for i-th submenu item, zero-based) ( In given example - i = 0 )
5) Then ItemCount for SubMenu
6) Loop with GetMenuString () Until "Save" detected
7) SubMenuItemHWND := GetMenuItemID (SubMenuHWND, Position of "Save")

8) SendMessage ( WindowHWND, WM_COMMAND, LoWord(SubMenuItemID), 0)

This is the way it works for me.
Andrey.
0
 
LVL 3

Author Comment

by:Matvey
ID: 1358592
Great, thanks Andrey, you've been very helpful.
I'll post the code I wrote...
I asked this question because I wanted to add such option to my new component. You can see it on the Delphi pages. It still didn't update it with menu selections, but I will do very soon. Please take a look at it and say if you find it useful. I will provide more options for it and will make the syntax more flexible soon using some parser tool.
(http://www.delphipages.com/edit/count.cfm?comID=452&Link=uploads%2FSystem%5FAPI%2FMUMacro%2Ezip)

I want to give you the points for this question so post an answere please.
Regards, Matvey

the code for calling File/Save :

procedure TForm1.Button1Click(Sender: TObject);
var
  hMain, hSub: HMENU;
  ItemString: Array[0..30] of Char;
  iItem: Integer;
  SelectItemID: UINT;
begin
  hMain := GetMenu(Handle);
  iItem := 0;
  repeat
    GetMenuString(hMain, iItem, @ItemString, 30, MF_BYPOSITION);
    inc(iItem);
  until (ItemString = 'File')or(iItem>GetMenuItemCount(hMain));
  hSub := GetSubMenu(hMain, iItem-1);
  iItem := 0;
  repeat
    GetMenuString(hSub, iItem, @ItemString, 30, MF_BYPOSITION);
    inc(iItem);
  until (ItemString = 'Save')or(iItem>GetMenuItemCount(hSub));
  SelectItemID := GetMenuItemID(hSub, iItem-1);
  SendMessage(Handle, WM_COMMAND, LoWord(SelectItemID), 0);
end;
0
 
LVL 1

Accepted Solution

by:
andrey070798 earned 200 total points
ID: 1358593
HI, Matvey!
Very glad to help.
Sorry for delays in answers. I don't have direct access to Internet. I'm doing that after work, in the evening, so ....
I'm posting it as an answer.

MY FIRST POINTS !!!! YPA!!!
here is the "answer":
       Here is steps to do that:
        1) Get Menu Handle (MHWND)
        2) MenuItemCount(MenuHWND) will return CountOfItems from Menu ( For Example if there File, Edit, Exit ---> value 3
        3) Loop with GetMenuString will give you string values, like "File", "Edit", "Exit" until "File" detected
        4) SubMenuHWND := GetSubMenu (MenuHWND, i) will return Handle for i-th submenu item, zero-based) ( In given example - i = 0 )
        5) Then ItemCount for SubMenu
        6) Loop with GetMenuString () Until "Save" detected
        7) SubMenuItemHWND := GetMenuItemID (SubMenuHWND, Position of "Save")

        8) SendMessage ( WindowHWND, WM_COMMAND, LoWord(SubMenuItemID), 0)

        This is the way it works for me.
        Andrey.
0
 
LVL 3

Author Comment

by:Matvey
ID: 1358594
Thanks again and I'l be glad to see you more on Ex-Ex!

--Matvey
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.
Want to learn how to record your desktop screen without having to use an outside camera. Click on this video and learn how to use the cool google extension called "Screencastify"! Step 1: Open a new google tab Step 2: Go to the left hand upper corn…
Suggested Courses

721 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question