Solved

MENU

Posted on 1998-07-23
7
1,432 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
  • 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
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
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 50 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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

747 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now