Scalabium Software

SMExport advertising
Knowledge for your independence'.
Home Delphi and C++Builder tips


#171: How can I display the chevron for toolbar and open dropdowned popup menu with invisible buttons?

Hello,

today I want to continue the previous tip and describe how to open the popup menu with invisible buttons of toolbar by click in chevron button.

Drop the TPopupMenu component on your form and change the Name property to PopupMenuForToolbar.

Now we must add the handler for WM_NOTIFY message in declaration of our form:

type 
   TForm1 = class(TForm) 
   private 
     { Private declarations } 
     procedure WMNotify(var Message: TMessage); message WM_NOTIFY; 
   end; 

And use the next code as body of handler:

procedure TForm1.WMNotify(var Message: TMessage); 
type 
    PNMREBARCHEVRON = ^TNMREBARCHEVRON; 
    TNMREBARCHEVRON = packed record 
     hdr: TNMHdr; 
     uBand: Integer; 
     wID: Integer; 
     lParam: LPARAM; 
     rc: TRect; 
     lParamNM: LPARAM; 
    end; 

const 
   RBN_CHEVRONPUSHED = RBN_FIRST - 10; 

var 
   i: Integer; 
   j: Integer; 
   R: TRect; 
   P: TPoint; 
   tb: TToolbar; 
   tbtn: TToolButton; 
   mi: TMenuItem; 
begin 
   inherited; 

   case PNMHDR(Message.lParam)^.Code of 
     RBN_CHEVRONPUSHED: 
       begin 
         with PNMREBARCHEVRON(Message.lParam)^ do 
         begin 
           tb := yourCoolBar.Bands[uBand].Control as TToolbar; 
           R := tb.ClientRect; 

           {find first invisible button in toolbar} 
           j := 0; 
           for i := 1 to tb.ButtonCount do 
           begin 
             tbtn := tb.Buttons[i-1]; 
             if (tbtn.Left + tbtn.Width) > R.Right then 
             begin 
               j := i; 
               break; 
             end 
           end; 

           if j <> 0 then 
           begin 
             {delete all existing items} 
             for i := PopupMenuForToolbar.Items.Count-1 downto 0 do 
             begin 
               mi := PopupMenuForToolbar.Items[i]; 
               PopupMenuForToolbar.Items.Delete(i); 
               mi.Free; 
             end; 

             {add all invisible buttons as menu items} 
             for i := j to tb.ButtonCount do 
             begin 
               mi := TMenuItem.Create(Self); 

               tbtn := tb.Buttons[i-1]; 
               if (tbtn.Style = tbsSeparator) then 
                 mi.Caption := '-' 
               else 
               begin 
                 mi.Caption := tbtn.Caption; 
                 mi.Hint := tbtn.Hint; 
                 mi.Tag := tbtn.Tag; 
                 mi.OnClick := tbtn.OnClick; 
               end; 
               PopupMenuForToolbar.Items.Add(mi); 
             end; 

             {show popup menu} 
             P := tb.ClientToScreen(Point(rc.Left, rc.Bottom)); 
             PopupMenuForToolbar.Popup(P.X+2, P.Y+2); 
           end; 
         end; 
       end; 
   end; 
end; 

As you see from comments in code, all what we need is to process the RBN_CHEVRONPUSHED code and add all invisible buttons from toolbar to our popupmenu.

It's all - run the project and you'll get nice feature for standard controls with compartibility with future versions of MS Windows.

And you don't need pay for third-party components with same functionality. Buy the beer for saved money:-)


Published: April 26, 2006

See also
 
Mail parser (ActiveX)
ABA Picture Convert
Excel Reader (dll)
DBISAM Viewer
ABA Spreadsheet Convert
Fast Document Viewer
dBase Viewer
Clarion to Text converter
Protected Storage Viewer
Viewer for MS Outlook Messages
 
 


Contact to webmaster

 

Borland Software Code Gear Scalabium Delphi tips

Copyright© 1998-2024, Scalabium Software. All rights reserved.
webmaster@scalabium.com

SMExport/SMImport suites