Solved

Adding a menu item to the main menu items

Posted on 1998-12-29
7
240 Views
Last Modified: 2010-04-04
Hello All,

I would like my wizards (which currently reside in the Tools menu) to appear in their own menu item (just preceding the Help menu item). I am surprised; that what I thought was straightforward has proven to be rather elusive. Please don't launch into a long discourse about TIMenuItemIntf, I just want the line(s) of code to create a stand-alone separate menu item.

Regards,
Edo
0
Comment
Question by:Edo082297
  • 3
  • 2
  • 2
7 Comments
 
LVL 8

Expert Comment

by:ZifNab
ID: 1353637
I'm guessing you talk of Delphi mainmenu or do you talk of your own programs mainmenu?
0
 
LVL 8

Expert Comment

by:ZifNab
ID: 1353638
Hi Edo,

I start with my first guess, the Delphi mainmenu :

ever read these pages? http://www.gexperts.com/opentoolsframe.html

another, more appropriate, because you ask for code is this :

http://www.drbob42.com/delphi/wizards.htm

especially from 8. TAddInMenuListExpert

Hope, that you now have the code you need and some more code you never asked for, but my guess is that you don't mind this

Regards, Zif.
0
 
LVL 1

Author Comment

by:Edo082297
ID: 1353639
Hello ZifNab

Your paltry attempt at an aswer should have been posted as a comment. I digested both Dr.Bob's article on Delphi Wizards and the OpenTools API, the GExpert article and the source code to GExpert's long ago. (I cannot obtain Gerald Nunn's method of adding a main menu item since he uses a function call that is part of Ray Lischener's _Hidden Paths_ companion source (or is it _Secrets ...?) source, and is thus not reproducible).

You are getting lazy in your lofty position, try again.

Edo
0
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
LVL 5

Expert Comment

by:JimBob091197
ID: 1353640
Hi Edo

I'm posting this as a comment so I don't get blasted like ZifNab!!  ;-)

In my expert's constructor, I declare 2 variables:
var
  MainMenu: TIMainMenuIntf;
  MenuItems: TIMenuItemIntf;

Also, NewMainMenuItem and NewMenuItem are declared in the expert as TIMenuItemIntf.  They are freed in the expert's destructor.

I insert the menu as follows:
  MainMenu := ToolServices.GetMainMenu;
  if (MainMenu <> nil) then
    try
      MenuItems := MainMenu.GetMenuItems;
      if (MenuItems <> nil) then
        try
          // Add item to Delphi's main menu bar.
          NewMainMenuItem := MenuItems.InsertItem(8, '&Test', 'TestMainMenuItem', '', 0, 0, 0, [mfVisible, mfEnabled], nil);

          // Add a sub menu to the new menu item.
          NewMenuItem := NewMainMenuItem.InsertItem(0, '&Sub Item', 'NewSubMenuItem', '', 0, 0, 0, [mfVisible, mfEnabled], OnSubClick);
        finally
          MenuItems.Free;
        end;
    finally
      MainMenu.Free;
    end;

Hope this helps you.
Cheers,
JB
0
 
LVL 1

Author Comment

by:Edo082297
ID: 1353641
Hello JB

Thankyou for your correct posting. I am now wondering what I wrote at work, it seems eerily similar, however I think I was trying an insert without the GetMenuItems call. Hmmm....

I wouldn't have blasted Zifnab had the section he refers to in Dr.Bob's article actually added a main menu item. It does not (unless there is a new version of the article, in which case I apologize profusely, and feel rather silly). The article adds a sub menu item to the Tools menu.

Post an answer...

Baie danke
Edo

0
 
LVL 8

Expert Comment

by:ZifNab
ID: 1353642
Edo,

From the bloody mess and still smoking body parts, you see on the floor right before you (it used to be ZifNab) I can only say :

1. I can't smell you already read these articles
2. You've to admit that this is rich information for the unknown
3. You knew how to enter SubMenu's? Correct?
4. Looking at the simple proposed code you can see the GetMainMenu method?
5. Knowing 3 and seeing 4, little step to put your wizards in your own 'mainmenu'.
6. And wouldn't it be great to get more code than you wanted? With full explenation? (but offcourse I didn't knew 1)
7. If you already had some code, you could also have posted it here. That's easier to see the problem.

But heck, who am I. Just somebody who wants to help people on a freely non-profit basis. Who is offcourse not always right (I always say that there are far more better 'experts' on this site than I am, I'm even not a programmer from education or job) and is most of the time talking out of his head.

Now, I'll take my escape through the sewer so my blood will be mixed by wather and I'll be invisible. And then I'm gone...

** poof **

Only few words in the sky will remember you that I was here :

Both, have a nice 1999.

Zif (R.I.P. 29 december 1998)
0
 
LVL 5

Accepted Solution

by:
JimBob091197 earned 50 total points
ID: 1353643
Hi all

Edo: I am posting an answer now!

Zif: Nice speech, man!  :)

Cheers,
JB

P.S.  There was once a big debate on this site about whether code is better or a reference to another web site.  I still prefer a few short lines of code rather than wading through a lot of stuff on another web site, but as Zif says in #6 - you usually get more code than you wanted...
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

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…
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 video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…

760 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

16 Experts available now in Live!

Get 1:1 Help Now