Solved

MENU

Posted on 1998-07-23
7
1,436 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Delphi XE10 Round Image 2 79
Downloading email attachments 2 67
QRReport  TQrmemo vertical stretching 1 42
Create a path if not exists 7 69
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…
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…
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …
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…

867 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

22 Experts available now in Live!

Get 1:1 Help Now