Articles   Members Online:
-Article/Tip Search
-News Group Search over 21 Million news group articles.
Member Area
-Account Center
-Top 10 NEW!!
-Submit Article/Tip
-Forums Upgraded!!
-My Articles
-Edit Information
-Become a Member
-Why sign up!
-Chat Online!
-Indexes NEW!!
-Build your resume
-Find a job
-Post a job
-Resume Search
-Link to us
Visit Embarcadero
Embarcadero Community
Adding / Deleting Menu Items in OLE-Bound Applications Turn on/off line numbers in source code. Switch to Orginial background IDE or DSP color Comment or reply to this aritlce/tip for discussion. Bookmark this article to my favorite article(s). Print this article
Delphi 2.x
User Rating
No Votes
# Votes
DSP, Administrator
Reference URL:
			Author: Andreas Heidenreich

How can I Delete Menu Items in Applications other than my own?


Solve 1:

When You want to control an external Application via OLE, you sometimes have to 
remove some Menue-Points. 

Generally, this is possible by putting the OLE-Application into a OLE-Container 
instead of opening it off-site. In an OLE-Container, the application tries to open 
its own Menu. When You now put a menu onto Your own application, OLE mixes the 
menues. Every second main menu-point from the external application is visible, the 
first, third, fifth ... menu-point is replaced by the menu You have written. In 
this way, You can write for example Your own FILE-menu for WORD. Now you just have 
to align the OLE-Container to Your form and make the form resizable, then You have 
Word customized as You wanted it. 

Solve 2:

To Create a WORD-Like Look-and-feel in Your application, You have to follow these 

Create a new Form 
insert an OLE-Container (NOT the WORD OLE-Object You have shipped with 
Delphi!!!)and  Set following properties: Align: alClient, AutoActivate: aaManual, 
AllowInPlace : TRUE, AllowActiveDoc: True. 
Insert a Menu and fill the first menu point with 'file' and the sub-menue with the 
approptiate Items. Now You will have a Listing like that: 

1   type
2     TOLE_Testform = class(TForm)
3       OleContainer1: TOleContainer;
4       MainMenu1: TMainMenu;
5   		DocOpenDialog: TOpenDialog;
6       File1: TMenuItem;
7       New1: TMenuItem;
8       Open1: TMenuItem;
9       Save1: TMenuItem;
10      Exit1: TMenuItem;
11    private
12      { Private-Deklarationen }
13    public
14      { Public-Deklarationen }
15    end;

When You now run the program, You will just see Your 'File'-Menu. 

Now add OnClick-Events for each menu item. 

For Open, it will go like this: 

16  procedure TOLE_Testform.Open1Click(Sender: TObject);
17  var
18    continue: boolean;
19    filename: string;
20  begin
21    continue := DocOpenDialog.Execute();
22    if continue = TRUE then
23    begin
24      filename := DocOpenDialog.Filename;
25      //      OleContainer1.DoVerb(ovShow);
26      OleContainer1.DestroyObject;
27      OleContainer1.CreateObjectFromFile(filename, FALSE);
28      OleContainer1.DoVerb(ovShow);
29    end;
30  end;
32  //CreateObjectFromFile will create the appropriate OLE-Object for the given file 
33  extension, e.g. WORD for *.DOC. 
35  //A new document You will get from this statement: 
37  procedure TOLE_Testform.New1Click(Sender: TObject);
38  begin
39    OleContainer1.DestroyObject;
40    OleContainer1.CreateObject('WORD.Document', FALSE);
41    OleContainer1.DoVerb(ovShow);
42  end;

When you opened an existing or created a new document, You will see that the 
default WORD file menu has been replaced by Your own. And now You can go on 
experimenting... ;-)) 

Solve 3:

I've been playing around. Trying to make a menu/menuitem in notepad. And I've 
succeded. But sadly I can not work out how to tell when the menu/menuitem is 
clicked. The two methods I've used to add the menuitem are listed now 

43  var
44    mnuItem: TMenuItem;
45    mnuItemHandle: hmenu;
46    notepad: hwnd;
47    notepadmenu: hmenu;
48    menucount: integer;
49    MenuItemInfo: TMenuItemInfo;
51  {Method 1}
53  procedure TForm1.AddMenu1;
54  notepad := findwindow('Notepad', 'Untitled - Notepad');
55  notepadmnu := getmenu(notepad);
56  mnuItem := TMenuItem.Create(self);
57  mnuitem.Caption := 'Test';
58  mnuItemHandle := mnuitem.handle;
59  appendmenu(notepadmenu, 0, mnuitemhandle, pchar(mnuitem.caption));
60  end;
62  {Method 2}
64  procedure TForm1.AddMenu2;
65  notepad := findwindow('Notepad', 'Untitled - Notepad');
66  notepadmnu := getmenu(notepad);
67  menucount := getmenuitemcount(notepadmnu);
68  MenuItemInfo.fMask := MIIM_DATA + MIIM_TYPE + MIIM_STATE + MIIM_ID;
69  MenuItemInfo.fType := MFT_STRING;
70  MenuItemInfo.fState := MFS_ENABLED;
71  MenuItemInfo.wID := 2000;
72  MenuItemInfo.dwTypeData := '!CLICK ME!';
73  MenuItemInfo.cch := 10;
74  MenuItemInfo.cbSize := sizeof(MenuItemInfo);
75  insertmenuitem(notepadmnu, c + 1, true, MenuItemInfo);
76  end;

Vote: How useful do you find this Article/Tip?
Bad Excellent
1 2 3 4 5 6 7 8 9 10


Share this page
Download from Google

Copyright © Mendozi Enterprises LLC