Delphi Pages Forums  

Go Back   Delphi Pages Forums > Delphi Forum > General

Lost Password?

Reply
 
Thread Tools Display Modes
  #1  
Old 02-18-2010, 02:38 PM
Gary Bamberger Gary Bamberger is offline
Junior Member
 
Join Date: Feb 2010
Posts: 2
Default Can't get access to modify sub menus

I have a program with a menu as follows:

File Edit Format View Help

A very standard menu. My function is passed in an HWND to the main window. From that HWND I can get an HMENU to the main menu. I can then modify the File menu in anyway that I want, but when I try to get access to the Edit menu with the GetSubMenu command it doesn't work.


Code:
procedure ModifyMenu(hWnd1: HWND);
 
var
mnu1:  HMENU;
mnu2:  HMENU;
name1: string[50];
name2: string[50];
count: integer;
 
begin
mnu1 := GetMenu(hWnd1);
GetMenuString(mnu1, 0, @name1, 50, MF_BYPOSITION);  // Correctly returns 'File' in name1
count := GetMenuItemCount(mnu1);                    // Correctly returns 5 menu items
 
mnu2 := GetSubMenu(mnu1, 1);                        // Seems to return a valid handle
GetMenuString(mnu2, 0, @name2, 50, MF_BYPOSITION);  // Returns '' in name2
end;
How do I get access to the Edit submenu so that I can modify it? I do not have a TWindow or TMenu to play with.
Reply With Quote
  #2  
Old 02-19-2010, 04:04 AM
MrBaseball34 MrBaseball34 is offline
Senior Member
 
Join Date: Jan 2001
Posts: 7,260
Default

Try this modification, you are passing in the handle of the menu which is an HMENU, not a HWND...

Code:
procedure ModifyMenu(hWnd1: HMENU);
var
  mnu1:  HMENU;
  mnu2:  HMENU;
  name1: string[50];
  name2: string[50];
  count: integer;
begin
  mnu1 := hWnd1;
  GetMenuString(mnu1, 0, @name1, 50, MF_BYPOSITION);  // Correctly returns 'File' in name1
  count := GetMenuItemCount(mnu1);                    // Correctly returns 5 menu items

  mnu2 := GetSubMenu(mnu1, 1);                        // Seems to return a valid handle
  GetMenuString(mnu2, 0, @name2, 50, MF_BYPOSITION);  // Returns '' in name2
  ShowMessage(name2);
  count := GetMenuItemCount(mnu2);                    // Correctly returns 5 menu items
  ShowMessage(IntToStr(count));
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
  ModifyMenu(MainMenu1.Handle);
end;
__________________
MrBaseball34

Hook 'em Horns
2005 College Football National Champions
2005 College Baseball National Champions
Reply With Quote
  #3  
Old 02-19-2010, 01:26 PM
Gary Bamberger Gary Bamberger is offline
Junior Member
 
Join Date: Feb 2010
Posts: 2
Default

Thank you for your reply. That looks like it would work, but I don't have a TForm and I do not have a choice in what is passed to the procedure. I am passed the HWND not the HMENU. I guess that I left out an important piece of information. My procedure exists in a DLL. I do not have access to any other information about the calling program other than the HWND that is passed to me.
Reply With Quote
  #4  
Old 02-19-2010, 01:32 PM
MrBaseball34 MrBaseball34 is offline
Senior Member
 
Join Date: Jan 2001
Posts: 7,260
Default

Well, that is certainly an important piece of information you left out. I don't have time to set this up in that manner, sorry.
__________________
MrBaseball34

Hook 'em Horns
2005 College Football National Champions
2005 College Baseball National Champions
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is On

Forum Jump


All times are GMT. The time now is 11:13 PM.


Powered by vBulletin® Version 3.8.8
Copyright ©2000 - 2018, vBulletin Solutions, Inc.