Learn how to a build a cloud-first strategyRegister Now


Creating Office 97 Menus

Posted on 1997-05-03
Medium Priority
Last Modified: 2010-04-06
I use Delphi 3.0.  Coolbars are great but they have not implemented the Office 97 CommandBar componets.  I want a menu that mimics the Office 97 Menu Coolbar.  All menu items behave as Internet Explorer style buttons and remain in the down state when an item's popup menu is showing.

How do I use Delphi's existing TMenu and TMainMenu to get the regions of menuitems and allow them to respond to mousemove messages (I havent' been able to get it to work), thus allowing me to determine using api calls what menu item the user is over and use another call to get the item's bounding region.  From there, I think I can learn to modify the canvas underneath the items to make them behave like IE buttons.  

Or, if I can't use the TMenu, how do I do it from scratch - I tried and got a lot of things to work but was unable to determine how to let other menu items continue to receive mousemove messages while one menu item's popup menu had captured the mouse (if I open files drop down menu and while its open move my mouse over the Edit menu item, the Edit menu item's menu drops down even though I never clicked outside of the file popup menu.  This drives me crazy since I can't figure out how they did it.)
Question by:bruceg050397
  • 3

Accepted Solution

StevenB earned 1020 total points
ID: 1335870
 O.K. There are a lot of questions here and rather than try and tackle tham all at once I'll give you the advice which I think will be the best launch pad for your problem. I'm happy to play arround with this and other ideas, but its probably best done with comments.
  The main issue seems to be getting hold of the fact that a mouse has moved off a component. This issue is central to most of the 'win97 look' problems and isn't obviously supported by delphi. The solution is to use the following two messages:

 message CM_MouseEnter;
 message CM_MouseLeave;

 If you put the following declarations in the protected are of your component:

    procedure CMMouseEnter(var msg:TMessage); message CM_MouseEnter;
    procedure CMMouseLeave(var msg:TMessage); message CM_MouseLeave;

  Then you can use the messages to trigger some boolean toggle of your own, rather than neccessarily using MouseCapture (Which you may have to turn off). Combined with MouseDown and MouseUp events and careful use of booleans you can get very good control of mouse movements over your components.

  I hope this is some help.


Expert Comment

ID: 1335871
 It just struck me that perhaps I wasn't completely clear about mouse capture. MouseCapture is a normal property which can be set to false on the MouseLeave event which I mentioned previously. Careful experimentation with this should lead to some success.

Author Comment

ID: 1335872
Steve, I'll give you an Excellent rating if you'll help with just this one aspect of the question which your answer touched on.  The crux of the problem is that I must use an api call to "popup" a standard windows popup menu when the user clicks on my button.  From that point on I have no control since the api does NOT provide a means to tell that popup menu to NOT capture the mouse.  So, how do I prevent a standard windows popup window from capturing the mouse.  Once it has done this (default windows functionality which I can't get my hands into) my hands are tied and no other control in the application will receive much less respond the onmouseenter and onmouseleave messages -- I tried this even before I asked this question.

Thanks for your time and sorry it took so long to respond, my wife just had our first child.


Expert Comment

ID: 1335873
 Firstly :  Congratulations.

  Secondly :
  I was concentrating mainly on creating your own menu's from scratch, not a particulatly difficult task, if you use borderless forms and mouse events to control different aspects of the paint method and event triggering. I tend to favour this 'Start From Scratch' solution to problems myself, but thats just personal preference.
  If you are using standard Popup Menus then the calls to use are probably these:

  GetCapture(VOID) : Returns HWND of window with mouse capture.
  SetCapture(HWND) : Sets HWND to capture mouse.

  And most importantly

  ReleaseCapture(VOID) : Releases mouse capture from window in the current thread.

  I confess I havn't tested these calls myself, but I think they are what you're after. If I'm going down the wrong track again then let me know.


Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

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

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…
Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
Is your data getting by on basic protection measures? In today’s climate of debilitating malware and ransomware—like WannaCry—that may not be enough. You need to establish more than basics, like a recovery plan that protects both data and endpoints.…
Is your OST file inaccessible, Need to transfer OST file from one computer to another? Want to convert OST file to PST? If the answer to any of the above question is yes, then look no further. With the help of Stellar OST to PST Converter, you can e…
Suggested Courses

810 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