Code source
Code source

  Présentation
  Unités exemple gratuites
  Unités commercialisées
  Conditions d'utilisation
  Comment acheter
  Vendez vos codes
Unités exemple

  LRJ_ClassesPlus
  LRJ_GridsPlus
  LRJ_MenusPlus
  LRJ_WindowsPlus

   Accueil | GlobalDesk | Code source Delphi | Développements | Votre compte | Contact   

Code source : unité exemple LRJ_MenusPlus




Description : contient l'objet LRJ_TPopupList qui contient les LRJ_TPopUpMenu disponibles dans l'application. Contient l'objet LRJ_TPopUpMenu qui implémente une procédure of object permettant d'être notifié lorsque le PopUp menu se referme et une propriété permettant d'aligner les items du PopUp menu vers la droite ou la gauche.

Utilise les unités : Windows, Classes, Messages, Forms, Menus et LRJ_ClassesPlus.

Télécharger LRJ_MenusPlus version 1.2

Télécharger une application de démonstration (avec les codes)

Le code de l'application de démonstration est visible plus bas.

//*********************************************************
//            LRJ_MenusPlus                               *
//            Version : 1.2                               *
//            Date dernière modif : 02.05.2009            *
//            Auteur : Laurent Hède                       *
//            Société LorenJo                             *
//            contact@lorenjo.com                         *
//            copyright LorenJo                           *
//            Réalisé en DELPHI 6                         *
//*********************************************************
unit LRJ_MenusPlus;

interface

               uses
               Windows,
               Classes,
               Messages,
               Forms,
               Menus,
               LRJ_ClassesPlus;

type

LRJ_TPopUpMenu = class;

   //-----------OBJECT--------------------------
LRJ_TPopupList = class(TObject)
   private  //-----------PRIVATE--------------------------
   MOOldWndProc: TFNWndProc;
   MONewWndProc: TFNWndProc;
   MOList: LRJ_TList; // nil
   MOLastPopUpOuvert: LRJ_TPopUpMenu; //nil

   procedure LRJMainWndProc(var Message: TMessage);
   procedure LRJWndProc(var Message: TMessage); virtual;
   procedure AddMenu(const AMenu: LRJ_TPopUpMenu);
   procedure RemoveMenu(const AMenu: LRJ_TPopUpMenu);
   function CountMenu: integer;
   protected //-----------PROTEGE--------------------------

   public   //-----------PUBLIC--------------------------
   procedure AfterConstruction; override;
   destructor Destroy; override;
    // nouveau ______________________________________________
   end; //-----------FIN--------------------------



   //-----------OBJECT--------------------------
LRJ_TPopUpMenu = class(TPopupMenu)
   private  //-----------PRIVATE--------------------------
   MOOnClose: TNotifyEvent;   // nil
   MOIfSetRightToLeftPopUp: boolean; // False

   procedure SetRightToLeftPopUp(ABool: boolean);
   procedure SetIfSetRightToLeftPopUp(ABool: boolean);
   protected //-----------PROTEGE--------------------------
   procedure DoOnClose; virtual;
   public   //-----------PUBLIC--------------------------
   procedure AfterConstruction; override;
   destructor Destroy; override;
   procedure Popup(X, Y: Integer); override;
    // nouveau ______________________________________________
   property OnClose: TNotifyEvent read MOOnClose write MOOnClose;
   property IfSetRightToLeftPopUp : boolean read MOIfSetRightToLeftPopUp write SetIfSetRightToLeftPopUp;
   end; //-----------FIN--------------------------



   
implementation
type
  Int_TPopupList = class(TPopupList);
var
  IntPricList : LRJ_TPopupList;
  
{--------------------------------------------------------------}
{--------------------------------------------------------------}
{-----------------------  LRJ_TPopUpMenu ---------------------------------------}
{--------------------------------------------------------------}
{--------------------------------------------------------------}
procedure LRJ_TPopUpMenu.SetRightToLeftPopUp(ABool: boolean);
var
  MenuItemInfo: TMenuItemInfo;
  Buffer: array[0..79] of Char;
begin
FillChar(MenuItemInfo, sizeOf(MenuItemInfo), 0);
FillChar(Buffer, sizeOf(Buffer), 0);
MenuItemInfo.cbSize := 44;
MenuItemInfo.fMask := MIIM_TYPE;
MenuItemInfo.dwTypeData := Buffer;
MenuItemInfo.cch := SizeOf(Buffer);
if GetMenuItemInfo(items.Handle, 0, true, MenuItemInfo) then
  begin
  if ABool then
    MenuItemInfo.fType := MenuItemInfo.fType or MFT_RIGHTORDER
  else
    if (MenuItemInfo.fType or MFT_RIGHTORDER) = MenuItemInfo.fType then
      MenuItemInfo.fType := MenuItemInfo.fType xor MFT_RIGHTORDER;
  MenuItemInfo.fMask := MIIM_TYPE;
  if SetMenuItemInfo(items.Handle, 0, True, MenuItemInfo) then
    DrawMenuBar(WindowHandle);
  end;
end;
{--------------------------------------------------------------}
procedure LRJ_TPopUpMenu.SetIfSetRightToLeftPopUp(ABool: boolean);
begin
if ABool <> MOIfSetRightToLeftPopUp then
  begin
  MOIfSetRightToLeftPopUp := ABool;
  SetRightToLeftPopUp(MOIfSetRightToLeftPopUp);
  end;
end;
{--------------------------------------------------------------}
procedure LRJ_TPopUpMenu.DoOnClose;
begin
if assigned(MOOnClose) then MOOnClose(self);
end;
{--------------------------------------------------------------}
procedure LRJ_TPopUpMenu.Popup(X, Y: Integer);
begin
if assigned(IntPricList) then
  IntPricList.MOLastPopUpOuvert := self;
if MOIfSetRightToLeftPopUp then SetRightToLeftPopUp(MOIfSetRightToLeftPopUp);
MenuAnimation := [maNone];
inherited Popup(X, Y);
end;
{--------------------------------------------------------------}
procedure LRJ_TPopUpMenu.AfterConstruction;
begin
inherited;
MOOnClose := nil;
MOIfSetRightToLeftPopUp := false;
SetRightToLeftPopUp(MOIfSetRightToLeftPopUp);
if IntPricList = nil then IntPricList := LRJ_TPopupList.create;
IntPricList.AddMenu(self);
end;
{--------------------------------------------------------------}
destructor LRJ_TPopUpMenu.Destroy;
begin 
if assigned(IntPricList) then
  begin
  IntPricList.RemoveMenu(self);
  if IntPricList.CountMenu = 0 then
    begin
    IntPricList.Free;
    IntPricList := nil;
    end;
  end;
inherited;
end;
{--------------------------------------------------------------}
{--------------------------------------------------------------}
{-----------------------  LRJ_TPopupList ---------------------------------------}
{--------------------------------------------------------------}
{--------------------------------------------------------------}
function LRJ_TPopupList.CountMenu: integer;
begin
result := 0;
if assigned(MOList) then result := MOList.count;
end;
{--------------------------------------------------------------}
procedure LRJ_TPopupList.AddMenu(const AMenu: LRJ_TPopUpMenu);
begin
if MOList = nil then MOList := LRJ_TList.Create;
MOList.Add(AMenu);
end;
{--------------------------------------------------------------}
procedure LRJ_TPopupList.RemoveMenu(const AMenu: LRJ_TPopUpMenu);
begin
if assigned(MOList) then MOList.remove(AMenu);
end;
{--------------------------------------------------------------}
procedure LRJ_TPopupList.AfterConstruction;
begin
inherited;
MOLastPopUpOuvert := nil;
MOList := nil;
MONewWndProc := Classes.MakeObjectInstance(LRJMainWndProc);
MOOldWndProc := TFNWndProc(GetWindowLong(PopupList.Window, GWL_WNDPROC));
SetWindowLong(PopupList.Window, GWL_WNDPROC, Longint(MONewWndProc));
end;
{--------------------------------------------------------------}
destructor LRJ_TPopupList.Destroy;
begin 
SetWindowLong(PopupList.Window, GWL_WNDPROC, Longint(MOOldWndProc));
if MOList <> nil then
  begin
  MOList.ClearForObjetList;
  MOList.Free;
  end;
inherited;
end;
{--------------------------------------------------------------}
procedure LRJ_TPopupList.LRJMainWndProc(var Message: TMessage);
begin
try
LRJWndProc(Message);
except
  Application.HandleException(Self);
end;
end;
{--------------------------------------------------------------}
procedure LRJ_TPopupList.LRJWndProc(var Message: TMessage);
begin
with Message do 
  begin
  case Msg of
  WM_EXITMENULOOP:
    begin
    if assigned(MOLastPopUpOuvert) then
      begin
      MOLastPopUpOuvert.DoOnClose;
      MOLastPopUpOuvert := nil;
      end;
    end;
  end;
  Int_TPopupList(PopupList).WndProc(Message);
  end;
end;
{--------------------------------------------------------------}
{--------------------------------------------------------------}
{-----------------------  fin ---------------------------------------}
{--------------------------------------------------------------}
{--------------------------------------------------------------}
initialization
IntPricList := nil;
finalization
if assigned(IntPricList) then IntPricList.free;
end.


Code de l'application de démonstration :

unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, Menus,


                     LRJ_MenusPlus;

type
  TForm1 = class(TForm)
    Label1: TLabel;
    Memo1: TMemo;
    Button1: TButton;
    Button2: TButton;
    Edit1: TEdit;
    Label2: TLabel;
    procedure FormCreate(Sender: TObject);
    procedure Button1Click(Sender: TObject);
    procedure Button2Click(Sender: TObject);
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
  private
  MOCompteurNotif: integer;
  MOPopUpMenu: LRJ_TPopUpMenu;

  procedure Int_OnClosePopUp(sender: TObject);
  public

  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

{--------------------------------------------------------------}
procedure TForm1.FormCreate(Sender: TObject);
var
  zItem, zitem2: TMenuItem;
begin
MOCompteurNotif := 0;
MOPopUpMenu := LRJ_TPopUpMenu.Create(self);
zItem := TMenuItem.Create(MOPopUpMenu);
zItem.Caption := 'item1';
MOPopUpMenu.Items.Add(zItem);
zItem := TMenuItem.Create(MOPopUpMenu);
zItem.Caption := 'item2';
MOPopUpMenu.Items.Add(zItem);
zitem2 := TMenuItem.Create(MOPopUpMenu);
zitem2.Caption := 'sousmenu1';
zItem.Add(zitem2);
zitem2 := TMenuItem.Create(MOPopUpMenu);
zitem2.Caption := 'sousmenu2';
zItem.Add(zitem2);
zItem := TMenuItem.Create(MOPopUpMenu);
zItem.Caption := 'item3';
MOPopUpMenu.Items.Add(zItem);
MOPopUpMenu.OnClose := Int_OnClosePopUp;
end;
{--------------------------------------------------------------}
procedure TForm1.Int_OnClosePopUp(sender: TObject);
begin
Inc(MOCompteurNotif);
edit1.text := '(' + IntToStr(MOCompteurNotif) + ') notification';
end;
{--------------------------------------------------------------}
procedure TForm1.Button1Click(Sender: TObject);
var
  zPoint: TPoint;
begin
MOPopUpMenu.IfSetRightToLeftPopUp := false;
zPoint.X := form1.ClientRect.Left + Button1.Left;
zPoint.Y := form1.ClientRect.top + Button1.top + Button1.height;
zPoint := form1.ClientToScreen(zPoint);
MOPopUpMenu.Popup(zPoint.X, zPoint.y);
end;
{--------------------------------------------------------------}
procedure TForm1.Button2Click(Sender: TObject);
var
  zPoint: TPoint;
begin
MOPopUpMenu.IfSetRightToLeftPopUp := true;
zPoint.X := form1.ClientRect.Left + Button2.Left;
zPoint.Y := form1.ClientRect.top + Button2.top + Button2.height;
zPoint := form1.ClientToScreen(zPoint);
MOPopUpMenu.Popup(zPoint.X, zPoint.y);
end;
{--------------------------------------------------------------}
procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);
begin
MOPopUpMenu.Free;
end;
{--------------------------------------------------------------}
end.


 Accueil | GlobalDesk | Code source Delphi | Développements | Votre compte | Contact 
Copyright © LorenJo 2000-2009    Notice légale