Solved

MENU

Posted on 1998-07-23
7
1,459 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
Industry Leaders: 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!

 
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

Independent Software Vendors: 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

Suggested Solutions

Title # Comments Views Activity
Downloading email attachments 2 96
Delphi IDE crash without error message ... 7 141
How to Get Images From Server using App Tethering 11 52
QuickReport, Delphi, Shape 12 47
In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

739 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