Solved

MENU

Posted on 1998-07-23
7
1,445 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
VMware Disaster Recovery and Data Protection

In this expert guide, you’ll learn about the components of a Modern Data Center. You will use cases for the value-added capabilities of Veeam®, including combining backup and replication for VMware disaster recovery and using replication for data center migration.

 
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

Ransomware: The New Cyber Threat & How to Stop It

This infographic explains ransomware, type of malware that blocks access to your files or your systems and holds them hostage until a ransom is paid. It also examines the different types of ransomware and explains what you can do to thwart this sinister online threat.  

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
calling Tcolordialog in dll make the form disappear 8 112
delphi exception 7 64
How to define IfThen functions in one common unit? 4 54
tidtcpserver connection lost handle 2 87
The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
This Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…

809 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